Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

286

287

288

289

290

291

292

293

294

295

296

297

298

299

300

301

302

303

304

305

306

307

308

309

310

311

312

313

314

315

316

317

318

319

320

321

322

323

324

325

326

327

328

329

330

331

332

333

334

335

336

337

338

339

340

341

342

343

344

345

346

347

348

349

350

351

352

353

354

355

356

357

358

359

360

361

362

363

364

365

366

367

368

369

370

371

372

373

374

375

376

377

378

379

380

381

382

383

384

385

386

387

388

389

390

391

392

393

394

395

396

397

398

399

400

401

402

403

404

405

406

407

408

409

410

411

412

413

414

415

416

417

418

419

420

421

422

423

424

425

426

427

428

429

430

431

432

433

434

435

436

437

438

439

440

441

442

443

444

445

446

447

448

449

450

451

452

453

454

455

456

457

458

459

460

461

462

463

464

465

466

467

468

469

470

471

472

473

474

475

476

477

478

479

480

481

482

483

484

485

486

487

488

489

490

491

492

493

494

495

496

497

498

499

500

501

502

503

504

505

506

507

508

509

510

511

512

513

514

515

516

517

518

519

520

521

522

523

524

525

526

527

528

529

530

531

532

533

534

535

536

537

538

539

540

541

542

543

544

545

546

547

548

549

550

551

552

553

554

555

556

557

558

559

560

561

562

563

564

565

566

567

568

569

570

571

572

573

574

575

576

577

578

579

580

581

582

583

584

585

586

587

588

589

590

591

592

593

594

595

596

597

598

599

600

601

602

603

604

605

606

607

608

609

610

611

612

613

614

615

616

617

618

619

620

621

622

623

624

625

626

627

628

629

630

631

632

633

634

635

636

637

638

639

640

641

642

643

644

645

646

647

648

649

650

651

652

653

654

655

656

657

658

659

660

661

662

663

664

665

666

667

668

669

670

671

672

673

674

675

676

677

678

679

680

681

682

683

684

685

686

687

688

689

690

691

692

693

694

695

696

697

698

699

700

701

702

703

704

705

706

707

708

709

710

711

712

713

714

715

716

717

718

719

720

721

722

723

724

725

726

727

728

729

730

731

732

733

734

735

736

737

738

739

740

741

742

743

744

745

746

747

748

749

750

751

752

753

754

755

756

757

758

759

760

761

762

763

764

765

766

767

768

769

770

771

772

773

774

775

776

777

778

779

780

781

782

783

784

785

786

787

788

789

790

791

792

793

794

795

796

797

798

799

800

801

802

803

804

805

806

807

808

809

810

811

812

813

814

815

816

817

818

819

820

821

822

823

824

825

826

827

828

829

830

831

832

833

834

835

836

837

838

839

840

841

842

843

844

845

846

847

848

849

850

851

852

853

854

855

856

857

858

859

860

861

862

863

864

865

866

867

868

869

870

871

872

873

874

875

876

877

878

879

880

881

882

883

884

885

886

887

888

889

890

891

892

893

894

895

896

897

898

899

900

901

902

903

904

905

906

907

908

909

910

911

912

913

914

915

916

917

918

919

920

921

922

923

924

925

926

927

928

929

930

931

932

933

934

935

936

937

938

939

940

941

942

943

944

945

946

947

948

949

950

951

952

953

954

955

956

957

958

959

960

961

962

963

964

965

966

967

968

969

970

971

972

973

974

975

976

977

978

979

980

981

982

983

984

985

986

987

988

989

990

991

992

993

994

995

996

997

998

999

1000

1001

1002

1003

1004

1005

1006

1007

1008

1009

1010

1011

1012

1013

1014

1015

1016

1017

1018

1019

1020

1021

1022

1023

1024

1025

1026

1027

1028

1029

1030

1031

1032

1033

1034

1035

1036

1037

1038

1039

1040

1041

1042

1043

1044

1045

1046

1047

1048

1049

1050

1051

1052

1053

1054

1055

1056

1057

1058

1059

1060

1061

1062

1063

1064

1065

1066

1067

1068

1069

1070

1071

1072

1073

1074

1075

1076

1077

1078

1079

1080

1081

1082

1083

1084

1085

1086

1087

1088

1089

1090

1091

1092

1093

1094

1095

1096

1097

1098

1099

1100

1101

1102

1103

1104

1105

1106

1107

1108

1109

1110

1111

1112

1113

1114

1115

1116

1117

1118

1119

1120

1121

1122

1123

1124

1125

1126

1127

1128

1129

1130

1131

1132

1133

1134

1135

1136

1137

1138

1139

1140

1141

1142

1143

1144

1145

1146

1147

1148

1149

1150

1151

1152

1153

1154

1155

1156

1157

1158

1159

1160

1161

1162

1163

1164

1165

1166

1167

1168

1169

1170

1171

1172

1173

1174

1175

1176

1177

1178

1179

1180

1181

1182

1183

1184

1185

1186

1187

1188

1189

1190

1191

1192

1193

1194

1195

1196

1197

1198

1199

1200

1201

1202

1203

1204

1205

1206

1207

1208

1209

1210

1211

1212

1213

1214

1215

1216

1217

1218

1219

1220

1221

1222

1223

1224

1225

1226

1227

1228

1229

1230

1231

1232

1233

1234

1235

1236

1237

1238

1239

1240

1241

1242

1243

1244

1245

1246

1247

1248

1249

1250

1251

1252

1253

1254

1255

1256

1257

1258

1259

1260

1261

1262

1263

1264

1265

1266

1267

1268

1269

1270

1271

1272

1273

1274

1275

1276

1277

1278

1279

1280

1281

1282

1283

1284

1285

1286

1287

1288

1289

1290

1291

1292

1293

1294

1295

1296

1297

1298

1299

1300

1301

1302

1303

1304

1305

1306

1307

1308

1309

1310

1311

1312

1313

1314

1315

1316

1317

1318

1319

1320

1321

1322

1323

1324

1325

1326

1327

1328

1329

1330

1331

1332

1333

1334

1335

1336

1337

1338

1339

1340

1341

1342

1343

1344

1345

1346

1347

1348

1349

1350

1351

1352

1353

1354

1355

1356

1357

1358

1359

1360

1361

1362

1363

1364

1365

1366

1367

1368

1369

1370

1371

1372

1373

1374

1375

1376

1377

1378

1379

1380

1381

1382

1383

1384

1385

1386

1387

1388

1389

1390

1391

1392

1393

1394

1395

1396

1397

1398

1399

1400

1401

1402

1403

1404

1405

1406

1407

1408

1409

1410

1411

1412

1413

1414

1415

1416

1417

1418

1419

1420

1421

1422

1423

1424

1425

1426

1427

1428

1429

1430

1431

1432

1433

1434

1435

1436

1437

1438

1439

1440

1441

1442

1443

1444

1445

1446

1447

1448

1449

1450

1451

1452

1453

1454

1455

1456

1457

1458

1459

1460

1461

1462

1463

1464

1465

1466

1467

1468

1469

1470

1471

1472

1473

1474

1475

1476

1477

1478

1479

1480

1481

1482

1483

1484

1485

1486

1487

1488

1489

1490

1491

1492

1493

1494

1495

1496

1497

1498

1499

1500

1501

1502

1503

1504

1505

1506

1507

1508

1509

1510

1511

1512

1513

1514

1515

1516

1517

1518

1519

1520

1521

1522

1523

1524

1525

1526

1527

1528

1529

1530

1531

1532

1533

1534

1535

1536

1537

1538

1539

1540

1541

1542

1543

1544

1545

1546

1547

1548

1549

1550

1551

1552

1553

1554

1555

1556

1557

1558

1559

1560

1561

1562

1563

1564

1565

1566

1567

1568

1569

1570

1571

1572

1573

1574

1575

1576

1577

1578

1579

1580

1581

1582

1583

1584

1585

1586

1587

1588

1589

1590

1591

1592

1593

1594

1595

1596

1597

1598

1599

1600

1601

1602

1603

1604

1605

1606

1607

1608

1609

1610

1611

1612

1613

1614

1615

1616

1617

1618

1619

1620

1621

1622

1623

1624

1625

1626

1627

1628

1629

1630

1631

1632

1633

1634

1635

1636

1637

1638

1639

1640

1641

1642

1643

1644

1645

1646

1647

1648

1649

1650

1651

1652

1653

1654

1655

1656

1657

1658

1659

1660

1661

1662

1663

1664

1665

1666

1667

1668

1669

1670

1671

1672

1673

1674

1675

1676

1677

1678

1679

1680

1681

1682

1683

1684

1685

1686

1687

1688

1689

1690

1691

1692

1693

1694

1695

1696

1697

1698

1699

1700

1701

1702

1703

1704

1705

1706

1707

1708

1709

1710

1711

1712

1713

1714

1715

1716

1717

1718

1719

1720

1721

1722

1723

1724

1725

1726

1727

1728

1729

1730

1731

1732

1733

1734

1735

1736

1737

1738

1739

1740

1741

1742

1743

1744

1745

1746

1747

1748

1749

1750

1751

1752

1753

1754

1755

1756

1757

1758

1759

1760

1761

1762

1763

1764

1765

1766

1767

1768

1769

1770

1771

1772

1773

1774

1775

1776

1777

1778

1779

1780

1781

1782

1783

1784

1785

1786

1787

1788

1789

1790

1791

1792

1793

1794

1795

1796

1797

1798

1799

1800

1801

1802

1803

1804

1805

1806

1807

1808

1809

1810

1811

1812

1813

1814

1815

1816

1817

1818

1819

1820

1821

1822

1823

1824

1825

1826

1827

1828

1829

1830

1831

1832

1833

1834

1835

1836

1837

1838

1839

1840

1841

1842

1843

1844

1845

1846

1847

1848

1849

1850

1851

1852

1853

1854

1855

1856

1857

1858

1859

1860

1861

1862

1863

1864

1865

1866

1867

1868

1869

1870

1871

1872

1873

1874

1875

1876

1877

1878

1879

1880

1881

1882

1883

1884

1885

1886

1887

1888

1889

1890

1891

1892

1893

1894

1895

1896

1897

1898

1899

1900

1901

1902

1903

1904

1905

1906

1907

1908

1909

1910

1911

1912

1913

1914

1915

1916

1917

1918

1919

1920

1921

1922

1923

1924

1925

1926

1927

1928

1929

1930

1931

1932

1933

1934

1935

1936

1937

1938

1939

1940

1941

1942

1943

1944

1945

1946

1947

1948

1949

1950

1951

1952

1953

1954

1955

1956

1957

1958

1959

1960

1961

1962

1963

1964

1965

1966

1967

1968

1969

1970

1971

1972

1973

1974

1975

1976

1977

1978

1979

1980

1981

1982

1983

1984

1985

1986

1987

1988

1989

1990

1991

1992

1993

1994

1995

1996

1997

1998

1999

2000

2001

2002

2003

2004

2005

2006

2007

2008

2009

2010

2011

2012

2013

2014

2015

2016

2017

2018

2019

2020

2021

2022

2023

2024

2025

2026

2027

2028

2029

2030

2031

2032

2033

2034

2035

2036

2037

2038

2039

2040

2041

2042

2043

2044

2045

2046

2047

2048

2049

2050

2051

2052

2053

2054

2055

2056

2057

2058

2059

2060

2061

2062

2063

2064

2065

2066

2067

2068

2069

2070

2071

2072

2073

2074

2075

2076

2077

2078

2079

2080

2081

2082

2083

2084

2085

2086

2087

2088

2089

2090

2091

2092

2093

2094

2095

2096

2097

2098

2099

2100

2101

2102

2103

2104

2105

2106

2107

2108

2109

2110

2111

2112

2113

2114

2115

2116

2117

2118

2119

2120

2121

2122

2123

2124

2125

2126

2127

2128

2129

2130

2131

2132

2133

2134

2135

2136

2137

2138

2139

2140

2141

2142

2143

2144

2145

2146

2147

2148

2149

2150

2151

2152

2153

2154

2155

2156

2157

2158

2159

2160

2161

2162

2163

2164

2165

2166

2167

2168

2169

2170

2171

2172

2173

2174

2175

2176

2177

2178

2179

2180

2181

2182

2183

2184

2185

2186

2187

2188

2189

2190

2191

2192

2193

2194

2195

2196

2197

2198

2199

2200

2201

2202

2203

2204

2205

2206

2207

2208

2209

2210

2211

2212

2213

2214

2215

2216

2217

2218

2219

2220

2221

2222

2223

2224

2225

2226

2227

2228

2229

2230

2231

2232

2233

2234

2235

2236

2237

2238

2239

2240

2241

2242

2243

2244

2245

2246

2247

2248

2249

2250

2251

2252

2253

2254

2255

2256

2257

2258

2259

2260

2261

2262

2263

2264

2265

2266

2267

2268

2269

2270

2271

2272

2273

2274

2275

2276

2277

2278

2279

2280

2281

2282

2283

2284

2285

2286

2287

2288

2289

2290

2291

2292

2293

2294

2295

2296

2297

2298

2299

2300

2301

2302

2303

2304

2305

2306

2307

2308

2309

2310

2311

2312

2313

2314

2315

2316

2317

2318

2319

2320

2321

2322

2323

2324

2325

2326

2327

2328

2329

2330

2331

2332

2333

2334

2335

2336

2337

2338

2339

2340

2341

2342

2343

2344

2345

2346

2347

2348

2349

2350

2351

2352

2353

2354

2355

2356

2357

2358

2359

2360

2361

2362

2363

2364

2365

2366

2367

2368

2369

2370

2371

2372

2373

2374

2375

2376

2377

2378

2379

2380

2381

2382

2383

2384

2385

2386

2387

2388

2389

2390

2391

2392

2393

2394

2395

2396

2397

2398

2399

2400

2401

2402

2403

2404

2405

2406

2407

2408

2409

2410

2411

2412

2413

2414

2415

2416

2417

2418

2419

2420

2421

2422

2423

2424

2425

2426

2427

2428

2429

2430

2431

2432

2433

2434

2435

2436

2437

2438

2439

2440

2441

2442

2443

2444

2445

2446

2447

2448

2449

2450

2451

2452

2453

2454

2455

2456

2457

2458

2459

2460

2461

2462

2463

2464

2465

2466

2467

2468

2469

2470

2471

2472

2473

2474

2475

2476

2477

2478

2479

2480

2481

2482

2483

2484

2485

2486

2487

2488

2489

2490

2491

2492

2493

2494

2495

2496

2497

2498

2499

2500

2501

2502

2503

2504

2505

2506

2507

2508

2509

2510

2511

2512

2513

2514

2515

2516

2517

2518

2519

2520

2521

2522

2523

2524

2525

2526

2527

2528

2529

2530

2531

2532

2533

2534

2535

2536

2537

2538

2539

2540

2541

2542

2543

2544

2545

2546

2547

2548

2549

2550

2551

2552

2553

2554

2555

2556

2557

2558

2559

2560

2561

2562

2563

2564

2565

2566

2567

2568

2569

2570

2571

2572

2573

2574

2575

2576

2577

2578

2579

2580

2581

2582

2583

2584

2585

2586

2587

2588

2589

2590

2591

2592

2593

2594

2595

2596

2597

2598

2599

2600

2601

2602

2603

2604

2605

2606

2607

2608

2609

2610

2611

2612

2613

2614

2615

2616

2617

2618

2619

2620

2621

2622

2623

2624

2625

2626

2627

2628

2629

2630

2631

2632

2633

2634

2635

2636

2637

2638

2639

2640

2641

2642

2643

2644

2645

2646

2647

2648

2649

2650

2651

2652

2653

2654

2655

2656

2657

2658

2659

2660

2661

2662

2663

2664

2665

2666

2667

2668

2669

2670

2671

2672

2673

2674

2675

2676

2677

2678

2679

2680

2681

2682

2683

2684

2685

2686

2687

2688

2689

2690

2691

2692

2693

2694

2695

2696

2697

2698

2699

2700

2701

2702

2703

2704

2705

2706

2707

2708

2709

2710

2711

2712

2713

2714

2715

2716

2717

2718

2719

2720

2721

2722

2723

2724

2725

2726

2727

2728

2729

2730

2731

2732

2733

2734

2735

2736

2737

2738

2739

2740

2741

2742

2743

2744

2745

2746

2747

2748

2749

2750

2751

2752

2753

2754

2755

2756

2757

2758

2759

2760

2761

2762

2763

2764

2765

2766

2767

2768

2769

2770

2771

2772

2773

2774

2775

2776

2777

2778

2779

2780

2781

2782

2783

2784

2785

2786

2787

2788

2789

2790

2791

2792

2793

2794

2795

2796

2797

2798

2799

2800

2801

2802

2803

2804

2805

2806

2807

2808

2809

2810

2811

2812

2813

2814

2815

2816

2817

2818

2819

2820

2821

2822

2823

2824

2825

2826

2827

2828

2829

2830

2831

2832

2833

2834

2835

2836

2837

2838

2839

2840

2841

2842

2843

2844

2845

2846

2847

2848

2849

2850

2851

2852

2853

2854

2855

2856

2857

2858

2859

2860

2861

2862

2863

2864

2865

2866

2867

2868

2869

2870

2871

2872

2873

2874

2875

2876

2877

2878

2879

2880

2881

2882

2883

2884

2885

2886

2887

2888

2889

2890

2891

2892

2893

2894

2895

2896

2897

2898

2899

2900

2901

2902

2903

2904

2905

2906

2907

2908

2909

2910

2911

2912

2913

2914

2915

2916

2917

2918

2919

2920

2921

2922

2923

2924

2925

2926

2927

2928

2929

2930

2931

2932

2933

2934

2935

2936

2937

2938

2939

2940

2941

2942

2943

2944

2945

2946

2947

2948

2949

2950

2951

2952

2953

2954

2955

2956

2957

2958

2959

2960

2961

2962

2963

2964

2965

2966

2967

2968

2969

2970

2971

2972

2973

2974

2975

2976

2977

2978

2979

2980

2981

2982

2983

2984

2985

2986

2987

2988

2989

2990

2991

2992

2993

2994

2995

2996

2997

2998

2999

3000

3001

3002

3003

3004

3005

3006

3007

3008

3009

3010

3011

3012

3013

3014

3015

3016

3017

3018

3019

3020

3021

3022

3023

3024

3025

3026

3027

3028

3029

3030

3031

3032

3033

3034

3035

3036

3037

3038

3039

3040

3041

3042

3043

3044

3045

3046

3047

3048

3049

3050

3051

3052

3053

3054

3055

3056

3057

3058

3059

3060

3061

3062

3063

3064

3065

3066

3067

3068

3069

3070

3071

3072

3073

3074

3075

3076

3077

3078

3079

3080

3081

3082

3083

3084

3085

3086

3087

3088

3089

3090

3091

3092

3093

3094

3095

3096

3097

3098

3099

3100

3101

3102

3103

3104

3105

3106

3107

3108

3109

3110

3111

3112

3113

3114

3115

3116

3117

3118

3119

3120

3121

3122

3123

3124

3125

3126

3127

3128

3129

3130

3131

3132

3133

3134

3135

3136

3137

3138

3139

3140

3141

3142

3143

3144

3145

3146

3147

3148

3149

3150

3151

3152

3153

3154

3155

3156

3157

3158

3159

3160

3161

3162

3163

3164

3165

3166

3167

3168

3169

3170

3171

3172

3173

3174

3175

3176

3177

3178

3179

3180

3181

3182

3183

3184

3185

3186

3187

3188

3189

3190

3191

3192

3193

3194

3195

3196

3197

3198

3199

3200

3201

3202

3203

3204

3205

3206

3207

3208

3209

3210

3211

3212

3213

3214

3215

3216

3217

3218

3219

3220

3221

3222

3223

3224

3225

3226

3227

3228

3229

3230

3231

3232

3233

3234

3235

3236

3237

3238

3239

3240

3241

3242

3243

3244

3245

3246

3247

3248

3249

3250

3251

3252

3253

3254

3255

3256

3257

3258

3259

3260

3261

3262

3263

3264

3265

3266

3267

3268

3269

3270

3271

3272

3273

3274

3275

3276

3277

3278

3279

3280

3281

3282

3283

3284

3285

3286

3287

3288

3289

3290

3291

3292

3293

3294

3295

3296

3297

3298

3299

3300

3301

3302

3303

3304

3305

3306

3307

3308

3309

3310

3311

3312

3313

3314

3315

3316

3317

3318

3319

3320

3321

3322

3323

3324

3325

3326

3327

3328

3329

3330

3331

3332

3333

3334

3335

3336

3337

3338

3339

3340

3341

3342

3343

3344

3345

3346

3347

3348

3349

3350

3351

3352

3353

3354

3355

3356

3357

3358

3359

3360

3361

3362

3363

3364

3365

3366

3367

3368

3369

3370

3371

3372

3373

3374

3375

3376

3377

3378

3379

3380

3381

3382

3383

3384

3385

3386

3387

3388

3389

3390

3391

3392

3393

3394

3395

3396

3397

3398

3399

3400

3401

3402

3403

3404

3405

3406

3407

3408

3409

3410

3411

3412

3413

3414

3415

3416

3417

3418

3419

3420

3421

3422

3423

3424

3425

3426

3427

3428

3429

3430

3431

3432

3433

3434

3435

3436

3437

3438

3439

3440

3441

3442

3443

3444

3445

3446

3447

3448

3449

3450

3451

3452

3453

3454

3455

3456

3457

3458

3459

3460

3461

3462

3463

3464

3465

3466

3467

3468

3469

3470

3471

3472

3473

3474

3475

3476

3477

3478

3479

3480

3481

3482

3483

3484

3485

3486

3487

3488

3489

3490

3491

3492

3493

3494

3495

3496

3497

3498

3499

3500

3501

3502

3503

3504

3505

3506

3507

3508

3509

3510

3511

3512

3513

3514

3515

3516

3517

3518

3519

3520

3521

3522

3523

3524

3525

3526

3527

3528

3529

3530

3531

3532

3533

3534

3535

3536

3537

3538

3539

3540

3541

3542

3543

3544

3545

3546

3547

3548

3549

3550

3551

3552

3553

3554

3555

3556

3557

3558

3559

3560

3561

3562

3563

3564

3565

3566

3567

3568

3569

3570

3571

3572

3573

3574

3575

3576

3577

3578

3579

3580

3581

3582

3583

3584

3585

3586

3587

3588

3589

3590

3591

3592

3593

3594

3595

3596

3597

3598

3599

3600

3601

3602

3603

3604

3605

3606

3607

3608

3609

3610

3611

3612

3613

3614

3615

3616

3617

3618

3619

3620

3621

3622

3623

3624

3625

3626

3627

3628

3629

3630

3631

3632

3633

3634

3635

3636

3637

3638

3639

3640

3641

3642

3643

3644

3645

3646

3647

3648

3649

3650

3651

3652

3653

3654

3655

3656

3657

3658

3659

3660

3661

3662

3663

3664

3665

3666

3667

3668

3669

3670

3671

3672

3673

3674

3675

3676

3677

3678

3679

3680

3681

3682

3683

3684

3685

3686

3687

3688

3689

3690

3691

3692

3693

3694

3695

3696

3697

3698

3699

3700

3701

3702

3703

3704

3705

3706

3707

3708

3709

3710

3711

3712

3713

3714

3715

3716

3717

3718

3719

3720

3721

3722

3723

3724

3725

3726

3727

3728

3729

3730

3731

3732

3733

3734

3735

3736

3737

3738

3739

3740

3741

3742

3743

3744

3745

3746

3747

3748

3749

3750

3751

3752

3753

3754

3755

3756

3757

3758

3759

3760

3761

3762

3763

3764

3765

3766

3767

3768

3769

3770

3771

3772

3773

3774

3775

3776

3777

3778

3779

3780

3781

3782

3783

3784

3785

3786

3787

3788

3789

3790

3791

3792

3793

3794

3795

3796

3797

3798

3799

3800

3801

3802

3803

3804

3805

3806

3807

3808

3809

3810

3811

3812

3813

3814

3815

3816

3817

3818

3819

3820

3821

3822

3823

3824

3825

3826

3827

3828

3829

3830

3831

3832

3833

3834

3835

3836

3837

3838

3839

3840

3841

3842

3843

3844

3845

3846

3847

3848

3849

3850

3851

3852

3853

3854

3855

3856

3857

3858

3859

3860

3861

3862

3863

3864

3865

3866

3867

3868

3869

3870

3871

3872

3873

3874

3875

3876

3877

3878

3879

3880

3881

3882

3883

3884

3885

3886

3887

3888

3889

3890

3891

3892

3893

3894

3895

3896

3897

3898

3899

3900

3901

3902

3903

3904

3905

3906

3907

3908

3909

3910

3911

3912

3913

3914

3915

3916

3917

3918

3919

3920

3921

3922

3923

3924

3925

3926

3927

3928

3929

3930

3931

3932

3933

3934

3935

3936

3937

3938

3939

3940

3941

3942

3943

3944

3945

3946

3947

3948

3949

3950

3951

3952

3953

3954

3955

3956

3957

3958

3959

3960

3961

3962

3963

3964

3965

3966

3967

3968

3969

3970

3971

3972

3973

3974

3975

3976

3977

3978

3979

3980

3981

3982

3983

3984

3985

3986

3987

3988

3989

3990

3991

3992

3993

3994

3995

3996

3997

3998

3999

4000

4001

4002

4003

4004

4005

4006

4007

4008

4009

4010

4011

4012

4013

4014

4015

4016

4017

4018

4019

4020

4021

4022

4023

4024

4025

4026

4027

4028

4029

4030

4031

4032

4033

4034

4035

4036

4037

4038

4039

4040

4041

4042

4043

4044

4045

4046

4047

4048

4049

4050

4051

4052

4053

4054

4055

4056

4057

4058

4059

4060

4061

4062

4063

4064

4065

4066

4067

4068

4069

4070

4071

4072

4073

4074

4075

4076

4077

4078

4079

4080

4081

4082

4083

4084

4085

4086

4087

4088

4089

4090

4091

4092

4093

4094

4095

4096

4097

4098

4099

4100

4101

4102

4103

4104

4105

4106

4107

4108

4109

4110

4111

4112

4113

4114

4115

4116

4117

4118

4119

4120

4121

4122

4123

4124

4125

4126

4127

4128

4129

4130

4131

4132

4133

4134

4135

4136

4137

4138

4139

4140

4141

4142

4143

4144

4145

4146

4147

4148

4149

4150

4151

4152

4153

4154

4155

4156

4157

4158

4159

4160

4161

4162

4163

4164

4165

4166

4167

4168

4169

4170

4171

4172

4173

4174

4175

4176

4177

4178

4179

4180

4181

4182

4183

4184

4185

4186

4187

4188

4189

4190

4191

4192

4193

4194

4195

4196

4197

4198

4199

4200

4201

4202

4203

4204

4205

4206

4207

4208

4209

4210

4211

4212

4213

4214

4215

4216

4217

4218

4219

4220

4221

4222

4223

4224

4225

4226

4227

4228

4229

4230

4231

4232

4233

4234

4235

4236

4237

4238

4239

4240

4241

4242

4243

4244

4245

4246

4247

4248

4249

4250

4251

4252

4253

4254

4255

4256

4257

4258

4259

4260

4261

4262

4263

4264

4265

4266

4267

4268

4269

4270

4271

4272

4273

4274

4275

4276

4277

4278

4279

4280

4281

4282

4283

4284

4285

4286

4287

4288

4289

4290

4291

4292

4293

4294

4295

4296

4297

4298

4299

4300

4301

4302

4303

4304

4305

4306

4307

4308

4309

4310

4311

4312

4313

4314

4315

4316

4317

4318

4319

4320

4321

4322

4323

4324

4325

4326

4327

4328

4329

4330

4331

4332

4333

4334

4335

4336

4337

4338

4339

4340

4341

4342

4343

4344

4345

4346

4347

4348

4349

4350

4351

4352

4353

4354

4355

4356

4357

4358

4359

4360

4361

4362

4363

4364

4365

4366

4367

4368

4369

4370

4371

4372

4373

4374

4375

4376

4377

4378

4379

4380

4381

4382

4383

4384

4385

4386

4387

4388

4389

4390

4391

4392

4393

4394

4395

4396

4397

4398

4399

4400

4401

4402

4403

4404

4405

4406

4407

4408

4409

4410

4411

4412

4413

4414

4415

4416

4417

4418

4419

4420

4421

4422

4423

4424

4425

4426

4427

4428

4429

4430

4431

4432

4433

4434

4435

4436

4437

4438

4439

4440

4441

4442

4443

4444

4445

4446

4447

4448

4449

4450

4451

4452

4453

4454

4455

4456

4457

4458

4459

4460

4461

4462

4463

4464

4465

4466

4467

4468

4469

4470

4471

4472

4473

4474

4475

4476

4477

4478

4479

4480

4481

4482

4483

4484

4485

4486

4487

4488

4489

4490

4491

4492

4493

4494

4495

4496

4497

4498

4499

4500

4501

4502

4503

4504

4505

4506

4507

4508

4509

4510

4511

4512

4513

4514

4515

4516

4517

4518

4519

4520

4521

4522

4523

4524

4525

4526

4527

4528

4529

4530

4531

4532

4533

4534

4535

4536

4537

4538

4539

4540

4541

4542

4543

4544

4545

4546

4547

4548

4549

4550

4551

4552

4553

4554

4555

4556

4557

4558

4559

4560

4561

4562

4563

4564

4565

4566

4567

4568

4569

4570

4571

4572

4573

4574

4575

4576

4577

4578

4579

4580

4581

4582

4583

4584

4585

4586

4587

4588

4589

4590

4591

4592

4593

4594

4595

4596

4597

4598

4599

4600

4601

4602

4603

4604

4605

4606

4607

4608

4609

4610

4611

4612

4613

4614

4615

4616

4617

4618

4619

4620

4621

4622

4623

4624

4625

4626

4627

4628

4629

4630

4631

4632

4633

4634

4635

4636

4637

4638

4639

4640

4641

4642

4643

4644

4645

4646

4647

4648

4649

4650

4651

4652

4653

4654

4655

4656

4657

4658

4659

4660

4661

4662

4663

4664

4665

4666

4667

4668

4669

4670

4671

4672

4673

4674

4675

4676

4677

4678

4679

4680

4681

4682

4683

4684

4685

4686

4687

4688

4689

4690

4691

4692

4693

4694

4695

4696

4697

4698

4699

4700

4701

4702

4703

4704

4705

4706

4707

4708

4709

4710

4711

4712

4713

4714

4715

4716

4717

4718

4719

4720

4721

4722

4723

4724

4725

4726

4727

4728

4729

4730

4731

4732

4733

4734

4735

4736

4737

4738

4739

4740

4741

4742

4743

4744

4745

4746

4747

4748

4749

4750

4751

4752

4753

4754

4755

4756

4757

4758

4759

4760

4761

4762

4763

4764

4765

4766

4767

4768

4769

4770

4771

4772

4773

4774

4775

4776

4777

4778

4779

4780

4781

4782

4783

4784

4785

4786

4787

4788

4789

4790

4791

4792

4793

4794

4795

4796

4797

4798

4799

4800

4801

4802

4803

4804

4805

4806

4807

4808

4809

4810

4811

4812

4813

4814

4815

4816

4817

4818

4819

4820

4821

4822

4823

4824

4825

4826

4827

4828

4829

4830

4831

4832

4833

4834

4835

4836

4837

4838

4839

4840

4841

4842

4843

4844

4845

4846

4847

4848

4849

4850

4851

4852

4853

4854

4855

4856

4857

4858

4859

4860

4861

4862

4863

4864

4865

4866

4867

4868

4869

4870

4871

4872

4873

4874

4875

4876

4877

4878

4879

4880

4881

4882

4883

4884

4885

4886

4887

4888

4889

4890

4891

4892

4893

4894

4895

4896

4897

4898

4899

4900

4901

4902

4903

4904

4905

4906

4907

4908

4909

4910

4911

4912

4913

4914

4915

4916

4917

4918

4919

4920

4921

4922

4923

4924

4925

4926

4927

4928

4929

4930

4931

4932

4933

4934

4935

4936

4937

4938

4939

4940

4941

4942

4943

4944

4945

4946

4947

4948

4949

4950

4951

4952

4953

4954

4955

4956

4957

4958

4959

4960

4961

4962

4963

4964

4965

4966

4967

4968

4969

4970

4971

4972

4973

4974

4975

4976

4977

4978

4979

4980

4981

4982

4983

4984

4985

4986

4987

4988

4989

4990

4991

4992

4993

4994

4995

4996

4997

4998

4999

5000

5001

5002

5003

5004

5005

5006

5007

5008

5009

5010

5011

5012

5013

5014

5015

5016

5017

5018

5019

5020

5021

5022

5023

5024

5025

5026

5027

5028

5029

5030

5031

5032

5033

5034

5035

5036

5037

5038

5039

5040

5041

5042

5043

5044

5045

5046

5047

5048

5049

5050

5051

5052

5053

5054

5055

5056

5057

5058

5059

5060

5061

5062

5063

5064

5065

5066

5067

5068

5069

5070

5071

5072

5073

5074

5075

5076

5077

5078

5079

5080

5081

5082

5083

5084

5085

5086

5087

5088

5089

5090

5091

5092

5093

5094

5095

5096

5097

5098

5099

5100

5101

5102

5103

5104

5105

5106

5107

5108

5109

5110

5111

5112

5113

5114

5115

5116

5117

5118

5119

5120

5121

5122

5123

5124

5125

5126

5127

5128

5129

5130

5131

5132

5133

5134

5135

5136

5137

5138

5139

5140

5141

5142

5143

5144

5145

5146

5147

5148

5149

5150

5151

5152

5153

5154

5155

5156

5157

5158

5159

5160

5161

5162

5163

5164

5165

5166

5167

5168

5169

5170

5171

5172

5173

5174

5175

5176

5177

5178

5179

5180

5181

5182

5183

5184

5185

5186

5187

5188

5189

5190

5191

5192

5193

5194

5195

5196

5197

5198

5199

5200

5201

5202

5203

5204

5205

5206

5207

5208

5209

5210

5211

5212

5213

5214

5215

5216

5217

5218

5219

5220

5221

5222

5223

5224

5225

5226

5227

5228

5229

5230

5231

5232

5233

5234

5235

5236

5237

5238

5239

5240

5241

5242

5243

5244

5245

5246

5247

5248

5249

5250

5251

5252

5253

5254

5255

5256

5257

5258

5259

5260

5261

5262

5263

5264

5265

5266

5267

5268

5269

5270

5271

5272

5273

5274

5275

5276

5277

5278

5279

5280

5281

5282

5283

5284

5285

5286

5287

5288

5289

5290

5291

5292

5293

5294

5295

5296

5297

5298

5299

5300

5301

5302

5303

5304

5305

5306

5307

5308

5309

5310

5311

5312

5313

5314

5315

5316

5317

5318

5319

5320

5321

5322

5323

5324

5325

5326

5327

5328

5329

5330

5331

5332

5333

5334

5335

5336

5337

5338

5339

5340

5341

5342

5343

5344

5345

5346

5347

5348

5349

5350

5351

5352

5353

5354

5355

5356

5357

5358

5359

5360

5361

5362

5363

5364

5365

5366

5367

5368

5369

5370

5371

5372

5373

5374

5375

5376

5377

5378

5379

5380

5381

5382

5383

5384

5385

5386

5387

5388

5389

5390

5391

5392

5393

5394

5395

5396

5397

5398

5399

5400

5401

5402

5403

5404

5405

5406

5407

5408

5409

5410

5411

5412

5413

5414

5415

5416

5417

5418

5419

5420

5421

5422

5423

5424

5425

5426

5427

5428

5429

5430

5431

5432

5433

5434

5435

5436

5437

5438

5439

5440

5441

5442

5443

5444

5445

5446

5447

5448

5449

5450

5451

5452

5453

5454

5455

5456

5457

5458

5459

5460

5461

5462

5463

5464

5465

5466

5467

5468

5469

5470

5471

5472

5473

5474

5475

5476

5477

5478

5479

5480

5481

5482

5483

5484

5485

5486

5487

5488

5489

5490

5491

5492

5493

5494

5495

5496

5497

5498

5499

5500

5501

5502

5503

5504

5505

5506

5507

5508

5509

5510

5511

5512

5513

5514

5515

5516

5517

5518

5519

5520

5521

5522

5523

5524

5525

5526

5527

5528

5529

5530

5531

5532

5533

5534

5535

5536

5537

5538

5539

5540

5541

5542

5543

5544

5545

5546

5547

5548

5549

5550

5551

5552

5553

5554

5555

5556

5557

5558

5559

5560

5561

5562

5563

5564

5565

5566

5567

5568

5569

5570

5571

5572

5573

5574

5575

5576

5577

5578

5579

5580

5581

5582

5583

5584

5585

5586

5587

5588

5589

5590

5591

5592

5593

5594

5595

5596

5597

5598

5599

5600

5601

5602

5603

5604

5605

5606

5607

5608

5609

5610

5611

5612

5613

5614

5615

5616

5617

5618

5619

5620

5621

5622

5623

5624

5625

5626

5627

5628

5629

5630

5631

5632

5633

5634

5635

5636

5637

5638

5639

5640

5641

5642

5643

5644

5645

5646

5647

5648

5649

5650

5651

5652

5653

5654

5655

5656

5657

5658

5659

5660

5661

5662

5663

5664

5665

5666

5667

5668

5669

5670

5671

5672

5673

5674

5675

5676

5677

5678

5679

5680

5681

5682

5683

5684

5685

5686

5687

5688

5689

5690

5691

5692

5693

5694

5695

5696

5697

5698

5699

5700

5701

5702

5703

5704

5705

5706

5707

5708

5709

5710

5711

5712

5713

5714

5715

5716

5717

5718

5719

5720

5721

5722

5723

5724

5725

5726

5727

5728

5729

5730

5731

5732

5733

5734

5735

5736

5737

5738

5739

5740

5741

5742

5743

5744

5745

5746

5747

5748

5749

5750

5751

5752

5753

5754

5755

5756

5757

5758

5759

5760

5761

5762

5763

5764

5765

5766

5767

5768

5769

5770

5771

5772

5773

5774

5775

5776

5777

5778

5779

5780

5781

5782

5783

5784

5785

5786

5787

5788

5789

5790

5791

5792

5793

5794

5795

5796

5797

5798

5799

5800

5801

5802

5803

5804

5805

5806

5807

5808

5809

5810

5811

5812

5813

5814

5815

5816

5817

5818

5819

5820

5821

5822

5823

5824

5825

5826

5827

5828

5829

5830

5831

5832

5833

5834

5835

5836

5837

5838

5839

5840

5841

5842

5843

5844

5845

5846

5847

5848

5849

5850

5851

5852

5853

5854

5855

5856

5857

5858

5859

5860

5861

5862

5863

5864

5865

5866

5867

5868

5869

5870

5871

5872

5873

5874

5875

5876

5877

5878

5879

5880

5881

5882

5883

5884

5885

5886

5887

5888

5889

5890

5891

5892

5893

5894

5895

5896

5897

5898

5899

5900

5901

5902

5903

5904

5905

5906

5907

5908

5909

5910

5911

5912

5913

5914

5915

5916

5917

5918

5919

5920

5921

5922

5923

5924

5925

5926

5927

5928

5929

5930

5931

5932

5933

5934

5935

5936

5937

5938

5939

5940

5941

5942

5943

5944

5945

5946

5947

5948

5949

5950

5951

5952

5953

5954

5955

5956

5957

5958

5959

5960

5961

5962

5963

5964

5965

5966

5967

5968

5969

5970

5971

5972

5973

5974

5975

5976

5977

5978

5979

5980

5981

5982

5983

5984

5985

5986

5987

5988

5989

5990

5991

5992

5993

5994

5995

5996

5997

5998

5999

6000

6001

6002

6003

6004

6005

6006

6007

6008

6009

6010

6011

6012

6013

6014

6015

6016

6017

6018

6019

6020

6021

6022

6023

6024

6025

6026

6027

6028

6029

6030

6031

6032

6033

6034

6035

6036

6037

6038

6039

6040

6041

6042

6043

6044

6045

6046

6047

6048

6049

6050

6051

6052

6053

6054

6055

6056

6057

6058

6059

6060

6061

6062

6063

6064

6065

6066

6067

6068

6069

6070

6071

6072

6073

6074

6075

6076

6077

6078

6079

6080

6081

6082

6083

6084

6085

6086

6087

6088

6089

6090

6091

6092

6093

6094

6095

6096

6097

6098

6099

6100

6101

6102

6103

6104

6105

6106

6107

6108

6109

6110

6111

6112

6113

6114

6115

6116

6117

6118

6119

6120

6121

6122

6123

6124

6125

6126

6127

6128

6129

6130

6131

6132

6133

6134

6135

6136

6137

6138

6139

6140

6141

6142

6143

6144

6145

6146

6147

6148

6149

6150

6151

6152

6153

6154

6155

6156

6157

6158

6159

6160

6161

6162

6163

6164

6165

6166

6167

6168

6169

6170

6171

6172

6173

6174

6175

6176

6177

6178

6179

6180

6181

6182

6183

6184

6185

6186

6187

6188

6189

6190

6191

6192

6193

6194

6195

6196

6197

6198

6199

6200

6201

6202

6203

6204

6205

6206

6207

6208

6209

6210

6211

6212

6213

6214

6215

6216

6217

6218

6219

6220

6221

6222

6223

6224

6225

6226

6227

6228

6229

6230

6231

6232

6233

6234

6235

6236

6237

6238

6239

6240

6241

6242

6243

6244

6245

6246

6247

6248

6249

6250

6251

6252

6253

6254

6255

6256

6257

6258

6259

6260

6261

6262

6263

6264

6265

6266

6267

6268

6269

6270

6271

6272

6273

6274

6275

6276

6277

6278

6279

6280

6281

6282

6283

6284

6285

6286

6287

6288

6289

6290

6291

6292

6293

6294

6295

6296

6297

6298

6299

6300

6301

6302

6303

6304

6305

6306

6307

6308

6309

6310

6311

6312

6313

6314

6315

6316

6317

6318

6319

6320

6321

6322

6323

6324

6325

6326

6327

6328

6329

6330

6331

6332

6333

6334

6335

6336

6337

6338

6339

6340

6341

6342

6343

6344

6345

6346

6347

6348

6349

6350

6351

6352

6353

6354

6355

6356

6357

6358

6359

6360

6361

6362

6363

6364

6365

6366

6367

6368

6369

6370

6371

6372

6373

6374

6375

6376

6377

6378

6379

6380

6381

6382

6383

6384

6385

6386

6387

6388

6389

6390

6391

6392

6393

6394

6395

6396

6397

6398

6399

6400

6401

6402

6403

6404

6405

6406

6407

6408

6409

6410

6411

6412

6413

6414

6415

6416

6417

6418

6419

6420

6421

6422

6423

6424

6425

6426

6427

6428

6429

6430

6431

6432

6433

6434

6435

6436

6437

6438

6439

6440

6441

6442

6443

6444

6445

6446

6447

6448

6449

6450

6451

6452

6453

6454

6455

6456

6457

6458

6459

6460

6461

6462

6463

6464

6465

6466

6467

6468

6469

6470

6471

6472

6473

6474

6475

6476

6477

6478

6479

6480

6481

6482

6483

6484

6485

6486

6487

6488

6489

6490

6491

6492

6493

6494

6495

6496

6497

6498

6499

6500

6501

6502

6503

6504

6505

6506

6507

6508

6509

6510

6511

6512

6513

6514

6515

6516

6517

6518

6519

6520

6521

6522

6523

6524

6525

6526

6527

6528

6529

6530

6531

6532

6533

6534

6535

6536

6537

6538

6539

6540

6541

6542

6543

6544

6545

6546

6547

6548

6549

6550

6551

6552

6553

6554

6555

6556

6557

6558

6559

6560

6561

6562

6563

6564

6565

6566

6567

6568

6569

6570

6571

6572

6573

6574

6575

6576

6577

6578

6579

6580

6581

6582

6583

6584

6585

6586

6587

6588

6589

6590

6591

6592

6593

6594

6595

6596

6597

6598

6599

6600

6601

6602

6603

6604

6605

6606

6607

6608

6609

6610

6611

6612

6613

6614

6615

6616

6617

6618

6619

6620

6621

6622

6623

6624

6625

6626

6627

6628

6629

6630

6631

6632

6633

6634

6635

6636

6637

6638

6639

6640

6641

6642

6643

6644

6645

6646

6647

6648

6649

6650

6651

6652

6653

6654

6655

6656

6657

6658

6659

6660

6661

6662

6663

6664

6665

6666

6667

6668

6669

6670

6671

6672

6673

6674

6675

6676

6677

6678

6679

6680

6681

6682

6683

6684

6685

6686

6687

6688

6689

6690

6691

6692

6693

6694

6695

6696

6697

6698

6699

6700

6701

6702

6703

6704

6705

6706

6707

6708

6709

6710

6711

6712

6713

6714

6715

6716

6717

6718

6719

6720

6721

6722

6723

6724

6725

6726

6727

6728

6729

6730

6731

6732

6733

6734

6735

6736

6737

6738

6739

6740

6741

6742

6743

6744

6745

6746

6747

6748

6749

6750

6751

6752

6753

6754

6755

6756

6757

6758

6759

6760

6761

6762

6763

6764

6765

6766

6767

6768

6769

6770

6771

6772

6773

6774

6775

6776

6777

6778

6779

6780

6781

6782

6783

6784

6785

6786

6787

6788

6789

6790

6791

6792

6793

6794

6795

6796

6797

6798

6799

6800

6801

6802

6803

6804

6805

6806

6807

6808

6809

6810

6811

6812

6813

6814

6815

6816

6817

6818

6819

6820

6821

6822

6823

6824

6825

6826

6827

6828

6829

6830

6831

6832

6833

6834

6835

6836

6837

6838

6839

6840

6841

6842

6843

6844

6845

6846

6847

6848

6849

6850

6851

6852

6853

6854

6855

6856

6857

6858

6859

6860

6861

6862

6863

6864

6865

6866

6867

6868

6869

6870

6871

6872

6873

6874

6875

6876

6877

6878

6879

6880

6881

6882

6883

6884

6885

6886

6887

6888

6889

6890

6891

6892

6893

6894

6895

6896

6897

6898

6899

6900

6901

6902

6903

6904

6905

6906

6907

6908

6909

6910

6911

6912

6913

6914

6915

6916

6917

6918

6919

6920

6921

6922

6923

6924

6925

6926

6927

6928

6929

6930

6931

6932

6933

6934

6935

6936

6937

6938

6939

6940

6941

6942

6943

6944

6945

6946

6947

6948

6949

6950

6951

6952

6953

6954

6955

6956

6957

6958

6959

6960

6961

6962

6963

6964

6965

6966

6967

6968

6969

6970

6971

6972

6973

6974

6975

6976

6977

6978

6979

6980

6981

6982

6983

6984

6985

6986

6987

6988

6989

6990

6991

6992

6993

6994

6995

6996

6997

6998

6999

7000

7001

7002

7003

7004

7005

7006

7007

7008

7009

7010

7011

7012

7013

7014

7015

7016

7017

7018

7019

7020

7021

7022

7023

7024

7025

7026

7027

7028

7029

7030

7031

7032

7033

7034

7035

7036

7037

7038

7039

7040

7041

7042

7043

7044

7045

7046

7047

7048

7049

7050

7051

7052

7053

7054

7055

7056

7057

7058

7059

7060

7061

7062

7063

7064

7065

7066

7067

7068

7069

7070

7071

7072

7073

7074

7075

7076

7077

7078

7079

7080

7081

7082

7083

7084

7085

7086

7087

7088

7089

7090

7091

7092

7093

7094

7095

7096

7097

7098

7099

7100

7101

7102

7103

7104

7105

7106

7107

7108

7109

7110

7111

7112

# distutils: language = c++ 

# distutils: libraries = ppl m 

r""" 

Cython wrapper for the Parma Polyhedra Library (PPL) 

  

The Parma Polyhedra Library (PPL) is a library for polyhedral 

computations over `\QQ`. This interface tries to reproduce the C++ API 

as faithfully as possible in Cython/Sage. For example, the following 

C++ excerpt: 

  

.. code-block:: c++ 

  

Variable x(0); 

Variable y(1); 

Constraint_System cs; 

cs.insert(x >= 0); 

cs.insert(x <= 3); 

cs.insert(y >= 0); 

cs.insert(y <= 3); 

C_Polyhedron poly_from_constraints(cs); 

  

translates into:: 

  

sage: from sage.libs.ppl import Variable, Constraint_System, C_Polyhedron 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: cs = Constraint_System() 

sage: cs.insert(x >= 0) 

sage: cs.insert(x <= 3) 

sage: cs.insert(y >= 0) 

sage: cs.insert(y <= 3) 

sage: poly_from_constraints = C_Polyhedron(cs) 

  

The same polyhedron constructed from generators:: 

  

sage: from sage.libs.ppl import Variable, Generator_System, C_Polyhedron, point 

sage: gs = Generator_System() 

sage: gs.insert(point(0*x + 0*y)) 

sage: gs.insert(point(0*x + 3*y)) 

sage: gs.insert(point(3*x + 0*y)) 

sage: gs.insert(point(3*x + 3*y)) 

sage: poly_from_generators = C_Polyhedron(gs) 

  

Rich comparisons test equality/inequality and strict/non-strict 

containment:: 

  

sage: poly_from_generators == poly_from_constraints 

True 

sage: poly_from_generators >= poly_from_constraints 

True 

sage: poly_from_generators < poly_from_constraints 

False 

sage: poly_from_constraints.minimized_generators() 

Generator_System {point(0/1, 0/1), point(0/1, 3/1), point(3/1, 0/1), point(3/1, 3/1)} 

sage: poly_from_constraints.minimized_constraints() 

Constraint_System {-x0+3>=0, -x1+3>=0, x0>=0, x1>=0} 

  

As we see above, the library is generally easy to use. There are a few 

pitfalls that are not entirely obvious without consulting the 

documentation, in particular: 

  

* There are no vectors used to describe :class:`Generator` (points, 

closure points, rays, lines) or :class:`Constraint` (strict 

inequalities, non-strict inequalities, or equations). Coordinates 

are always specified via linear polynomials in :class:`Variable` 

  

* All coordinates of rays and lines as well as all coefficients of 

constraint relations are (arbitrary precision) integers. Only the 

generators :func:`point` and :func:`closure_point` allow one to 

specify an overall divisor of the otherwise integral 

coordinates. For example:: 

  

sage: from sage.libs.ppl import Variable, point 

sage: x = Variable(0); y = Variable(1) 

sage: p = point( 2*x+3*y, 5 ); p 

point(2/5, 3/5) 

sage: p.coefficient(x) 

2 

sage: p.coefficient(y) 

3 

sage: p.divisor() 

5 

  

* PPL supports (topologically) closed polyhedra 

(:class:`C_Polyhedron`) as well as not necessarily closed polyhedra 

(:class:`NNC_Polyhedron`). Only the latter allows closure points 

(=points of the closure but not of the actual polyhedron) and strict 

inequalities (``>`` and ``<``) 

  

The naming convention for the C++ classes is that they start with 

``PPL_``, for example, the original ``Linear_Expression`` becomes 

``PPL_Linear_Expression``. The Python wrapper has the same name as the 

original library class, that is, just ``Linear_Expression``. In short: 

  

* If you are using the Python wrapper (if in doubt: thats you), then 

you use the same names as the PPL C++ class library. 

  

* If you are writing your own Cython code, you can access the 

underlying C++ classes by adding the prefix ``PPL_``. 

  

Finally, PPL is fast. For example, here is the permutahedron of 5 

basis vectors:: 

  

sage: from sage.libs.ppl import Variable, Generator_System, point, C_Polyhedron 

sage: basis = list(range(5)) 

sage: x = [ Variable(i) for i in basis ] 

sage: gs = Generator_System(); 

sage: for coeff in Permutations(basis): 

....: gs.insert(point( sum( (coeff[i]+1)*x[i] for i in basis ) )) 

sage: C_Polyhedron(gs) 

A 4-dimensional polyhedron in QQ^5 defined as the convex hull of 120 points 

  

The above computation (using PPL) finishes without noticeable delay (timeit 

measures it to be 90 microseconds on sage.math). Below we do the same 

computation with cddlib, which needs more than 3 seconds on the same 

hardware:: 

  

sage: basis = list(range(5)) 

sage: gs = [ tuple(coeff) for coeff in Permutations(basis) ] 

sage: Polyhedron(vertices=gs, backend='cdd') # long time (3s on sage.math, 2011) 

A 4-dimensional polyhedron in QQ^5 defined as the convex hull of 120 vertices 

  

DIFFERENCES VS. C++ 

  

Since Python and C++ syntax are not always compatible, there are 

necessarily some differences. The main ones are: 

  

* The :class:`Linear_Expression` also accepts an iterable as input for 

the homogeneous coefficients. 

  

* :class:`Polyhedron` and its subclasses as well as 

:class:`Generator_System` and :class:`Constraint_System` can be set 

immutable via a ``set_immutable()`` method. This is the analog of 

declaring a C++ instance ``const``. All other classes are immutable 

by themselves. 

  

AUTHORS: 

  

- Volker Braun (2010-10-08): initial version. 

- Risan (2012-02-19): extension for MIP_Problem class 

""" 

  

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

# Copyright (C) 2010 Volker Braun <vbraun.name@gmail.com> 

# 

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

# as published by the Free Software Foundation; either version 2 of 

# the License, or (at youroption) any later version. 

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

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

from __future__ import print_function 

  

from cysignals.signals cimport sig_on, sig_off 

  

from sage.structure.sage_object cimport SageObject 

from sage.libs.gmp.mpz cimport * 

from sage.libs.gmpxx cimport mpz_class 

from sage.rings.integer cimport Integer 

from sage.rings.rational cimport Rational 

  

from libcpp cimport bool as cppbool 

from cpython.object cimport Py_LT, Py_LE, Py_EQ, Py_NE, Py_GT, Py_GE 

  

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

# Potentially expensive operations: 

# - compute dual description 

# - solve linear program 

# These can only be triggered by methods in the Polyhedron class 

# they need to be wrapped in sig_on() / sig_off() 

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

  

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

# PPL can use floating-point arithmetic to compute integers 

cdef extern from "ppl.hh" namespace "Parma_Polyhedra_Library": 

cdef void set_rounding_for_PPL() 

cdef void restore_pre_PPL_rounding() 

  

# but with PPL's rounding the gsl will be very unhappy; must turn off! 

restore_pre_PPL_rounding() 

  

  

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

# Cython does not support ctypedef within cppclass; Hack around this restriction: 

cdef extern from "ppl.hh" namespace "Parma_Polyhedra_Library::Generator": 

ctypedef enum PPL_GeneratorType "Parma_Polyhedra_Library::Generator::Type": 

LINE, RAY, POINT, CLOSURE_POINT 

  

cdef extern from "ppl.hh" namespace "Parma_Polyhedra_Library::Constraint": 

ctypedef enum PPL_ConstraintType "Parma_Polyhedra_Library::Constraint::Type": 

EQUALITY, NONSTRICT_INEQUALITY, STRICT_INEQUALITY 

  

cdef extern from "ppl.hh" namespace "Parma_Polyhedra_Library::MIP_Problem": 

ctypedef enum PPL_MIP_Problem_Control_Parameter_Name: 

PRICING 

ctypedef enum PPL_MIP_Problem_Control_Parameter_Value: 

PRICING_STEEPEST_EDGE_FLOAT, PRICING_STEEPEST_EDGE_EXACT, PRICING_TEXTBOOK 

  

  

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

cdef extern from "ppl.hh" namespace "Parma_Polyhedra_Library": 

  

ctypedef size_t PPL_dimension_type "Parma_Polyhedra_Library::dimension_type" 

ctypedef mpz_class PPL_Coefficient "Parma_Polyhedra_Library::Coefficient" 

cdef cppclass PPL_Variable "Parma_Polyhedra_Library::Variable" 

cdef cppclass PPL_Variables_Set "Parma_Polyhedra_Library::Variables_Set" 

cdef cppclass PPL_Linear_Expression "Parma_Polyhedra_Library::Linear_Expression" 

cdef cppclass PPL_Generator "Parma_Polyhedra_Library::Generator" 

cdef cppclass PPL_Generator_System "Parma_Polyhedra_Library::Generator_System" 

cdef cppclass PPL_Constraint "Parma_Polyhedra_Library::Constraint" 

cdef cppclass PPL_Constraint_System "Parma_Polyhedra_Library::Constraint_System" 

cdef cppclass PPL_Polyhedron "Parma_Polyhedra_Library::Polyhedron" 

cdef cppclass PPL_C_Polyhedron "Parma_Polyhedra_Library::C_Polyhedron" (PPL_Polyhedron) 

cdef cppclass PPL_NNC_Polyhedron "Parma_Polyhedra_Library::NNC_Polyhedron" (PPL_Polyhedron) 

cdef cppclass PPL_Poly_Gen_Relation "Parma_Polyhedra_Library::Poly_Gen_Relation" 

cdef cppclass PPL_Poly_Con_Relation "Parma_Polyhedra_Library::Poly_Con_Relation" 

cdef cppclass PPL_MIP_Problem "Parma_Polyhedra_Library::MIP_Problem" 

  

cdef cppclass PPL_Variable: 

PPL_Variable(PPL_dimension_type i) 

PPL_dimension_type id() 

bint OK() 

PPL_dimension_type space_dimension() 

  

cdef cppclass PPL_Variables_Set: 

PPL_Variables_Set() 

PPL_Variables_Set(PPL_Variable v) 

PPL_Variables_Set(PPL_Variable v, PPL_Variable w) 

PPL_dimension_type space_dimension() 

void insert(PPL_Variable v) 

size_t size() 

void ascii_dump() 

bint OK() 

  

cdef cppclass PPL_Linear_Expression: 

PPL_Linear_Expression() 

PPL_Linear_Expression(PPL_Linear_Expression &e) 

PPL_Linear_Expression(PPL_Coefficient n) 

PPL_Linear_Expression(PPL_Variable v) 

PPL_dimension_type space_dimension() 

PPL_Coefficient coefficient(PPL_Variable v) 

PPL_Coefficient inhomogeneous_term() 

bint is_zero() 

bint all_homogeneous_terms_are_zero() 

void ascii_dump() 

bint OK() 

PPL_Linear_Expression operator+(PPL_Linear_Expression& e) 

PPL_Linear_Expression operator-(PPL_Linear_Expression& e) 

PPL_Linear_Expression operator*(PPL_Coefficient n) 

PPL_Constraint operator> (PPL_Linear_Expression& e) 

PPL_Constraint operator>=(PPL_Linear_Expression& e) 

PPL_Constraint operator==(PPL_Linear_Expression& e) 

PPL_Constraint operator<=(PPL_Linear_Expression& e) 

PPL_Constraint operator< (PPL_Linear_Expression& e) 

  

cdef cppclass PPL_Generator: 

PPL_Generator(PPL_Generator &g) 

# Cython does not support static members 

#PPL_Generator line(PPL_Linear_Expression &e) 

#PPL_Generator ray(PPL_Linear_Expression &e) 

#PPL_Generator point(PPL_Linear_Expression &e, PPL_Coefficient d) 

#PPL_Generator closure_point(PPL_Linear_Expression &e) 

PPL_dimension_type space_dimension() 

PPL_GeneratorType type() 

bint is_line() 

bint is_ray() 

bint is_line_or_ray() 

bint is_point() 

bint is_closure_point() 

PPL_Coefficient coefficient(PPL_Variable v) 

PPL_Coefficient divisor() except + 

bint is_equivalent_to(PPL_Generator &y) 

void ascii_dump() 

bint OK() 

  

cdef cppclass PPL_Constraint: 

PPL_Constraint(PPL_Constraint &g) 

PPL_dimension_type space_dimension() 

PPL_ConstraintType type() 

bint is_equality() 

bint is_inequality() 

bint is_nonstrict_inequality() 

bint is_strict_inequality() 

PPL_Coefficient coefficient(PPL_Variable v) 

PPL_Coefficient inhomogeneous_term() 

bint is_tautological() 

bint is_inconsistent() 

bint is_equivalent_to(PPL_Constraint &y) 

void ascii_dump() 

bint OK() 

  

cdef cppclass PPL_Generator_System: 

# This seems to not work in cython 

#cppclass PPL_const_iterator "const_iterator": 

# PPL_Generator operator*() 

# PPL_const_iterator operator++() 

# bint operator==(PPL_const_iterator&) 

# bint operator!=(PPL_const_iterator&) 

#PPL_const_iterator begin() 

#PPL_const_iterator end() 

PPL_Generator_System() 

PPL_Generator_System(PPL_Generator &g) 

PPL_Generator_System(PPL_Generator_System &gs) 

PPL_dimension_type space_dimension() 

void clear() 

void insert(PPL_Generator &g) 

bint empty() 

void ascii_dump() 

bint OK() 

  

cdef cppclass PPL_Constraint_System: 

# This seems to not work in cython 

#cppclass PPL_const_iterator "const_iterator": 

# PPL_Constraint operator*() 

# PPL_const_iterator operator++() 

# bint operator==(PPL_const_iterator&) 

# bint operator!=(PPL_const_iterator&) 

#PPL_const_iterator begin() 

#PPL_const_iterator end() 

PPL_Constraint_System() 

PPL_Constraint_System(PPL_Constraint &g) 

PPL_Constraint_System(PPL_Constraint_System &gs) 

PPL_dimension_type space_dimension() 

bint has_equalities() 

bint has_strict_inequalities() 

void clear() 

void insert(PPL_Constraint &g) 

bint empty() 

void ascii_dump() 

bint OK() 

  

cdef enum PPL_Degenerate_Element: 

UNIVERSE, EMPTY 

  

cdef enum PPL_Optimization_Mode "Parma_Polyhedra_Library::Optimization_Mode": 

MINIMIZATION, MAXIMIZATION 

  

cdef enum MIP_Problem_Status: 

UNFEASIBLE_MIP_PROBLEM, UNBOUNDED_MIP_PROBLEM, OPTIMIZED_MIP_PROBLEM 

  

cdef cppclass PPL_Polyhedron: 

PPL_dimension_type space_dimension() 

PPL_dimension_type affine_dimension() 

PPL_Constraint_System& constraints() 

PPL_Constraint_System& minimized_constraints() 

PPL_Generator_System& generators() 

PPL_Generator_System& minimized_generators() 

PPL_Poly_Con_Relation relation_with(PPL_Constraint &c) except +ValueError 

PPL_Poly_Gen_Relation relation_with(PPL_Generator &g) except +ValueError 

bint is_empty() 

bint is_universe() 

bint is_topologically_closed() 

bint is_disjoint_from(PPL_Polyhedron &y) except +ValueError 

bint is_discrete() 

bint is_bounded() 

bint contains_integer_point() 

bint constrains(PPL_Variable var) except +ValueError 

bint bounds_from_above(PPL_Linear_Expression &expr) except +ValueError 

bint bounds_from_below(PPL_Linear_Expression &expr) except +ValueError 

bint maximize(PPL_Linear_Expression &expr, PPL_Coefficient &sup_n, PPL_Coefficient &sup_d, 

cppbool &maximum) 

bint maximize(PPL_Linear_Expression &expr, PPL_Coefficient &sup_n, PPL_Coefficient &sup_d, 

cppbool &maximum, PPL_Generator &g) 

bint minimize(PPL_Linear_Expression &expr, PPL_Coefficient &inf_n, PPL_Coefficient &inf_d, 

cppbool &minimum) 

bint minimize(PPL_Linear_Expression &expr, PPL_Coefficient &inf_n, PPL_Coefficient &inf_d, 

cppbool &minimum, PPL_Generator &g) 

bint frequency(PPL_Linear_Expression &expr, PPL_Coefficient &freq_n, PPL_Coefficient &freq_d, 

PPL_Coefficient &val_n, PPL_Coefficient &val_d) 

bint contains(PPL_Polyhedron &y) except +ValueError 

bint strictly_contains(PPL_Polyhedron &y) except +ValueError 

void add_constraint(PPL_Constraint &c) except +ValueError 

void add_generator(PPL_Generator &g) except +ValueError 

void add_constraints(PPL_Constraint_System &cs) except +ValueError 

void add_generators(PPL_Generator_System &gs) except +ValueError 

void refine_with_constraint(PPL_Constraint &c) except +ValueError 

void refine_with_constraints(PPL_Constraint_System &cs) except +ValueError 

void unconstrain(PPL_Variable var) except +ValueError 

void intersection_assign(PPL_Polyhedron &y) except +ValueError 

void poly_hull_assign(PPL_Polyhedron &y) except +ValueError 

void upper_bound_assign(PPL_Polyhedron &y) except +ValueError 

void poly_difference_assign(PPL_Polyhedron &y) except +ValueError 

void difference_assign(PPL_Polyhedron &y) except +ValueError 

void drop_some_non_integer_points() 

void topological_closure_assign() 

void add_space_dimensions_and_embed(PPL_dimension_type m) except +ValueError 

void add_space_dimensions_and_project(PPL_dimension_type m) except +ValueError 

void concatenate_assign(PPL_Polyhedron &y) except +ValueError 

void remove_higher_space_dimensions(PPL_dimension_type new_dimension) except +ValueError 

void ascii_dump() 

int hash_code() 

PPL_dimension_type max_space_dimension() 

bint OK(cppbool check_not_empty=false) 

bint operator!=(PPL_Polyhedron &y) 

bint operator==(PPL_Polyhedron &y) 

  

cdef cppclass PPL_C_Polyhedron(PPL_Polyhedron): 

PPL_C_Polyhedron(PPL_dimension_type num_dimensions, PPL_Degenerate_Element) 

PPL_C_Polyhedron(PPL_Constraint_System &cs) except +ValueError 

PPL_C_Polyhedron(PPL_Generator_System &gs) except +ValueError 

PPL_C_Polyhedron(PPL_C_Polyhedron &y) 

  

cdef cppclass PPL_NNC_Polyhedron(PPL_Polyhedron): 

PPL_NNC_Polyhedron(PPL_dimension_type num_dimensions, PPL_Degenerate_Element kind) 

PPL_NNC_Polyhedron(PPL_Constraint_System &cs) except +ValueError 

PPL_NNC_Polyhedron(PPL_Generator_System &gs) except +ValueError 

PPL_NNC_Polyhedron(PPL_NNC_Polyhedron &y) 

PPL_NNC_Polyhedron(PPL_C_Polyhedron &y) 

  

cdef cppclass PPL_Poly_Gen_Relation: 

PPL_Poly_Gen_Relation(PPL_Poly_Gen_Relation &cpy_from) 

bint implies(PPL_Poly_Gen_Relation &y) 

void ascii_dump() 

bint OK() 

  

cdef cppclass PPL_Poly_Con_Relation: 

PPL_Poly_Con_Relation(PPL_Poly_Con_Relation &cpy_from) 

bint implies(PPL_Poly_Con_Relation &y) 

void ascii_dump() 

bint OK() 

  

cdef cppclass PPL_MIP_Problem: 

PPL_MIP_Problem(PPL_MIP_Problem &cpy_from) 

PPL_MIP_Problem(PPL_dimension_type dim) except +ValueError 

PPL_MIP_Problem(PPL_dimension_type dim, PPL_Constraint_System &cs, PPL_Linear_Expression &obj, PPL_Optimization_Mode) except +ValueError 

PPL_dimension_type space_dimension() 

PPL_Linear_Expression& objective_function() 

void clear() 

void add_space_dimensions_and_embed(PPL_dimension_type m) except +ValueError 

void add_constraint(PPL_Constraint &c) except +ValueError 

void add_constraints(PPL_Constraint_System &cs) except +ValueError 

void add_to_integer_space_dimensions(PPL_Variables_Set &i_vars) except +ValueError 

void set_objective_function(PPL_Linear_Expression &obj) except +ValueError 

void set_optimization_mode(PPL_Optimization_Mode mode) 

PPL_Optimization_Mode optimization_mode() 

bint is_satisfiable() 

MIP_Problem_Status solve() 

void evaluate_objective_function(PPL_Generator evaluating_point, PPL_Coefficient &num, PPL_Coefficient &den) except +ValueError 

PPL_Generator& feasible_point() 

PPL_Generator optimizing_point() except +ValueError 

void optimal_value(PPL_Coefficient &num, PPL_Coefficient &den) except +ValueError 

bint OK() 

PPL_MIP_Problem_Control_Parameter_Value get_control_parameter(PPL_MIP_Problem_Control_Parameter_Name name) 

void set_control_parameter(PPL_MIP_Problem_Control_Parameter_Value value) 

  

cdef extern from "ppl.hh": 

PPL_Generator PPL_line "Parma_Polyhedra_Library::line" (PPL_Linear_Expression &e) except +ValueError 

PPL_Generator PPL_ray "Parma_Polyhedra_Library::ray" (PPL_Linear_Expression &e) except +ValueError 

PPL_Generator PPL_point "Parma_Polyhedra_Library::point" (PPL_Linear_Expression &e, PPL_Coefficient &d) except +ValueError 

PPL_Generator PPL_closure_point "Parma_Polyhedra_Library::closure_point" (PPL_Linear_Expression &e, PPL_Coefficient &d) except +ValueError 

  

  

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

# Cython does not support static methods; hack around 

cdef extern from "ppl.hh": 

  

PPL_Poly_Gen_Relation PPL_Poly_Gen_Relation_nothing "Parma_Polyhedra_Library::Poly_Gen_Relation::nothing" () 

PPL_Poly_Gen_Relation PPL_Poly_Gen_Relation_subsumes "Parma_Polyhedra_Library::Poly_Gen_Relation::subsumes" () 

  

PPL_Poly_Con_Relation PPL_Poly_Con_Relation_nothing "Parma_Polyhedra_Library::Poly_Con_Relation::nothing" () 

PPL_Poly_Con_Relation PPL_Poly_Con_Relation_is_disjoint "Parma_Polyhedra_Library::Poly_Con_Relation::is_disjoint" () 

PPL_Poly_Con_Relation PPL_Poly_Con_Relation_strictly_intersects "Parma_Polyhedra_Library::Poly_Con_Relation::strictly_intersects" () 

PPL_Poly_Con_Relation PPL_Poly_Con_Relation_is_included "Parma_Polyhedra_Library::Poly_Con_Relation::is_included" () 

PPL_Poly_Con_Relation PPL_Poly_Con_Relation_saturates "Parma_Polyhedra_Library::Poly_Con_Relation::saturates" () 

  

  

  

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

# Workaround for private constructors 

cdef extern from "ppl_shim.hh": 

PPL_Poly_Gen_Relation* new_relation_with(PPL_Polyhedron &p, PPL_Generator &g) except +ValueError 

PPL_Poly_Con_Relation* new_relation_with(PPL_Polyhedron &p, PPL_Constraint &c) except +ValueError 

  

  

### Forward declarations ########################### 

cdef class _mutable_or_immutable(SageObject) 

cdef class Variable(object) 

cdef class Variables_Set(object) 

cdef class Linear_Expression(object) 

cdef class Generator(object) 

cdef class Generator_System(_mutable_or_immutable) 

cdef class Generator_System_iterator(object) 

cdef class Constraint(object) 

cdef class Constraint_System(_mutable_or_immutable) 

cdef class Constraint_System_iterator(object) 

cdef class Polyhedron(_mutable_or_immutable) 

cdef class C_Polyhedron(Polyhedron) 

cdef class NNC_Polyhedron(Polyhedron) 

cdef class Poly_Gen_Relation(object) 

cdef class Poly_Con_Relation(object) 

cdef class MIP_Problem(_mutable_or_immutable) 

  

  

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

### _mutable_or_immutable ########################## 

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

cdef class _mutable_or_immutable(SageObject): 

r""" 

A base class for mutable or immutable objects. 

  

By default, any object is mutable. It can then be 

:meth:`set_immutable`. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import _mutable_or_immutable as ExampleObj 

sage: x = ExampleObj() 

sage: x.is_mutable() 

True 

sage: x.is_immutable() 

False 

sage: x.set_immutable() 

sage: x.is_mutable() 

False 

""" 

  

cdef bint _is_mutable 

  

def __cinit__(self): 

""" 

The Cython constructor. 

  

TESTS:: 

  

sage: from sage.libs.ppl import _mutable_or_immutable as ExampleObj 

sage: x = ExampleObj() # indirect doctest 

sage: x.is_mutable() 

True 

""" 

self._is_mutable = True 

  

  

def set_immutable(self): 

""" 

Make this object immutable. 

  

This operation cannot be undone. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import _mutable_or_immutable as ExampleObj 

sage: x = ExampleObj() 

sage: x.is_mutable() 

True 

sage: x.set_immutable() 

sage: x.is_mutable() 

False 

""" 

self._is_mutable = False 

  

  

def is_mutable(self): 

""" 

Return whether this object is mutable. 

  

The data members of the object can only be modified if the 

object is mutable. 

  

OUTPUT: 

  

Boolean. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import _mutable_or_immutable as ExampleObj 

sage: x = ExampleObj() 

sage: x.is_mutable() 

True 

""" 

return self._is_mutable 

  

  

def is_immutable(self): 

""" 

Return whether this object is immutable. 

  

OUTPUT: 

  

Boolean. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import _mutable_or_immutable as ExampleObj 

sage: x = ExampleObj() 

sage: x.is_immutable() 

False 

""" 

return not self._is_mutable 

  

  

def assert_mutable(self, msg): 

r""" 

Raise ``ValueError`` if the object is not mutable. 

  

INPUT: 

  

- ``msg`` -- a string. The message to be returned together 

with the ``ValueError`` 

  

OUTPUT: 

  

This method returns no output. A ``ValueError``` is raised if 

the object is not mutable. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import _mutable_or_immutable as ExampleObj 

sage: x = ExampleObj() 

sage: x.assert_mutable("this will not trigger") 

sage: x.set_immutable() 

sage: x.assert_mutable("this will trigger") 

Traceback (most recent call last): 

... 

ValueError: this will trigger 

""" 

if not self._is_mutable: 

raise ValueError(msg) 

  

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

### MIP_Problem #################################### 

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

cdef class MIP_Problem(_mutable_or_immutable): 

r""" 

wrapper for PPL's MIP_Problem class 

  

An object of the class MIP_Problem represents a Mixed Integer 

(Linear) Program problem. 

  

INPUT: 

  

- ``dim`` -- integer 

- ``args`` -- an array of the defining data of the MIP_Problem. 

For each element, any one of the following is accepted: 

  

* A :class:`Constraint_System`. 

  

* A :class:`Linear_Expression`. 

  

OUTPUT: 

  

A :class:`MIP_Problem`. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, Constraint_System, MIP_Problem 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: cs = Constraint_System() 

sage: cs.insert( x >= 0) 

sage: cs.insert( y >= 0 ) 

sage: cs.insert( 3 * x + 5 * y <= 10 ) 

sage: m = MIP_Problem(2, cs, x + y) 

sage: m.optimal_value() 

10/3 

sage: m.optimizing_point() 

point(10/3, 0/3) 

""" 

cdef PPL_MIP_Problem *thisptr 

  

def __repr__(self): 

""" 

String representation of MIP Problem. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, Constraint_System, MIP_Problem 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: cs = Constraint_System() 

sage: cs.insert( x >= 0 ) 

sage: cs.insert( y >= 0 ) 

sage: cs.insert( 3 * x + 5 * y <= 10 ) 

sage: m = MIP_Problem(2, cs, x + y) 

sage: m 

A MIP_Problem 

Maximize: x0+x1 

Subject to constraints 

""" 

ret = 'A MIP_Problem\n' 

if self.optimization_mode() == 'maximization': 

ret += 'Maximize' 

else: 

ret += 'Minimize' 

ret += ': ' + str(self.objective_function()) + '\n' 

ret += 'Subject to constraints\n' 

  

return ret 

  

def __cinit__(self, PPL_dimension_type dim = 0, *args): 

""" 

Constructor 

  

TESTS:: 

  

sage: from sage.libs.ppl import Variable, Constraint_System, MIP_Problem 

sage: MIP_Problem(0) 

A MIP_Problem 

Maximize: 0 

Subject to constraints 

  

Check that :trac:`19903` is fixed:: 

  

sage: from sage.libs.ppl import Variable, Constraint_System, MIP_Problem 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: cs = Constraint_System() 

sage: cs.insert(x + y <= 2) 

sage: _ = MIP_Problem(2, cs, 0) 

sage: _ = MIP_Problem(2, cs, x) 

sage: _ = MIP_Problem(2, None, None) 

Traceback (most recent call last): 

... 

TypeError: Cannot convert NoneType to sage.libs.ppl.Constraint_System 

sage: _ = MIP_Problem(2, cs, 'hey') 

Traceback (most recent call last): 

... 

TypeError: unable to convert 'hey' to an integer 

sage: _ = MIP_Problem(2, cs, x, 'middle') 

Traceback (most recent call last): 

... 

ValueError: unknown mode 'middle' 

""" 

cdef Constraint_System cs 

cdef Linear_Expression obj 

cdef PPL_Optimization_Mode mode 

  

if not args: 

self.thisptr = new PPL_MIP_Problem(dim) 

  

elif 2 <= len(args) <= 3: 

cs = <Constraint_System?>args[0] 

try: 

obj = <Linear_Expression?> args[1] 

except TypeError: 

obj = Linear_Expression(args[1]) 

  

mode = MAXIMIZATION 

if len(args) == 3: 

if args[2] == 'maximization': 

mode = MAXIMIZATION 

elif args[2] == 'minimization': 

mode = MINIMIZATION 

else: 

raise ValueError('unknown mode {!r}'.format(args[2])) 

self.thisptr = new PPL_MIP_Problem(dim, cs.thisptr[0], obj.thisptr[0], mode) 

  

else: 

raise ValueError('cannot initialize from {!r}'.format(args)) 

  

def __dealloc__(self): 

""" 

The Cython destructor 

""" 

del self.thisptr 

  

def optimization_mode(self): 

""" 

Return the optimization mode used in the MIP_Problem. 

  

It will return "maximization" if the MIP_Problem was set 

to MAXIMIZATION mode, and "minimization" otherwise. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import MIP_Problem 

sage: m = MIP_Problem() 

sage: m.optimization_mode() 

'maximization' 

""" 

if self.thisptr.optimization_mode() == MAXIMIZATION: 

return "maximization" 

elif self.thisptr.optimization_mode() == MINIMIZATION: 

return "minimization" 

  

def optimal_value(self): 

""" 

Return the optimal value of the MIP_Problem. ValueError thrown if self does not 

have an optimizing point, i.e., if the MIP problem is unbounded or not satisfiable. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, Constraint_System, MIP_Problem 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: cs = Constraint_System() 

sage: cs.insert( x >= 0 ) 

sage: cs.insert( y >= 0 ) 

sage: cs.insert( 3 * x + 5 * y <= 10 ) 

sage: m = MIP_Problem(2, cs, x + y) 

sage: m.optimal_value() 

10/3 

sage: cs = Constraint_System() 

sage: cs.insert( x >= 0 ) 

sage: m = MIP_Problem(1, cs, x + x ) 

sage: m.optimal_value() 

Traceback (most recent call last): 

... 

ValueError: PPL::MIP_Problem::optimizing_point(): 

*this does not have an optimizing point. 

""" 

cdef PPL_Coefficient sup_n 

cdef PPL_Coefficient sup_d 

  

sig_on() 

try: 

self.thisptr.optimal_value(sup_n, sup_d) 

finally: 

sig_off() 

  

cdef Integer Int_sup_n = Integer(0) 

mpz_set(Int_sup_n.value, sup_n.get_mpz_t()) 

cdef Integer Int_sup_d = Integer(0) 

mpz_set(Int_sup_d.value, sup_d.get_mpz_t()) 

  

return Rational((Int_sup_n, Int_sup_d)) 

  

def space_dimension(self): 

""" 

Return the space dimension of the MIP_Problem. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, Constraint_System, MIP_Problem 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: cs = Constraint_System() 

sage: cs.insert( x >= 0) 

sage: cs.insert( y >= 0 ) 

sage: cs.insert( 3 * x + 5 * y <= 10 ) 

sage: m = MIP_Problem(2, cs, x + y) 

sage: m.space_dimension() 

2 

""" 

return self.thisptr.space_dimension() 

  

def objective_function(self): 

""" 

Return the optimal value of the MIP_Problem. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, Constraint_System, MIP_Problem 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: cs = Constraint_System() 

sage: cs.insert( x >= 0) 

sage: cs.insert( y >= 0 ) 

sage: cs.insert( 3 * x + 5 * y <= 10 ) 

sage: m = MIP_Problem(2, cs, x + y) 

sage: m.objective_function() 

x0+x1 

""" 

rc = Linear_Expression() 

rc.thisptr[0] = self.thisptr.objective_function() 

return rc 

  

def clear(self): 

""" 

Reset the MIP_Problem to be equal to the trivial MIP_Problem. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, Constraint_System, MIP_Problem 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: cs = Constraint_System() 

sage: cs.insert( x >= 0) 

sage: cs.insert( y >= 0 ) 

sage: cs.insert( 3 * x + 5 * y <= 10 ) 

sage: m = MIP_Problem(2, cs, x + y) 

sage: m.objective_function() 

x0+x1 

sage: m.clear() 

sage: m.objective_function() 

0 

""" 

self.thisptr.clear() 

  

def add_space_dimensions_and_embed(self, PPL_dimension_type m): 

""" 

Adds m new space dimensions and embeds the old MIP problem in the new vector space. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, Constraint_System, MIP_Problem 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: cs = Constraint_System() 

sage: cs.insert( x >= 0) 

sage: cs.insert( y >= 0 ) 

sage: cs.insert( 3 * x + 5 * y <= 10 ) 

sage: m = MIP_Problem(2, cs, x + y) 

sage: m.add_space_dimensions_and_embed(5) 

sage: m.space_dimension() 

7 

""" 

self.assert_mutable("The MIP_Problem is not mutable!"); 

sig_on() 

self.thisptr.add_space_dimensions_and_embed(m) 

sig_off() 

  

def _add_rational_constraint(self, e, denom, lower, upper): 

""" 

Helper function for adding constraints: add the constraint 

``lower <= e/denom <= upper``. 

 

INPUT: 

  

- ``e`` -- a linear expression (type ``Linear_Expression``) 

  

- ``denom`` -- a positive integer 

  

- ``lower``, ``upper`` -- a rational number or ``None``, where 

``None`` means that there is no constraint 

  

TESTS: 

  

Create a linear system with only equalities as constraints:: 

  

sage: p = MixedIntegerLinearProgram(solver="PPL") 

sage: x = p.new_variable(nonnegative=False) 

sage: n = 40 

sage: v = random_vector(QQ, n) 

sage: M = random_matrix(QQ, 2*n, n) 

sage: for j in range(2*n): # indirect doctest 

....: lhs = p.sum(M[j,i]*x[i] for i in range(n)) 

....: rhs = M.row(j).inner_product(v) 

....: p.add_constraint(lhs == rhs) 

sage: p.solve() # long time 

0 

  

""" 

cdef Rational rhs 

  

if lower == upper: 

if lower is not None: 

rhs = Rational(lower * denom) 

self.add_constraint(e * rhs.denominator() == rhs.numerator()) 

else: 

if lower is not None: 

rhs = Rational(lower * denom) 

self.add_constraint(e * rhs.denominator() >= rhs.numerator()) 

if upper is not None: 

rhs = Rational(upper * denom) 

self.add_constraint(e * rhs.denominator() <= rhs.numerator()) 

  

def add_constraint(self, Constraint c): 

""" 

Adds a copy of constraint c to the MIP problem. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, Constraint_System, MIP_Problem 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: m = MIP_Problem() 

sage: m.add_space_dimensions_and_embed(2) 

sage: m.add_constraint(x >= 0) 

sage: m.add_constraint(y >= 0) 

sage: m.add_constraint(3 * x + 5 * y <= 10) 

sage: m.set_objective_function(x + y) 

sage: m.optimal_value() 

10/3 

  

TESTS:: 

  

sage: z = Variable(2) 

sage: m.add_constraint(z >= -3) 

Traceback (most recent call last): 

... 

ValueError: PPL::MIP_Problem::add_constraint(c): 

c.space_dimension() == 3 exceeds this->space_dimension == 2. 

""" 

self.assert_mutable("The MIP_Problem is not mutable!"); 

sig_on() 

try: 

self.thisptr.add_constraint(c.thisptr[0]) 

finally: 

sig_off() 

  

def add_constraints(self, Constraint_System cs): 

""" 

Adds a copy of the constraints in cs to the MIP problem. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, Constraint_System, MIP_Problem 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: cs = Constraint_System() 

sage: cs.insert( x >= 0) 

sage: cs.insert( y >= 0 ) 

sage: cs.insert( 3 * x + 5 * y <= 10 ) 

sage: m = MIP_Problem(2) 

sage: m.set_objective_function(x + y) 

sage: m.add_constraints(cs) 

sage: m.optimal_value() 

10/3 

  

TESTS:: 

  

sage: p = Variable(9) 

sage: cs.insert(p >= -3) 

sage: m.add_constraints(cs) 

Traceback (most recent call last): 

... 

ValueError: PPL::MIP_Problem::add_constraints(cs): 

cs.space_dimension() == 10 exceeds this->space_dimension() == 2. 

""" 

self.assert_mutable("The MIP_Problem is not mutable!"); 

sig_on() 

try: 

self.thisptr.add_constraints(cs.thisptr[0]) 

finally: 

sig_off() 

  

def add_to_integer_space_dimensions(self, Variables_Set i_vars): 

""" 

Sets the variables whose indexes are in set `i_vars` to be integer space dimensions. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, Variables_Set, Constraint_System, MIP_Problem 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: cs = Constraint_System() 

sage: cs.insert( x >= 0) 

sage: cs.insert( y >= 0 ) 

sage: cs.insert( 3 * x + 5 * y <= 10 ) 

sage: m = MIP_Problem(2) 

sage: m.set_objective_function(x + y) 

sage: m.add_constraints(cs) 

sage: i_vars = Variables_Set(x, y) 

sage: m.add_to_integer_space_dimensions(i_vars) 

sage: m.optimal_value() 

3 

""" 

self.assert_mutable("The MIP_Problem is not mutable!"); 

sig_on() 

try: 

self.thisptr.add_to_integer_space_dimensions(i_vars.thisptr[0]) 

finally: 

sig_off() 

  

def set_objective_function(self, Linear_Expression obj): 

""" 

Sets the objective function to obj. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, Constraint_System, MIP_Problem 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: m = MIP_Problem() 

sage: m.add_space_dimensions_and_embed(2) 

sage: m.add_constraint(x >= 0) 

sage: m.add_constraint(y >= 0) 

sage: m.add_constraint(3 * x + 5 * y <= 10) 

sage: m.set_objective_function(x + y) 

sage: m.optimal_value() 

10/3 

  

TESTS:: 

  

sage: z = Variable(2) 

sage: m.set_objective_function(x + y + z) 

Traceback (most recent call last): 

... 

ValueError: PPL::MIP_Problem::set_objective_function(obj): 

obj.space_dimension() == 3 exceeds this->space_dimension == 2. 

""" 

self.assert_mutable("The MIP_Problem is not mutable!"); 

self.thisptr.set_objective_function(obj.thisptr[0]) 

  

def set_optimization_mode(self, mode): 

""" 

Sets the optimization mode to mode. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import MIP_Problem 

sage: m = MIP_Problem() 

sage: m.optimization_mode() 

'maximization' 

sage: m.set_optimization_mode('minimization') 

sage: m.optimization_mode() 

'minimization' 

  

TESTS:: 

  

sage: m.set_optimization_mode('max') 

Traceback (most recent call last): 

... 

ValueError: Unknown value: mode=max. 

""" 

if mode == 'minimization': 

self.thisptr.set_optimization_mode(MINIMIZATION) 

elif mode == 'maximization': 

self.thisptr.set_optimization_mode(MAXIMIZATION) 

else: 

raise ValueError('Unknown value: mode={}.'.format(mode)) 

  

def is_satisfiable(self): 

""" 

Check if the MIP_Problem is satisfiable 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, Constraint_System, MIP_Problem 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: m = MIP_Problem() 

sage: m.add_space_dimensions_and_embed(2) 

sage: m.add_constraint(x >= 0) 

sage: m.add_constraint(y >= 0) 

sage: m.add_constraint(3 * x + 5 * y <= 10) 

sage: m.is_satisfiable() 

True 

""" 

ret = self.thisptr.is_satisfiable() 

  

return ret 

  

def evaluate_objective_function(self, Generator evaluating_point): 

""" 

Return the result of evaluating the objective function on evaluating_point. ValueError thrown 

if self and evaluating_point are dimension-incompatible or if the generator evaluating_point is not a point. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, Constraint_System, MIP_Problem, Generator 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: m = MIP_Problem() 

sage: m.add_space_dimensions_and_embed(2) 

sage: m.add_constraint(x >= 0) 

sage: m.add_constraint(y >= 0) 

sage: m.add_constraint(3 * x + 5 * y <= 10) 

sage: m.set_objective_function(x + y) 

sage: g = Generator.point(5 * x - 2 * y, 7) 

sage: m.evaluate_objective_function(g) 

3/7 

sage: z = Variable(2) 

sage: g = Generator.point(5 * x - 2 * z, 7) 

sage: m.evaluate_objective_function(g) 

Traceback (most recent call last): 

... 

ValueError: PPL::MIP_Problem::evaluate_objective_function(p, n, d): 

*this and p are dimension incompatible. 

""" 

cdef PPL_Coefficient sup_n 

cdef PPL_Coefficient sup_d 

  

sig_on() 

try: 

self.thisptr.evaluate_objective_function(evaluating_point.thisptr[0], sup_n, sup_d) 

finally: 

sig_off() 

  

cdef Integer Int_sup_n = Integer(0) 

mpz_set(Int_sup_n.value, sup_n.get_mpz_t()) 

cdef Integer Int_sup_d = Integer(0) 

mpz_set(Int_sup_d.value, sup_d.get_mpz_t()) 

  

return Rational((Int_sup_n, Int_sup_d)) 

  

def solve(self): 

""" 

Optimizes the MIP_Problem 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, Constraint_System, MIP_Problem 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: m = MIP_Problem() 

sage: m.add_space_dimensions_and_embed(2) 

sage: m.add_constraint(x >= 0) 

sage: m.add_constraint(y >= 0) 

sage: m.add_constraint(3 * x + 5 * y <= 10) 

sage: m.set_objective_function(x + y) 

sage: m.solve() 

{'status': 'optimized'} 

""" 

sig_on() 

try: 

tmp = self.thisptr.solve() 

finally: 

sig_off() 

if tmp == UNFEASIBLE_MIP_PROBLEM: 

return { 'status':'unfeasible' } 

elif tmp == UNBOUNDED_MIP_PROBLEM: 

return { 'status':'unbounded' } 

else: 

return { 'status':'optimized' } 

  

def optimizing_point(self): 

""" 

Returns an optimal point for the MIP_Problem, if it exists. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, Constraint_System, MIP_Problem 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: m = MIP_Problem() 

sage: m.add_space_dimensions_and_embed(2) 

sage: m.add_constraint(x >= 0) 

sage: m.add_constraint(y >= 0) 

sage: m.add_constraint(3 * x + 5 * y <= 10) 

sage: m.set_objective_function(x + y) 

sage: m.optimizing_point() 

point(10/3, 0/3) 

""" 

cdef PPL_Generator *g 

sig_on() 

try: 

g = new_MIP_optimizing_point(self.thisptr[0]) 

finally: 

sig_off() 

return _wrap_Generator(g[0]) 

  

def OK(self): 

""" 

Check if all the invariants are satisfied. 

  

OUTPUT: 

  

``True`` if and only if ``self`` satisfies all the invariants. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, Constraint_System, MIP_Problem 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: m = MIP_Problem() 

sage: m.add_space_dimensions_and_embed(2) 

sage: m.add_constraint(x >= 0) 

sage: m.OK() 

True 

""" 

return self.thisptr.OK() 

  

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

### Polyhedron ##################################### 

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

cdef class Polyhedron(_mutable_or_immutable): 

r""" 

Wrapper for PPL's ``Polyhedron`` class. 

  

An object of the class Polyhedron represents a convex polyhedron 

in the vector space. 

  

A polyhedron can be specified as either a finite system of 

constraints or a finite system of generators (see Section 

Representations of Convex Polyhedra) and it is always possible to 

obtain either representation. That is, if we know the system of 

constraints, we can obtain from this the system of generators that 

define the same polyhedron and vice versa. These systems can 

contain redundant members: in this case we say that they are not 

in the minimal form. 

  

INPUT/OUTPUT: 

  

This is an abstract base for :class:`C_Polyhedron` and 

:class:`NNC_Polyhedron`. You cannot instantiate this class. 

""" 

  

cdef PPL_Polyhedron *thisptr 

  

  

def __init__(self): 

r""" 

The Python constructor. 

  

See also :class:`C_Polyhedron` and 

:class:`NNC_Polyhedron`. You must not instantiate 

:class:`Polyhedron` objects. 

  

TESTS:: 

  

sage: from sage.libs.ppl import Polyhedron 

sage: Polyhedron() 

Traceback (most recent call last): 

... 

NotImplementedError: The Polyhedron class is abstract, you must not instantiate it. 

""" 

raise NotImplementedError('The Polyhedron class is abstract, you must not instantiate it.') 

  

  

def _repr_(self): 

""" 

Return a string representation. 

  

OUTPUT: 

  

String. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, C_Polyhedron 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: C_Polyhedron( 5*x-2*y >= x+y-1 )._repr_() 

'A 2-dimensional polyhedron in QQ^2 defined as the convex hull of 1 point, 1 ray, 1 line' 

  

Special cases:: 

  

sage: C_Polyhedron(3, 'empty')._repr_() 

'The empty polyhedron in QQ^3' 

sage: C_Polyhedron(3, 'universe')._repr_() 

'The space-filling polyhedron in QQ^3' 

""" 

dim = self.affine_dimension() 

ambient_dim = self.space_dimension() 

gs = self.minimized_generators() 

n_points = 0 

n_closure_points = 0 

n_lines = 0 

n_rays = 0 

for g in gs: 

if g.is_line(): 

n_lines += 1 

elif g.is_ray(): 

n_rays += 1 

elif g.is_point(): 

n_points += 1 

elif g.is_closure_point(): 

n_closure_points += 1 

else: 

assert False 

if self.is_empty(): 

return 'The empty polyhedron in QQ^'+str(ambient_dim) 

if self.is_universe(): 

return 'The space-filling polyhedron in QQ^'+str(ambient_dim) 

desc = 'A ' + str(dim) + '-dimensional polyhedron' 

desc += ' in QQ' 

desc += '^' + str(ambient_dim) 

desc += ' defined as the convex hull of ' 

first = True 

if n_points>0: 

if not first: 

desc += ", " 

first = False 

desc += str(n_points) 

if n_points==1: desc += ' point' 

else: desc += ' points' 

if n_closure_points>0: 

if not first: 

desc += ", " 

first = False 

desc += str(n_closure_points) 

if n_closure_points==1: desc += ' closure_point' 

else: desc += ' closure_points' 

if n_rays>0: 

if not first: 

desc += ", " 

first = False 

desc += str(n_rays) 

if n_rays==1: desc += ' ray' 

else: desc += ' rays' 

if n_lines>0: 

if not first: 

desc += ", " 

first = False 

desc += repr(n_lines) 

if n_lines==1: desc +=' line' 

else: desc +=' lines' 

return desc; 

  

  

def space_dimension(self): 

r""" 

Return the dimension of the vector space enclosing ``self``. 

  

OUTPUT: 

  

Integer. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, C_Polyhedron 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: p = C_Polyhedron( 5*x-2*y >= x+y-1 ) 

sage: p.space_dimension() 

2 

""" 

return self.thisptr.space_dimension() 

  

  

def affine_dimension(self): 

r""" 

Return the affine dimension of ``self``. 

  

OUTPUT: 

  

An integer. Returns 0 if ``self`` is empty. Otherwise, returns 

the affine dimension of ``self``. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, C_Polyhedron 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: p = C_Polyhedron( 5*x-2*y == x+y-1 ) 

sage: p.affine_dimension() 

1 

""" 

sig_on() 

cdef size_t dim = self.thisptr.affine_dimension() 

sig_off() 

return dim 

  

  

def constraints(self): 

r""" 

Returns the system of constraints. 

  

See also :meth:`minimized_constraints`. 

  

OUTPUT: 

  

A :class:`Constraint_System`. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, C_Polyhedron 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: p = C_Polyhedron( y>=0 ) 

sage: p.add_constraint( x>=0 ) 

sage: p.add_constraint( x+y>=0 ) 

sage: p.constraints() 

Constraint_System {x1>=0, x0>=0, x0+x1>=0} 

sage: p.minimized_constraints() 

Constraint_System {x1>=0, x0>=0} 

""" 

sig_on() 

cdef PPL_Constraint_System cs = self.thisptr.constraints() 

sig_off() 

return _wrap_Constraint_System(cs) 

  

  

def minimized_constraints(self): 

r""" 

Returns the minimized system of constraints. 

  

See also :meth:`constraints`. 

  

OUTPUT: 

  

A :class:`Constraint_System`. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, C_Polyhedron 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: p = C_Polyhedron( y>=0 ) 

sage: p.add_constraint( x>=0 ) 

sage: p.add_constraint( x+y>=0 ) 

sage: p.constraints() 

Constraint_System {x1>=0, x0>=0, x0+x1>=0} 

sage: p.minimized_constraints() 

Constraint_System {x1>=0, x0>=0} 

""" 

sig_on() 

cdef PPL_Constraint_System cs = self.thisptr.minimized_constraints() 

sig_off() 

return _wrap_Constraint_System(cs) 

  

  

def generators(self): 

r""" 

Returns the system of generators. 

  

See also :meth:`minimized_generators`. 

  

OUTPUT: 

  

A :class:`Generator_System`. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, C_Polyhedron, point 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: p = C_Polyhedron(3,'empty') 

sage: p.add_generator( point(-x-y) ) 

sage: p.add_generator( point(0) ) 

sage: p.add_generator( point(+x+y) ) 

sage: p.generators() 

Generator_System {point(-1/1, -1/1, 0/1), point(0/1, 0/1, 0/1), point(1/1, 1/1, 0/1)} 

sage: p.minimized_generators() 

Generator_System {point(-1/1, -1/1, 0/1), point(1/1, 1/1, 0/1)} 

""" 

sig_on() 

cdef PPL_Generator_System gs = self.thisptr.generators() 

sig_off() 

return _wrap_Generator_System(gs) 

  

  

def minimized_generators(self): 

r""" 

Returns the minimized system of generators. 

  

See also :meth:`generators`. 

  

OUTPUT: 

  

A :class:`Generator_System`. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, C_Polyhedron, point 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: p = C_Polyhedron(3,'empty') 

sage: p.add_generator( point(-x-y) ) 

sage: p.add_generator( point(0) ) 

sage: p.add_generator( point(+x+y) ) 

sage: p.generators() 

Generator_System {point(-1/1, -1/1, 0/1), point(0/1, 0/1, 0/1), point(1/1, 1/1, 0/1)} 

sage: p.minimized_generators() 

Generator_System {point(-1/1, -1/1, 0/1), point(1/1, 1/1, 0/1)} 

""" 

sig_on() 

cdef PPL_Generator_System gs = self.thisptr.minimized_generators() 

sig_off() 

return _wrap_Generator_System(gs) 

  

  

cdef _relation_with_generator(Polyhedron self, Generator g): 

r""" 

Helper method for :meth:`relation_with`. 

""" 

rel = Poly_Gen_Relation(True) 

try: 

sig_on() 

try: 

rel.thisptr = new_relation_with(self.thisptr[0], g.thisptr[0]) 

finally: 

sig_off() 

except BaseException: 

# rel.thisptr must be set to something valid or rel.__dealloc__() will segfault 

rel.thisptr = new PPL_Poly_Gen_Relation(PPL_Poly_Gen_Relation_nothing()) 

raise 

return rel 

  

  

cdef _relation_with_constraint(Polyhedron self, Constraint c): 

r""" 

Helper method for :meth:`relation_with`. 

""" 

rel = Poly_Con_Relation(True) 

try: 

sig_on() 

try: 

rel.thisptr = new_relation_with(self.thisptr[0], c.thisptr[0]) 

finally: 

sig_off() 

except BaseException: 

# rel.thisptr must be set to something valid or rel.__dealloc__() will segfault 

rel.thisptr = new PPL_Poly_Con_Relation(PPL_Poly_Con_Relation_nothing()) 

raise 

return rel 

  

  

def relation_with(self, arg): 

r""" 

Return the relations holding between the polyhedron ``self`` 

and the generator or constraint ``arg``. 

  

INPUT: 

  

- ``arg`` -- a :class:`Generator` or a :class:`Constraint`. 

  

OUTPUT: 

  

A :class:`Poly_Gen_Relation` or a :class:`Poly_Con_Relation` 

according to the type of the input. 

  

Raises ``ValueError`` if ``self`` and the generator/constraint 

``arg`` are dimension-incompatible. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, C_Polyhedron, point, ray, Poly_Con_Relation 

sage: x = Variable(0); y = Variable(1) 

sage: p = C_Polyhedron(2, 'empty') 

sage: p.add_generator( point(1*x+0*y) ) 

sage: p.add_generator( point(0*x+1*y) ) 

sage: p.minimized_constraints() 

Constraint_System {x0+x1-1==0, -x1+1>=0, x1>=0} 

sage: p.relation_with( point(1*x+1*y) ) 

nothing 

sage: p.relation_with( point(1*x+1*y, 2) ) 

subsumes 

sage: p.relation_with( x+y==-1 ) 

is_disjoint 

sage: p.relation_with( x==y ) 

strictly_intersects 

sage: p.relation_with( x+y<=1 ) 

is_included, saturates 

sage: p.relation_with( x+y<1 ) 

is_disjoint, saturates 

  

In a Sage program you will usually use :meth:`relation_with` 

together with :meth:`~sage.libs.ppl.Poly_Gen_Relation.implies` 

or :meth:`~sage.libs.ppl.Poly_Con_Relation.implies`, for 

example:: 

  

sage: p.relation_with( x+y<1 ).implies(Poly_Con_Relation.saturates()) 

True 

  

You can only get relations with dimension-compatible 

generators or constraints:: 

  

sage: z = Variable(2) 

sage: p.relation_with( point(x+y+z) ) 

Traceback (most recent call last): 

... 

ValueError: PPL::C_Polyhedron::relation_with(g): 

this->space_dimension() == 2, g.space_dimension() == 3. 

sage: p.relation_with( z>0 ) 

Traceback (most recent call last): 

... 

ValueError: PPL::C_Polyhedron::relation_with(c): 

this->space_dimension() == 2, c.space_dimension() == 3. 

""" 

if isinstance(arg, Generator): 

return self._relation_with_generator(arg) 

if isinstance(arg, Constraint): 

return self._relation_with_constraint(arg) 

else: 

raise TypeError('Argument must be Generator or a Constraint') 

  

  

def is_empty(self): 

""" 

Test if ``self`` is an empty polyhedron. 

  

OUTPUT: 

  

Boolean. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import C_Polyhedron 

sage: C_Polyhedron(3, 'empty').is_empty() 

True 

sage: C_Polyhedron(3, 'universe').is_empty() 

False 

""" 

sig_on() 

cdef bint result = self.thisptr.is_empty() 

sig_off() 

return result 

  

  

def is_universe(self): 

""" 

Test if ``self`` is a universe (space-filling) polyhedron. 

  

OUTPUT: 

  

Boolean. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import C_Polyhedron 

sage: C_Polyhedron(3, 'empty').is_universe() 

False 

sage: C_Polyhedron(3, 'universe').is_universe() 

True 

""" 

sig_on() 

cdef bint result = self.thisptr.is_universe() 

sig_off() 

return result 

  

  

def is_topologically_closed(self): 

""" 

Tests if ``self`` is topologically closed. 

  

OUTPUT: 

  

Returns ``True`` if and only if ``self`` is a topologically 

closed subset of the ambient vector space. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, C_Polyhedron, NNC_Polyhedron 

sage: x = Variable(0); y = Variable(1) 

sage: C_Polyhedron(3, 'universe').is_topologically_closed() 

True 

sage: C_Polyhedron( x>=1 ).is_topologically_closed() 

True 

sage: NNC_Polyhedron( x>1 ).is_topologically_closed() 

False 

""" 

sig_on() 

cdef bint result = self.thisptr.is_topologically_closed() 

sig_off() 

return result 

  

  

def is_disjoint_from(self, Polyhedron y): 

r""" 

Tests whether ``self`` and ``y`` are disjoint. 

  

INPUT: 

  

- ``y`` -- a :class:`Polyhedron`. 

  

OUTPUT: 

  

Boolean. Returns ``True`` if and only if ``self`` and ``y`` 

are disjoint. 

  

Rayises a ``ValueError`` if ``self`` and ``y`` are 

topology-incompatible or dimension-incompatible. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, C_Polyhedron, NNC_Polyhedron 

sage: x = Variable(0); y = Variable(1) 

sage: C_Polyhedron(x<=0).is_disjoint_from( C_Polyhedron(x>=1) ) 

True 

  

This is not allowed:: 

  

sage: x = Variable(0); y = Variable(1) 

sage: poly_1d = C_Polyhedron(x<=0) 

sage: poly_2d = C_Polyhedron(x+0*y>=1) 

sage: poly_1d.is_disjoint_from(poly_2d) 

Traceback (most recent call last): 

... 

ValueError: PPL::C_Polyhedron::intersection_assign(y): 

this->space_dimension() == 1, y.space_dimension() == 2. 

  

Nor is this:: 

  

sage: x = Variable(0); y = Variable(1) 

sage: c_poly = C_Polyhedron( x<=0 ) 

sage: nnc_poly = NNC_Polyhedron( x >0 ) 

sage: c_poly.is_disjoint_from(nnc_poly) 

Traceback (most recent call last): 

... 

ValueError: PPL::C_Polyhedron::intersection_assign(y): 

y is a NNC_Polyhedron. 

sage: NNC_Polyhedron(c_poly).is_disjoint_from(nnc_poly) 

True 

""" 

cdef bint result 

sig_on() 

try: 

result = self.thisptr.is_disjoint_from(y.thisptr[0]) 

finally: 

sig_off() 

return result 

  

  

def is_discrete(self): 

r""" 

Test whether ``self`` is discrete. 

  

OUTPUT: 

  

Boolean. Returns ``True`` if and only if ``self`` is discrete. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, C_Polyhedron, point, ray 

sage: x = Variable(0); y = Variable(1) 

sage: p = C_Polyhedron( point(1*x+2*y) ) 

sage: p.is_discrete() 

True 

sage: p.add_generator( point(x) ) 

sage: p.is_discrete() 

False 

""" 

sig_on() 

cdef bint result = self.thisptr.is_discrete() 

sig_off() 

return result 

  

  

def is_bounded(self): 

r""" 

Test whether ``self`` is bounded. 

  

OUTPUT: 

  

Boolean. Returns ``True`` if and only if ``self`` is a bounded polyhedron. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, NNC_Polyhedron, point, closure_point, ray 

sage: x = Variable(0) 

sage: p = NNC_Polyhedron( point(0*x) ) 

sage: p.add_generator( closure_point(1*x) ) 

sage: p.is_bounded() 

True 

sage: p.add_generator( ray(1*x) ) 

sage: p.is_bounded() 

False 

""" 

sig_on() 

cdef bint result = self.thisptr.is_bounded() 

sig_off() 

return result 

  

  

def contains_integer_point(self): 

r""" 

Test whether ``self`` contains an integer point. 

  

OUTPUT: 

  

Boolean. Returns ``True`` if and only if ``self`` contains an 

integer point. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, NNC_Polyhedron 

sage: x = Variable(0) 

sage: p = NNC_Polyhedron(x>0) 

sage: p.add_constraint(x<1) 

sage: p.contains_integer_point() 

False 

sage: p.topological_closure_assign() 

sage: p.contains_integer_point() 

True 

""" 

sig_on() 

cdef bint result = self.thisptr.contains_integer_point() 

sig_off() 

return result 

  

  

def constrains(self, Variable var): 

r""" 

Test whether ``var`` is constrained in ``self``. 

  

INPUT: 

  

- ``var`` -- a :class:`Variable`. 

  

OUTPUT: 

  

Boolean. Returns ``True`` if and only if ``var`` is 

constrained in ``self``. 

  

Raises a ``ValueError`` if ``var`` is not a space dimension of 

``self``. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, C_Polyhedron 

sage: x = Variable(0) 

sage: p = C_Polyhedron(1, 'universe') 

sage: p.constrains(x) 

False 

sage: p = C_Polyhedron(x>=0) 

sage: p.constrains(x) 

True 

sage: y = Variable(1) 

sage: p.constrains(y) 

Traceback (most recent call last): 

... 

ValueError: PPL::C_Polyhedron::constrains(v): 

this->space_dimension() == 1, v.space_dimension() == 2. 

""" 

cdef bint result 

sig_on() 

try: 

result = self.thisptr.constrains(var.thisptr[0]) 

finally: 

sig_off() 

return result 

  

  

def bounds_from_above(self, Linear_Expression expr): 

r""" 

Test whether the ``expr`` is bounded from above. 

  

INPUT: 

  

- ``expr`` -- a :class:`Linear_Expression` 

  

OUTPUT: 

  

Boolean. Returns ``True`` if and only if ``expr`` is bounded 

from above in ``self``. 

  

Raises a ``ValueError`` if ``expr`` and ``this`` are 

dimension-incompatible. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, C_Polyhedron, Linear_Expression 

sage: x = Variable(0); y = Variable(1) 

sage: p = C_Polyhedron(y<=0) 

sage: p.bounds_from_above(x+1) 

False 

sage: p.bounds_from_above(Linear_Expression(y)) 

True 

sage: p = C_Polyhedron(x<=0) 

sage: p.bounds_from_above(y+1) 

Traceback (most recent call last): 

... 

ValueError: PPL::C_Polyhedron::bounds_from_above(e): 

this->space_dimension() == 1, e.space_dimension() == 2. 

""" 

cdef bint result 

sig_on() 

try: 

result = self.thisptr.bounds_from_above(expr.thisptr[0]) 

finally: 

sig_off() 

return result 

  

  

def bounds_from_below(self, Linear_Expression expr): 

r""" 

Test whether the ``expr`` is bounded from above. 

  

INPUT: 

  

- ``expr`` -- a :class:`Linear_Expression` 

  

OUTPUT: 

  

Boolean. Returns ``True`` if and only if ``expr`` is bounded 

from above in ``self``. 

  

Raises a ``ValueError`` if ``expr`` and ``this`` are 

dimension-incompatible. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, C_Polyhedron, Linear_Expression 

sage: x = Variable(0); y = Variable(1) 

sage: p = C_Polyhedron(y>=0) 

sage: p.bounds_from_below(x+1) 

False 

sage: p.bounds_from_below(Linear_Expression(y)) 

True 

sage: p = C_Polyhedron(x<=0) 

sage: p.bounds_from_below(y+1) 

Traceback (most recent call last): 

... 

ValueError: PPL::C_Polyhedron::bounds_from_below(e): 

this->space_dimension() == 1, e.space_dimension() == 2. 

""" 

cdef bint result 

sig_on() 

try: 

result = self.thisptr.bounds_from_below(expr.thisptr[0]) 

finally: 

sig_off() 

return result 

  

  

def maximize(self, Linear_Expression expr): 

r""" 

Maximize ``expr``. 

  

INPUT: 

  

- ``expr`` -- a :class:`Linear_Expression`. 

  

OUTPUT: 

  

A dictionary with the following keyword:value pair: 

  

* ``'bounded'``: Boolean. Whether the linear expression 

``expr`` is bounded from above on ``self``. 

  

If ``expr`` is bounded from above, the following additional 

keyword:value pairs are set to provide information about the 

supremum: 

  

* ``'sup_n'``: Integer. The numerator of the supremum value. 

  

* ``'sup_d'``: Non-zero integer. The denominator of the supremum 

value. 

  

* ``'maximum'``: Boolean. ``True`` if and only if the supremum 

is also the maximum value. 

  

* ``'generator'``: a :class:`Generator`. A point or closure 

point where expr reaches its supremum value. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, C_Polyhedron, NNC_Polyhedron, Constraint_System, Linear_Expression 

sage: x = Variable(0); y = Variable(1) 

sage: cs = Constraint_System() 

sage: cs.insert( x>=0 ) 

sage: cs.insert( y>=0 ) 

sage: cs.insert( 3*x+5*y<=10 ) 

sage: p = C_Polyhedron(cs) 

sage: p.maximize( x+y ) 

{'bounded': True, 

'generator': point(10/3, 0/3), 

'maximum': True, 

'sup_d': 3, 

'sup_n': 10} 

  

Unbounded case:: 

  

sage: cs = Constraint_System() 

sage: cs.insert( x>0 ) 

sage: p = NNC_Polyhedron(cs) 

sage: p.maximize( +x ) 

{'bounded': False} 

sage: p.maximize( -x ) 

{'bounded': True, 

'generator': closure_point(0/1), 

'maximum': False, 

'sup_d': 1, 

'sup_n': 0} 

""" 

cdef PPL_Coefficient sup_n 

cdef PPL_Coefficient sup_d 

cdef Generator g = point() 

cdef cppbool maximum 

sig_on() 

rc = self.thisptr.maximize(<PPL_Linear_Expression&>expr.thisptr[0], sup_n, sup_d, maximum, g.thisptr[0]) 

sig_off() 

  

cdef Integer Int_sup_n = Integer(0) 

mpz_set(Int_sup_n.value, sup_n.get_mpz_t()) 

cdef Integer Int_sup_d = Integer(0) 

mpz_set(Int_sup_d.value, sup_d.get_mpz_t()) 

  

if rc: 

return { 'bounded':True, 'sup_n':Int_sup_n, 'sup_d':Int_sup_d, 'maximum':maximum, 'generator':g } 

else: 

return { 'bounded':False } 

  

  

def minimize(self, Linear_Expression expr): 

r""" 

Minimize ``expr``. 

  

INPUT: 

  

- ``expr`` -- a :class:`Linear_Expression`. 

  

OUTPUT: 

  

A dictionary with the following keyword:value pair: 

  

* ``'bounded'``: Boolean. Whether the linear expression 

``expr`` is bounded from below on ``self``. 

  

If ``expr`` is bounded from below, the following additional 

keyword:value pairs are set to provide information about the 

infimum: 

  

* ``'inf_n'``: Integer. The numerator of the infimum value. 

  

* ``'inf_d'``: Non-zero integer. The denominator of the infimum 

value. 

  

* ``'minimum'``: Boolean. ``True`` if and only if the infimum 

is also the minimum value. 

  

* ``'generator'``: a :class:`Generator`. A point or closure 

point where expr reaches its infimum value. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, C_Polyhedron, NNC_Polyhedron, Constraint_System, Linear_Expression 

sage: x = Variable(0); y = Variable(1) 

sage: cs = Constraint_System() 

sage: cs.insert( x>=0 ) 

sage: cs.insert( y>=0 ) 

sage: cs.insert( 3*x+5*y<=10 ) 

sage: p = C_Polyhedron(cs) 

sage: p.minimize( x+y ) 

{'bounded': True, 

'generator': point(0/1, 0/1), 

'inf_d': 1, 

'inf_n': 0, 

'minimum': True} 

  

Unbounded case:: 

  

sage: cs = Constraint_System() 

sage: cs.insert( x>0 ) 

sage: p = NNC_Polyhedron(cs) 

sage: p.minimize( +x ) 

{'bounded': True, 

'generator': closure_point(0/1), 

'inf_d': 1, 

'inf_n': 0, 

'minimum': False} 

sage: p.minimize( -x ) 

{'bounded': False} 

""" 

cdef PPL_Coefficient inf_n 

cdef PPL_Coefficient inf_d 

cdef Generator g = point() 

cdef cppbool minimum 

sig_on() 

rc = self.thisptr.minimize(<PPL_Linear_Expression&>expr.thisptr[0], inf_n, inf_d, minimum, g.thisptr[0]) 

sig_off() 

  

cdef Integer Int_inf_n = Integer(0) 

mpz_set(Int_inf_n.value, inf_n.get_mpz_t()) 

cdef Integer Int_inf_d = Integer(0) 

mpz_set(Int_inf_d.value, inf_d.get_mpz_t()) 

  

if rc: 

return { 'bounded':True, 'inf_n':Int_inf_n, 'inf_d':Int_inf_d, 'minimum':minimum, 'generator':g } 

else: 

return { 'bounded':False } 

  

  

def contains(self, Polyhedron y): 

r""" 

Test whether ``self`` contains ``y``. 

  

INPUT: 

  

- ``y`` -- a :class:`Polyhedron`. 

  

OUTPUT: 

  

Boolean. Returns ``True`` if and only if ``self`` contains ``y``. 

  

Raises a ``ValueError`` if ``self`` and ``y`` are 

topology-incompatible or dimension-incompatible. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, C_Polyhedron, NNC_Polyhedron 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: p0 = C_Polyhedron( x>=0 ) 

sage: p1 = C_Polyhedron( x>=1 ) 

sage: p0.contains(p1) 

True 

sage: p1.contains(p0) 

False 

  

Errors are raised if the dimension or topology is not compatible:: 

  

sage: p0.contains(C_Polyhedron(y>=0)) 

Traceback (most recent call last): 

... 

ValueError: PPL::C_Polyhedron::contains(y): 

this->space_dimension() == 1, y.space_dimension() == 2. 

sage: p0.contains(NNC_Polyhedron(x>0)) 

Traceback (most recent call last): 

... 

ValueError: PPL::C_Polyhedron::contains(y): 

y is a NNC_Polyhedron. 

""" 

cdef bint result 

sig_on() 

try: 

result = self.thisptr.contains(y.thisptr[0]) 

finally: 

sig_off() 

return result 

  

  

def strictly_contains(self, Polyhedron y): 

r""" 

Test whether ``self`` strictly contains ``y``. 

  

INPUT: 

  

- ``y`` -- a :class:`Polyhedron`. 

  

OUTPUT: 

  

Boolean. Returns ``True`` if and only if ``self`` contains 

``y`` and ``self`` does not equal ``y``. 

  

Raises a ``ValueError`` if ``self`` and ``y`` are 

topology-incompatible or dimension-incompatible. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, C_Polyhedron, NNC_Polyhedron 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: p0 = C_Polyhedron( x>=0 ) 

sage: p1 = C_Polyhedron( x>=1 ) 

sage: p0.strictly_contains(p1) 

True 

sage: p1.strictly_contains(p0) 

False 

  

Errors are raised if the dimension or topology is not compatible:: 

  

sage: p0.strictly_contains(C_Polyhedron(y>=0)) 

Traceback (most recent call last): 

... 

ValueError: PPL::C_Polyhedron::contains(y): 

this->space_dimension() == 1, y.space_dimension() == 2. 

sage: p0.strictly_contains(NNC_Polyhedron(x>0)) 

Traceback (most recent call last): 

... 

ValueError: PPL::C_Polyhedron::contains(y): 

y is a NNC_Polyhedron. 

""" 

cdef bint result 

sig_on() 

try: 

result = self.thisptr.strictly_contains(y.thisptr[0]) 

finally: 

sig_off() 

return result 

  

  

def add_constraint(self, Constraint c): 

r""" 

Add a constraint to the polyhedron. 

  

Adds a copy of constraint ``c`` to the system of constraints 

of ``self``, without minimizing the result. 

  

See alse :meth:`add_constraints`. 

  

INPUT: 

  

- ``c`` -- the :class:`Constraint` that will be added to the 

system of constraints of ``self``. 

  

OUTPUT: 

  

This method modifies the polyhedron ``self`` and does not 

return anything. 

  

Raises a ``ValueError`` if ``self`` and the constraint ``c`` are 

topology-incompatible or dimension-incompatible. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, C_Polyhedron 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: p = C_Polyhedron( y>=0 ) 

sage: p.add_constraint( x>=0 ) 

  

We just added a 1-d constraint to a 2-d polyhedron, this is 

fine. The other way is not:: 

  

sage: p = C_Polyhedron( x>=0 ) 

sage: p.add_constraint( y>=0 ) 

Traceback (most recent call last): 

... 

ValueError: PPL::C_Polyhedron::add_constraint(c): 

this->space_dimension() == 1, c.space_dimension() == 2. 

  

The constraint must also be topology-compatible, that is, 

:class:`C_Polyhedron` only allows non-strict inequalities:: 

  

sage: p = C_Polyhedron( x>=0 ) 

sage: p.add_constraint( x< 1 ) 

Traceback (most recent call last): 

... 

ValueError: PPL::C_Polyhedron::add_constraint(c): 

c is a strict inequality. 

""" 

self.assert_mutable('The Polyhedron is not mutable!') 

sig_on() 

try: 

self.thisptr.add_constraint(c.thisptr[0]) 

finally: 

sig_off() 

  

  

def add_generator(self, Generator g): 

r""" 

Add a generator to the polyhedron. 

  

Adds a copy of constraint ``c`` to the system of generators 

of ``self``, without minimizing the result. 

  

INPUT: 

  

- ``g`` -- the :class:`Generator` that will be added to the 

system of Generators of ``self``. 

  

OUTPUT: 

  

This method modifies the polyhedron ``self`` and does not 

return anything. 

  

Raises a ``ValueError`` if ``self`` and the generator ``g`` 

are topology-incompatible or dimension-incompatible, or if 

``self`` is an empty polyhedron and ``g`` is not a point. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, C_Polyhedron, point, closure_point, ray 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: p = C_Polyhedron(1, 'empty') 

sage: p.add_generator( point(0*x) ) 

  

We just added a 1-d generator to a 2-d polyhedron, this is 

fine. The other way is not:: 

  

sage: p = C_Polyhedron(1, 'empty') 

sage: p.add_generator( point(0*y) ) 

Traceback (most recent call last): 

... 

ValueError: PPL::C_Polyhedron::add_generator(g): 

this->space_dimension() == 1, g.space_dimension() == 2. 

  

The constraint must also be topology-compatible, that is, 

:class:`C_Polyhedron` does not allow :func:`closure_point` 

generators:: 

  

sage: p = C_Polyhedron( point(0*x+0*y) ) 

sage: p.add_generator( closure_point(0*x) ) 

Traceback (most recent call last): 

... 

ValueError: PPL::C_Polyhedron::add_generator(g): 

g is a closure point. 

  

Finally, ever non-empty polyhedron must have at least one 

point generator:: 

  

sage: p = C_Polyhedron(3, 'empty') 

sage: p.add_generator( ray(x) ) 

Traceback (most recent call last): 

... 

ValueError: PPL::C_Polyhedron::add_generator(g): 

*this is an empty polyhedron and g is not a point. 

""" 

self.assert_mutable('The Polyhedron is not mutable!') 

sig_on() 

try: 

self.thisptr.add_generator(g.thisptr[0]) 

finally: 

sig_off() 

  

  

def add_constraints(self, Constraint_System cs): 

r""" 

Add constraints to the polyhedron. 

  

Adds a copy of constraints in ``cs`` to the system of constraints 

of ``self``, without minimizing the result. 

  

See alse :meth:`add_constraint`. 

  

INPUT: 

  

- ``cs`` -- the :class:`Constraint_System` that will be added 

to the system of constraints of ``self``. 

  

OUTPUT: 

  

This method modifies the polyhedron ``self`` and does not 

return anything. 

  

Raises a ``ValueError`` if ``self`` and the constraints in 

``cs`` are topology-incompatible or dimension-incompatible. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, C_Polyhedron, Constraint_System 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: cs = Constraint_System() 

sage: cs.insert(x>=0) 

sage: cs.insert(y>=0) 

sage: p = C_Polyhedron( y<=1 ) 

sage: p.add_constraints(cs) 

  

We just added a 1-d constraint to a 2-d polyhedron, this is 

fine. The other way is not:: 

  

sage: p = C_Polyhedron( x<=1 ) 

sage: p.add_constraints(cs) 

Traceback (most recent call last): 

... 

ValueError: PPL::C_Polyhedron::add_recycled_constraints(cs): 

this->space_dimension() == 1, cs.space_dimension() == 2. 

  

The constraints must also be topology-compatible, that is, 

:class:`C_Polyhedron` only allows non-strict inequalities:: 

  

sage: p = C_Polyhedron( x>=0 ) 

sage: p.add_constraints( Constraint_System(x<0) ) 

Traceback (most recent call last): 

... 

ValueError: PPL::C_Polyhedron::add_recycled_constraints(cs): 

cs contains strict inequalities. 

""" 

self.assert_mutable('The Polyhedron is not mutable!') 

sig_on() 

try: 

self.thisptr.add_constraints(cs.thisptr[0]) 

finally: 

sig_off() 

  

  

def add_generators(self, Generator_System gs): 

r""" 

Add generators to the polyhedron. 

  

Adds a copy of the generators in ``gs`` to the system of 

generators of ``self``, without minimizing the result. 

  

See alse :meth:`add_generator`. 

  

INPUT: 

  

- ``gs`` -- the :class:`Generator_System` that will be added 

to the system of constraints of ``self``. 

  

OUTPUT: 

  

This method modifies the polyhedron ``self`` and does not 

return anything. 

  

Raises a ``ValueError`` if ``self`` and one of the generators 

in ``gs`` are topology-incompatible or dimension-incompatible, 

or if ``self`` is an empty polyhedron and ``gs`` does not 

contain a point. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, C_Polyhedron, Generator_System, point, ray, closure_point 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: gs = Generator_System() 

sage: gs.insert(point(0*x+0*y)) 

sage: gs.insert(point(1*x+1*y)) 

sage: p = C_Polyhedron(2, 'empty') 

sage: p.add_generators(gs) 

  

We just added a 1-d constraint to a 2-d polyhedron, this is 

fine. The other way is not:: 

  

sage: p = C_Polyhedron(1, 'empty') 

sage: p.add_generators(gs) 

Traceback (most recent call last): 

... 

ValueError: PPL::C_Polyhedron::add_recycled_generators(gs): 

this->space_dimension() == 1, gs.space_dimension() == 2. 

  

The constraints must also be topology-compatible, that is, 

:class:`C_Polyhedron` does not allow :func:`closure_point` 

generators:: 

  

sage: p = C_Polyhedron( point(0*x+0*y) ) 

sage: p.add_generators( Generator_System(closure_point(x) )) 

Traceback (most recent call last): 

... 

ValueError: PPL::C_Polyhedron::add_recycled_generators(gs): 

gs contains closure points. 

""" 

self.assert_mutable('The Polyhedron is not mutable!') 

sig_on() 

try: 

self.thisptr.add_generators(gs.thisptr[0]) 

finally: 

sig_off() 

  

  

def unconstrain(self, Variable var): 

r""" 

Compute the cylindrification of ``self`` with respect to space 

dimension ``var``. 

  

INPUT: 

  

- ``var`` -- a :class:`Variable`. The space dimension that 

will be unconstrained. Exceptions: 

  

OUTPUT: 

  

This method assigns the cylindrification to ``self`` and does 

not return anything. 

  

Raises a ``ValueError`` if ``var`` is not a space dimension of 

``self``. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, C_Polyhedron, point 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: p = C_Polyhedron( point(x+y) ); p 

A 0-dimensional polyhedron in QQ^2 defined as the convex hull of 1 point 

sage: p.unconstrain(x); p 

A 1-dimensional polyhedron in QQ^2 defined as the convex hull of 1 point, 1 line 

sage: z = Variable(2) 

sage: p.unconstrain(z) 

Traceback (most recent call last): 

... 

ValueError: PPL::C_Polyhedron::unconstrain(var): 

this->space_dimension() == 2, required space dimension == 3. 

""" 

sig_on() 

try: 

self.thisptr.unconstrain(var.thisptr[0]) 

finally: 

sig_off() 

  

  

def intersection_assign(self, Polyhedron y): 

r""" 

Assign to ``self`` the intersection of ``self`` and ``y``. 

  

INPUT: 

  

- ``y`` -- a :class:`Polyhedron` 

  

OUTPUT: 

  

This method assigns the intersection to ``self`` and does not 

return anything. 

  

Raises a ``ValueError`` if ``self`` and ``y`` are 

topology-incompatible or dimension-incompatible. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, C_Polyhedron, NNC_Polyhedron 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: p = C_Polyhedron( 1*x+0*y >= 0 ) 

sage: p.intersection_assign( C_Polyhedron(y>=0) ) 

sage: p.constraints() 

Constraint_System {x0>=0, x1>=0} 

sage: z = Variable(2) 

sage: p.intersection_assign( C_Polyhedron(z>=0) ) 

Traceback (most recent call last): 

... 

ValueError: PPL::C_Polyhedron::intersection_assign(y): 

this->space_dimension() == 2, y.space_dimension() == 3. 

sage: p.intersection_assign( NNC_Polyhedron(x+y<1) ) 

Traceback (most recent call last): 

... 

ValueError: PPL::C_Polyhedron::intersection_assign(y): 

y is a NNC_Polyhedron. 

""" 

self.assert_mutable('The Polyhedron is not mutable!') 

sig_on() 

try: 

self.thisptr.intersection_assign(y.thisptr[0]) 

finally: 

sig_off() 

  

  

def poly_hull_assign(self, Polyhedron y): 

r""" 

Assign to ``self`` the poly-hull of ``self`` and ``y``. 

  

For any pair of NNC polyhedra `P_1` and `P_2`, the convex 

polyhedral hull (or poly-hull) of is the smallest NNC 

polyhedron that includes both `P_1` and `P_2`. The poly-hull 

of any pair of closed polyhedra in is also closed. 

  

INPUT: 

  

- ``y`` -- a :class:`Polyhedron` 

  

OUTPUT: 

  

This method assigns the poly-hull to ``self`` and does not 

return anything. 

  

Raises a ``ValueError`` if ``self`` and ``y`` are 

topology-incompatible or dimension-incompatible. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, C_Polyhedron, point, NNC_Polyhedron 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: p = C_Polyhedron( point(1*x+0*y) ) 

sage: p.poly_hull_assign(C_Polyhedron( point(0*x+1*y) )) 

sage: p.generators() 

Generator_System {point(0/1, 1/1), point(1/1, 0/1)} 

  

``self`` and ``y`` must be dimension- and topology-compatible, 

or an exception is raised:: 

  

sage: z = Variable(2) 

sage: p.poly_hull_assign( C_Polyhedron(z>=0) ) 

Traceback (most recent call last): 

... 

ValueError: PPL::C_Polyhedron::poly_hull_assign(y): 

this->space_dimension() == 2, y.space_dimension() == 3. 

sage: p.poly_hull_assign( NNC_Polyhedron(x+y<1) ) 

Traceback (most recent call last): 

... 

ValueError: PPL::C_Polyhedron::poly_hull_assign(y): 

y is a NNC_Polyhedron. 

""" 

self.assert_mutable('The Polyhedron is not mutable!') 

sig_on() 

try: 

self.thisptr.poly_hull_assign(y.thisptr[0]) 

finally: 

sig_off() 

  

  

upper_bound_assign = poly_hull_assign 

  

  

def poly_difference_assign(self, Polyhedron y): 

r""" 

Assign to ``self`` the poly-difference of ``self`` and ``y``. 

  

For any pair of NNC polyhedra `P_1` and `P_2` the convex 

polyhedral difference (or poly-difference) of `P_1` and `P_2` 

is defined as the smallest convex polyhedron containing the 

set-theoretic difference `P_1\setminus P_2` of `P_1` and 

`P_2`. 

  

In general, even if `P_1` and `P_2` are topologically closed 

polyhedra, their poly-difference may be a convex polyhedron 

that is not topologically closed. For this reason, when 

computing the poly-difference of two :class:`C_Polyhedron`, 

the library will enforce the topological closure of the 

result. 

  

INPUT: 

  

- ``y`` -- a :class:`Polyhedron` 

  

OUTPUT: 

  

This method assigns the poly-difference to ``self`` and does 

not return anything. 

  

Raises a ``ValueError`` if ``self`` and ``y`` are 

topology-incompatible or dimension-incompatible. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, C_Polyhedron, point, closure_point, NNC_Polyhedron 

sage: x = Variable(0) 

sage: p = NNC_Polyhedron( point(0*x) ) 

sage: p.add_generator( point(1*x) ) 

sage: p.poly_difference_assign(NNC_Polyhedron( point(0*x) )) 

sage: p.minimized_constraints() 

Constraint_System {-x0+1>=0, x0>0} 

  

The poly-difference of :class:`C_polyhedron` is really its closure:: 

  

sage: p = C_Polyhedron( point(0*x) ) 

sage: p.add_generator( point(1*x) ) 

sage: p.poly_difference_assign(C_Polyhedron( point(0*x) )) 

sage: p.minimized_constraints() 

Constraint_System {x0>=0, -x0+1>=0} 

  

``self`` and ``y`` must be dimension- and topology-compatible, 

or an exception is raised:: 

  

sage: y = Variable(1) 

sage: p.poly_difference_assign( C_Polyhedron(y>=0) ) 

Traceback (most recent call last): 

... 

ValueError: PPL::C_Polyhedron::poly_difference_assign(y): 

this->space_dimension() == 1, y.space_dimension() == 2. 

sage: p.poly_difference_assign( NNC_Polyhedron(x+y<1) ) 

Traceback (most recent call last): 

... 

ValueError: PPL::C_Polyhedron::poly_difference_assign(y): 

y is a NNC_Polyhedron. 

""" 

self.assert_mutable('The Polyhedron is not mutable!') 

sig_on() 

try: 

self.thisptr.poly_difference_assign(y.thisptr[0]) 

finally: 

sig_off() 

  

  

difference_assign = poly_difference_assign 

  

  

def drop_some_non_integer_points(self): 

r""" 

Possibly tighten ``self`` by dropping some points with 

non-integer coordinates. 

  

The modified polyhedron satisfies: 

  

* it is (not necessarily strictly) contained in the original 

polyhedron. 

  

* integral vertices (generating points with integer 

coordinates) of the original polyhedron are not removed. 

  

.. NOTE:: 

  

The modified polyhedron is not necessarily a lattice 

polyhedron; Some vertices will, in general, still be 

rational. Lattice points interior to the polyhedron may be 

lost in the process. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, NNC_Polyhedron, Constraint_System 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: cs = Constraint_System() 

sage: cs.insert( x>=0 ) 

sage: cs.insert( y>=0 ) 

sage: cs.insert( 3*x+2*y<5 ) 

sage: p = NNC_Polyhedron(cs) 

sage: p.minimized_generators() 

Generator_System {point(0/1, 0/1), closure_point(0/2, 5/2), closure_point(5/3, 0/3)} 

sage: p.drop_some_non_integer_points() 

sage: p.minimized_generators() 

Generator_System {point(0/1, 0/1), point(0/1, 2/1), point(4/3, 0/3)} 

""" 

self.assert_mutable('The Polyhedron is not mutable!') 

sig_on() 

self.thisptr.drop_some_non_integer_points() 

sig_off() 

  

  

def topological_closure_assign(self): 

r""" 

Assign to ``self`` its topological closure. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, NNC_Polyhedron 

sage: x = Variable(0) 

sage: p = NNC_Polyhedron(x>0) 

sage: p.is_topologically_closed() 

False 

sage: p.topological_closure_assign() 

sage: p.is_topologically_closed() 

True 

sage: p.minimized_constraints() 

Constraint_System {x0>=0} 

""" 

self.assert_mutable('The Polyhedron is not mutable!') 

sig_on() 

self.thisptr.topological_closure_assign() 

sig_off() 

  

  

def add_space_dimensions_and_embed(self, m): 

r""" 

Add ``m`` new space dimensions and embed ``self`` in the new 

vector space. 

  

The new space dimensions will be those having the highest 

indexes in the new polyhedron, which is characterized by a 

system of constraints in which the variables running through 

the new dimensions are not constrained. For instance, when 

starting from the polyhedron `P` and adding a third space 

dimension, the result will be the polyhedron 

  

.. MATH:: 

  

\Big\{ 

(x,y,z)^T \in \RR^3 

\Big| 

(x,y)^T \in P 

\Big\} 

  

INPUT: 

  

- ``m`` -- integer. 

  

OUTPUT: 

  

This method assigns the embedded polyhedron to ``self`` and 

does not return anything. 

  

Raises a ``ValueError`` if adding ``m`` new space dimensions 

would cause the vector space to exceed dimension 

``self.max_space_dimension()``. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, C_Polyhedron, point 

sage: x = Variable(0) 

sage: p = C_Polyhedron( point(3*x) ) 

sage: p.add_space_dimensions_and_embed(1) 

sage: p.minimized_generators() 

Generator_System {line(0, 1), point(3/1, 0/1)} 

sage: p.add_space_dimensions_and_embed( p.max_space_dimension() ) 

Traceback (most recent call last): 

... 

ValueError: PPL::C_Polyhedron::add_space_dimensions_and_embed(m): 

adding m new space dimensions exceeds the maximum allowed space dimension. 

""" 

self.assert_mutable('The Polyhedron is not mutable!') 

m = int(m) 

sig_on() 

try: 

self.thisptr.add_space_dimensions_and_embed(m) 

finally: 

sig_off() 

  

  

def add_space_dimensions_and_project(self, m): 

r""" 

Add ``m`` new space dimensions and embed ``self`` in the new 

vector space. 

  

The new space dimensions will be those having the highest 

indexes in the new polyhedron, which is characterized by a 

system of constraints in which the variables running through 

the new dimensions are all constrained to be equal to `0`. 

For instance, when starting from the polyhedron `P` and adding 

a third space dimension, the result will be the polyhedron 

  

.. MATH:: 

  

\Big\{ 

(x,y,0)^T \in \RR^3 

\Big| 

(x,y)^T \in P 

\Big\} 

  

INPUT: 

  

- ``m`` -- integer. 

  

OUTPUT: 

  

This method assigns the projected polyhedron to ``self`` and 

does not return anything. 

  

Raises a ``ValueError`` if adding ``m`` new space dimensions 

would cause the vector space to exceed dimension 

``self.max_space_dimension()``. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, C_Polyhedron, point 

sage: x = Variable(0) 

sage: p = C_Polyhedron( point(3*x) ) 

sage: p.add_space_dimensions_and_project(1) 

sage: p.minimized_generators() 

Generator_System {point(3/1, 0/1)} 

sage: p.add_space_dimensions_and_project( p.max_space_dimension() ) 

Traceback (most recent call last): 

... 

ValueError: PPL::C_Polyhedron::add_space_dimensions_and_project(m): 

adding m new space dimensions exceeds the maximum allowed space dimension. 

""" 

self.assert_mutable('The Polyhedron is not mutable!') 

m = int(m) 

sig_on() 

try: 

self.thisptr.add_space_dimensions_and_project(m) 

finally: 

sig_off() 

  

  

def concatenate_assign(self, Polyhedron y): 

r""" 

Assign to ``self`` the concatenation of ``self`` and ``y``. 

  

This function returns the Cartesian product of ``self`` and 

``y``. 

  

Viewing a polyhedron as a set of tuples (its points), it is 

sometimes useful to consider the set of tuples obtained by 

concatenating an ordered pair of polyhedra. Formally, the 

concatenation of the polyhedra `P` and `Q` (taken in this 

order) is the polyhedron such that 

  

.. MATH:: 

  

R = 

\Big\{ 

(x_0,\dots,x_{n-1},y_0,\dots,y_{m-1})^T \in \RR^{n+m} 

\Big| 

(x_0,\dots,x_{n-1})^T \in P 

,~ 

(y_0,\dots,y_{m-1})^T \in Q 

\Big\} 

  

Another way of seeing it is as follows: first embed polyhedron 

`P` into a vector space of dimension `n+m` and then add a 

suitably renamed-apart version of the constraints defining 

`Q`. 

  

INPUT: 

  

- ``m`` -- integer. 

  

OUTPUT: 

  

This method assigns the concatenated polyhedron to ``self`` and 

does not return anything. 

  

Raises a ``ValueError`` if ``self`` and ``y`` are 

topology-incompatible or if adding ``y.space_dimension()`` new 

space dimensions would cause the vector space to exceed 

dimension ``self.max_space_dimension()``. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, C_Polyhedron, NNC_Polyhedron, point 

sage: x = Variable(0) 

sage: p1 = C_Polyhedron( point(1*x) ) 

sage: p2 = C_Polyhedron( point(2*x) ) 

sage: p1.concatenate_assign(p2) 

sage: p1.minimized_generators() 

Generator_System {point(1/1, 2/1)} 

  

The polyhedra must be topology-compatible and not exceed the 

maximum space dimension:: 

  

sage: p1.concatenate_assign( NNC_Polyhedron(1, 'universe') ) 

Traceback (most recent call last): 

... 

ValueError: PPL::C_Polyhedron::concatenate_assign(y): 

y is a NNC_Polyhedron. 

sage: p1.concatenate_assign( C_Polyhedron(p1.max_space_dimension(), 'empty') ) 

Traceback (most recent call last): 

... 

ValueError: PPL::C_Polyhedron::concatenate_assign(y): 

concatenation exceeds the maximum allowed space dimension. 

""" 

self.assert_mutable('The Polyhedron is not mutable!') 

sig_on() 

try: 

self.thisptr.concatenate_assign(y.thisptr[0]) 

finally: 

sig_off() 

  

  

def remove_higher_space_dimensions(self, new_dimension): 

r""" 

Remove the higher dimensions of the vector space so that the 

resulting space will have dimension ``new_dimension``. 

  

OUTPUT: 

  

This method modifies ``self`` and does not return anything. 

  

Raises a ``ValueError`` if ``new_dimensions`` is greater than 

the space dimension of ``self``. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import C_Polyhedron, Variable 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: p = C_Polyhedron(3*x+0*y==2) 

sage: p.remove_higher_space_dimensions(1) 

sage: p.minimized_constraints() 

Constraint_System {3*x0-2==0} 

sage: p.remove_higher_space_dimensions(2) 

Traceback (most recent call last): 

... 

ValueError: PPL::C_Polyhedron::remove_higher_space_dimensions(nd): 

this->space_dimension() == 1, required space dimension == 2. 

""" 

self.assert_mutable('The Polyhedron is not mutable!') 

new_dimension = int(new_dimension) 

sig_on() 

try: 

self.thisptr.remove_higher_space_dimensions(new_dimension) 

finally: 

sig_off() 

  

  

def ascii_dump(self): 

r""" 

Write an ASCII dump to stderr. 

  

EXAMPLES:: 

  

sage: sage_cmd = 'from sage.libs.ppl import C_Polyhedron, Variable\n' 

sage: sage_cmd += 'x = Variable(0)\n' 

sage: sage_cmd += 'y = Variable(1)\n' 

sage: sage_cmd += 'p = C_Polyhedron(3*x+2*y==1)\n' 

sage: sage_cmd += 'p.minimized_generators()\n' 

sage: sage_cmd += 'p.ascii_dump()\n' 

sage: from sage.tests.cmdline import test_executable 

sage: (out, err, ret) = test_executable(['sage', '-c', sage_cmd], timeout=100) # long time, indirect doctest 

sage: print(err) # long time 

space_dim 2 

-ZE -EM +CM +GM +CS +GS -CP -GP -SC +SG 

con_sys (up-to-date) 

topology NECESSARILY_CLOSED 

2 x 2 SPARSE (sorted) 

index_first_pending 2 

size 3 -1 3 2 = (C) 

size 3 1 0 0 >= (C) 

<BLANKLINE> 

gen_sys (up-to-date) 

topology NECESSARILY_CLOSED 

2 x 2 DENSE (not_sorted) 

index_first_pending 2 

size 3 0 2 -3 L (C) 

size 3 2 0 1 P (C) 

<BLANKLINE> 

sat_c 

0 x 0 

<BLANKLINE> 

sat_g 

2 x 2 

0 0 

0 1 

""" 

sig_on() 

self.thisptr.ascii_dump() 

sig_off() 

  

  

def max_space_dimension(self): 

r""" 

Return the maximum space dimension all kinds of Polyhedron can handle. 

  

OUTPUT: 

  

Integer. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import C_Polyhedron 

sage: C_Polyhedron(1, 'empty').max_space_dimension() # random output 

1152921504606846974 

sage: C_Polyhedron(1, 'empty').max_space_dimension() 

357913940 # 32-bit 

1152921504606846974 # 64-bit 

""" 

return self.thisptr.max_space_dimension() 

  

  

def OK(self, check_non_empty=False): 

""" 

Check if all the invariants are satisfied. 

  

The check is performed so as to intrude as little as 

possible. If the library has been compiled with run-time 

assertions enabled, error messages are written on std::cerr in 

case invariants are violated. This is useful for the purpose 

of debugging the library. 

  

INPUT: 

  

- ``check_not_empty`` -- boolean. ``True`` if and only if, in 

addition to checking the invariants, ``self`` must be 

checked to be not empty. 

  

OUTPUT: 

  

``True`` if and only if ``self`` satisfies all the invariants 

and either ``check_not_empty`` is ``False`` or ``self`` is not 

empty. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Linear_Expression, Variable 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: e = 3*x+2*y+1 

sage: e.OK() 

True 

""" 

sig_on() 

cdef bint result = self.thisptr.OK() 

sig_off() 

return result 

  

  

def __hash__(self): 

r""" 

Hash value for polyhedra. 

  

TESTS:: 

  

sage: from sage.libs.ppl import Constraint_System, Variable, C_Polyhedron 

sage: x = Variable(0) 

sage: p = C_Polyhedron( 5*x >= 3 ) 

sage: p.set_immutable() 

sage: hash(p) 

1 

  

sage: y = Variable(1) 

sage: cs = Constraint_System() 

sage: cs.insert( x >= 0 ) 

sage: cs.insert( y >= 0 ) 

sage: p = C_Polyhedron(cs) 

sage: p.set_immutable() 

sage: hash(p) 

2 

  

sage: hash(C_Polyhedron(x >= 0)) 

Traceback (most recent call last): 

... 

TypeError: mutable polyhedra are unhashable 

""" 

if self.is_mutable(): 

raise TypeError("mutable polyhedra are unhashable") 

# TODO: the hash code from PPL looks like being the dimension! 

return self.thisptr[0].hash_code() 

  

def __richcmp__(Polyhedron lhs, Polyhedron rhs, op): 

r""" 

Comparison for polyhedra. 

  

INPUT: 

  

- ``lhs``, ``rhs`` -- :class:`Polyhedron`. 

  

- ``op`` -- integer. The comparison operation to be performed. 

  

OUTPUT: 

  

Boolean. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, C_Polyhedron 

sage: x = Variable(0) 

sage: C_Polyhedron(x>=0) > C_Polyhedron(x>=1) # indirect doctest 

True 

""" 

cdef result 

sig_on() 

if op == Py_LT: 

result = rhs.strictly_contains(lhs) 

elif op == Py_LE: 

result = rhs.contains(lhs) 

elif op == Py_EQ: 

result = (lhs.thisptr[0] == rhs.thisptr[0]) 

elif op == Py_GT: 

result = lhs.strictly_contains(rhs) 

elif op == Py_GE: 

result = lhs.contains(rhs) 

elif op == Py_NE: 

result = (lhs.thisptr[0] != rhs.thisptr[0]) 

else: 

assert False # unreachable 

sig_off() 

return result 

  

  

  

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

### C_Polyhedron ################################### 

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

cdef class C_Polyhedron(Polyhedron): 

r""" 

Wrapper for PPL's ``C_Polyhedron`` class. 

  

An object of the class :class:`C_Polyhedron` represents a 

topologically closed convex polyhedron in the vector space. See 

:class:`NNC_Polyhedron` for more general (not necessarily closed) 

polyhedra. 

  

When building a closed polyhedron starting from a system of 

constraints, an exception is thrown if the system contains a 

strict inequality constraint. Similarly, an exception is thrown 

when building a closed polyhedron starting from a system of 

generators containing a closure point. 

  

INPUT: 

  

- ``arg`` -- the defining data of the polyhedron. Any one of the 

following is accepted: 

  

* A non-negative integer. Depending on ``degenerate_element``, 

either the space-filling or the empty polytope in the given 

dimension ``arg`` is constructed. 

  

* A :class:`Constraint_System`. 

  

* A :class:`Generator_System`. 

  

* A single :class:`Constraint`. 

  

* A single :class:`Generator`. 

  

* A :class:`C_Polyhedron`. 

  

- ``degenerate_element`` -- string, either ``'universe'`` or 

``'empty'``. Only used if ``arg`` is an integer. 

  

OUTPUT: 

  

A :class:`C_Polyhedron`. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Constraint, Constraint_System, Generator, Generator_System, Variable, C_Polyhedron, point, ray 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: C_Polyhedron( 5*x-2*y >= x+y-1 ) 

A 2-dimensional polyhedron in QQ^2 defined as the convex hull of 1 point, 1 ray, 1 line 

sage: cs = Constraint_System() 

sage: cs.insert( x >= 0 ) 

sage: cs.insert( y >= 0 ) 

sage: C_Polyhedron(cs) 

A 2-dimensional polyhedron in QQ^2 defined as the convex hull of 1 point, 2 rays 

sage: C_Polyhedron( point(x+y) ) 

A 0-dimensional polyhedron in QQ^2 defined as the convex hull of 1 point 

sage: gs = Generator_System() 

sage: gs.insert( point(-x-y) ) 

sage: gs.insert( ray(x) ) 

sage: C_Polyhedron(gs) 

A 1-dimensional polyhedron in QQ^2 defined as the convex hull of 1 point, 1 ray 

  

The empty and universe polyhedra are constructed like this:: 

  

sage: C_Polyhedron(3, 'empty') 

The empty polyhedron in QQ^3 

sage: C_Polyhedron(3, 'empty').constraints() 

Constraint_System {-1==0} 

sage: C_Polyhedron(3, 'universe') 

The space-filling polyhedron in QQ^3 

sage: C_Polyhedron(3, 'universe').constraints() 

Constraint_System {} 

  

Note that, by convention, the generator system of a polyhedron is 

either empty or contains at least one point. In particular, if you 

define a polyhedron via a non-empty :class:`Generator_System` it 

must contain a point (at any position). If you start with a single 

generator, this generator must be a point:: 

  

sage: C_Polyhedron( ray(x) ) 

Traceback (most recent call last): 

... 

ValueError: PPL::C_Polyhedron::C_Polyhedron(gs): 

*this is an empty polyhedron and 

the non-empty generator system gs contains no points. 

""" 

  

  

def __cinit__(self, arg, degenerate_element='universe'): 

""" 

The Cython constructor. 

  

See :class:`C_Polyhedron` for documentation. 

  

TESTS:: 

  

sage: from sage.libs.ppl import C_Polyhedron 

sage: C_Polyhedron(3, 'empty') # indirect doctest 

The empty polyhedron in QQ^3 

""" 

if isinstance(arg, C_Polyhedron): 

ph = <C_Polyhedron>arg 

self.thisptr = new PPL_C_Polyhedron(<PPL_C_Polyhedron&>ph.thisptr[0]) 

return 

if isinstance(arg, Generator): 

arg = Generator_System(arg) 

if isinstance(arg, Constraint): 

arg = Constraint_System(arg) 

if isinstance(arg, Generator_System): 

gs = <Generator_System>arg 

self.thisptr = new PPL_C_Polyhedron(gs.thisptr[0]) 

return 

if isinstance(arg, Constraint_System): 

cs = <Constraint_System>arg 

self.thisptr = new PPL_C_Polyhedron(cs.thisptr[0]) 

return 

try: 

dim = int(arg) 

assert dim>=0 

except ValueError: 

raise ValueError('Cannot initialize C_Polyhedron with '+str(arg)+'.') 

degenerate_element = degenerate_element.lower() 

if degenerate_element=='universe': 

self.thisptr = new PPL_C_Polyhedron(<PPL_dimension_type>dim, UNIVERSE) 

return 

elif degenerate_element=='empty': 

self.thisptr = new PPL_C_Polyhedron(<PPL_dimension_type>dim, EMPTY) 

return 

else: 

raise ValueError('Unknown value: degenerate_element='+str(degenerate_element)+'.') 

  

  

def __init__(self, *args): 

""" 

The Python destructor. 

  

See :class:`C_Polyhedron` for documentation. 

  

TESTS:: 

  

sage: from sage.libs.ppl import C_Polyhedron 

sage: C_Polyhedron(3, 'empty') # indirect doctest 

The empty polyhedron in QQ^3 

""" 

# override Polyhedron.__init__ 

pass 

  

  

def __dealloc__(self): 

""" 

The Cython destructor. 

""" 

del self.thisptr 

  

  

def __reduce__(self): 

""" 

Pickle object 

  

TESTS:: 

  

sage: from sage.libs.ppl import C_Polyhedron, Variable 

sage: P = C_Polyhedron(3, 'empty') 

sage: loads(dumps(P)) 

The empty polyhedron in QQ^3 

  

sage: Q = C_Polyhedron(5, 'universe') 

sage: loads(dumps(Q)) 

The space-filling polyhedron in QQ^5 

  

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: H = C_Polyhedron( 5*x-2*y >= x+y-1 ) 

sage: loads(dumps(H)) 

A 2-dimensional polyhedron in QQ^2 defined as the convex hull of 1 point, 1 ray, 1 line 

""" 

if self.is_empty(): 

return (C_Polyhedron, (self.space_dimension(), 'empty')) 

elif self.is_universe(): 

return (C_Polyhedron, (self.space_dimension(), 'universe')) 

else: 

return (C_Polyhedron, (self.generators(),)) 

  

  

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

### NNC_Polyhedron ################################# 

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

cdef class NNC_Polyhedron(Polyhedron): 

r""" 

Wrapper for PPL's ``NNC_Polyhedron`` class. 

  

An object of the class ``NNC_Polyhedron`` represents a not 

necessarily closed (NNC) convex polyhedron in the vector space. 

  

Note: Since NNC polyhedra are a generalization of closed 

polyhedra, any object of the class :class:`C_Polyhedron` can be 

(explicitly) converted into an object of the class 

:class:`NNC_Polyhedron`. The reason for defining two different 

classes is that objects of the class :class:`C_Polyhedron` are 

characterized by a more efficient implementation, requiring less 

time and memory resources. 

  

INPUT: 

  

- ``arg`` -- the defining data of the polyhedron. Any one of the 

following is accepted: 

  

* An non-negative integer. Depending on ``degenerate_element``, 

either the space-filling or the empty polytope in the given 

dimension ``arg`` is constructed. 

  

* A :class:`Constraint_System`. 

  

* A :class:`Generator_System`. 

  

* A single :class:`Constraint`. 

  

* A single :class:`Generator`. 

  

* A :class:`NNC_Polyhedron`. 

  

* A :class:`C_Polyhedron`. 

  

- ``degenerate_element`` -- string, either ``'universe'`` or 

``'empty'``. Only used if ``arg`` is an integer. 

  

OUTPUT: 

  

A :class:`C_Polyhedron`. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Constraint, Constraint_System, Generator, Generator_System, Variable, NNC_Polyhedron, point, ray, closure_point 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: NNC_Polyhedron( 5*x-2*y > x+y-1 ) 

A 2-dimensional polyhedron in QQ^2 defined as the convex hull of 1 point, 1 closure_point, 1 ray, 1 line 

sage: cs = Constraint_System() 

sage: cs.insert( x > 0 ) 

sage: cs.insert( y > 0 ) 

sage: NNC_Polyhedron(cs) 

A 2-dimensional polyhedron in QQ^2 defined as the convex hull of 1 point, 1 closure_point, 2 rays 

sage: NNC_Polyhedron( point(x+y) ) 

A 0-dimensional polyhedron in QQ^2 defined as the convex hull of 1 point 

sage: gs = Generator_System() 

sage: gs.insert( point(-y) ) 

sage: gs.insert( closure_point(-x-y) ) 

sage: gs.insert( ray(x) ) 

sage: p = NNC_Polyhedron(gs); p 

A 1-dimensional polyhedron in QQ^2 defined as the convex hull of 1 point, 1 closure_point, 1 ray 

sage: p.minimized_constraints() 

Constraint_System {x1+1==0, x0+1>0} 

  

Note that, by convention, every polyhedron must contain a point:: 

  

sage: NNC_Polyhedron( closure_point(x+y) ) 

Traceback (most recent call last): 

... 

ValueError: PPL::NNC_Polyhedron::NNC_Polyhedron(gs): 

*this is an empty polyhedron and 

the non-empty generator system gs contains no points. 

""" 

  

  

def __cinit__(self, arg, degenerate_element='universe'): 

""" 

The Cython constructor. 

  

See :class:`NNC_Polyhedron` for documentation. 

  

TESTS:: 

  

sage: from sage.libs.ppl import NNC_Polyhedron 

sage: NNC_Polyhedron(3, 'empty') # indirect doctest 

The empty polyhedron in QQ^3 

""" 

if isinstance(arg, NNC_Polyhedron): 

p_nnc = <NNC_Polyhedron>arg 

self.thisptr = new PPL_NNC_Polyhedron(<PPL_NNC_Polyhedron&>p_nnc.thisptr[0]) 

return 

if isinstance(arg, C_Polyhedron): 

p_c = <C_Polyhedron>arg 

self.thisptr = new PPL_NNC_Polyhedron(<PPL_C_Polyhedron&>p_c.thisptr[0]) 

return 

if isinstance(arg, Generator): 

arg = Generator_System(arg) 

if isinstance(arg, Constraint): 

arg = Constraint_System(arg) 

if isinstance(arg, Generator_System): 

gs = <Generator_System>arg 

self.thisptr = new PPL_NNC_Polyhedron(gs.thisptr[0]) 

return 

if isinstance(arg, Constraint_System): 

cs = <Constraint_System>arg 

self.thisptr = new PPL_NNC_Polyhedron(cs.thisptr[0]) 

return 

try: 

dim = int(arg) 

assert dim>=0 

except ValueError: 

raise ValueError('Cannot initialize NNC_Polyhedron with '+str(arg)+'.') 

degenerate_element = degenerate_element.lower() 

if degenerate_element=='universe': 

self.thisptr = new PPL_NNC_Polyhedron(<PPL_dimension_type>dim, UNIVERSE) 

return 

elif degenerate_element=='empty': 

self.thisptr = new PPL_NNC_Polyhedron(<PPL_dimension_type>dim, EMPTY) 

return 

else: 

raise ValueError('Unknown value: degenerate_element='+str(degenerate_element)+'.') 

  

  

def __init__(self, *args): 

""" 

The Python destructor. 

  

See :class:`NNC_Polyhedron` for documentation. 

  

TESTS:: 

  

sage: from sage.libs.ppl import NNC_Polyhedron 

sage: NNC_Polyhedron(3, 'empty') # indirect doctest 

The empty polyhedron in QQ^3 

""" 

# override Polyhedron.__init__ 

pass 

  

  

def __dealloc__(self): 

""" 

The Cython destructor. 

""" 

del self.thisptr 

  

  

def __reduce__(self): 

""" 

Pickle object 

  

TESTS:: 

  

sage: from sage.libs.ppl import NNC_Polyhedron, Variable 

sage: P = NNC_Polyhedron(3, 'empty') 

sage: loads(dumps(P)) 

The empty polyhedron in QQ^3 

  

sage: Q = NNC_Polyhedron(5, 'universe') 

sage: loads(dumps(Q)) 

The space-filling polyhedron in QQ^5 

  

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: H = NNC_Polyhedron( 5*x-2*y > x+y-1 ) 

sage: loads(dumps(H)) 

A 2-dimensional polyhedron in QQ^2 defined as the convex hull of 1 point, 

1 closure_point, 1 ray, 1 line 

""" 

if self.is_empty(): 

return (NNC_Polyhedron, (self.space_dimension(), 'empty')) 

elif self.is_universe(): 

return (NNC_Polyhedron, (self.space_dimension(), 'universe')) 

else: 

return (NNC_Polyhedron, (self.generators(),)) 

  

  

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

### Variable ####################################### 

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

cdef class Variable(object): 

r""" 

Wrapper for PPL's ``Variable`` class. 

  

A dimension of the vector space. 

  

An object of the class Variable represents a dimension of the 

space, that is one of the Cartesian axes. Variables are used as 

basic blocks in order to build more complex linear 

expressions. Each variable is identified by a non-negative 

integer, representing the index of the corresponding Cartesian 

axis (the first axis has index 0). The space dimension of a 

variable is the dimension of the vector space made by all the 

Cartesian axes having an index less than or equal to that of the 

considered variable; thus, if a variable has index `i`, its space 

dimension is `i+1`. 

  

INPUT: 

  

- ``i`` -- integer. The index of the axis. 

  

OUTPUT: 

  

A :class:`Variable` 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable 

sage: x = Variable(123) 

sage: x.id() 

123 

sage: x 

x123 

  

Note that the "meaning" of an object of the class Variable is 

completely specified by the integer index provided to its 

constructor: be careful not to be mislead by C++ language variable 

names. For instance, in the following example the linear 

expressions ``e1`` and ``e2`` are equivalent, since the two 

variables ``x`` and ``z`` denote the same Cartesian axis:: 

  

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: z = Variable(0) 

sage: e1 = x + y; e1 

x0+x1 

sage: e2 = y + z; e2 

x0+x1 

sage: e1 - e2 

0 

""" 

  

cdef PPL_Variable *thisptr 

  

  

def __cinit__(self, PPL_dimension_type i): 

""" 

The Cython constructor. 

  

See :class:`Variable` for documentation. 

  

TESTS:: 

  

sage: from sage.libs.ppl import Variable 

sage: Variable(123) # indirect doctest 

x123 

""" 

self.thisptr = new PPL_Variable(i) 

  

  

def __dealloc__(self): 

""" 

The Cython destructor. 

""" 

del self.thisptr 

  

  

def id(self): 

""" 

Return the index of the Cartesian axis associated to the variable. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable 

sage: x = Variable(123) 

sage: x.id() 

123 

""" 

return self.thisptr.id() 

  

  

def OK(self): 

""" 

Checks if all the invariants are satisfied. 

  

OUTPUT: 

  

Boolean. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable 

sage: x = Variable(0) 

sage: x.OK() 

True 

""" 

return self.thisptr.OK() 

  

  

def space_dimension(self): 

r""" 

Return the dimension of the vector space enclosing ``self``. 

  

OUTPUT: 

  

Integer. The returned value is ``self.id()+1``. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable 

sage: x = Variable(0) 

sage: x.space_dimension() 

1 

""" 

return self.thisptr.space_dimension() 

  

  

def __repr__(self): 

""" 

Return a string representation. 

  

OUTPUT: 

  

String. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable 

sage: x = Variable(0) 

sage: x.__repr__() 

'x0' 

""" 

return 'x{0}'.format(self.id()) 

  

  

def __add__(self, other): 

r""" 

Return the sum ``self`` + ``other``. 

  

INPUT: 

  

- ``self``, ``other`` -- anything convertible to 

``Linear_Expression``: An integer, a :class:`Variable`, or a 

:class:`Linear_Expression`. 

  

OUTPUT: 

  

A :class:`Linear_Expression` representing ``self`` + ``other``. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable 

sage: x = Variable(0); y = Variable(1) 

sage: x + 15 

x0+15 

sage: 15 + y 

x1+15 

""" 

return Linear_Expression(self)+Linear_Expression(other) 

  

  

def __sub__(self, other): 

r""" 

Return the difference ``self`` - ``other``. 

  

INPUT: 

  

- ``self``, ``other`` -- anything convertible to 

``Linear_Expression``: An integer, a :class:`Variable`, or a 

:class:`Linear_Expression`. 

  

OUTPUT: 

  

A :class:`Linear_Expression` representing ``self`` - ``other``. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable 

sage: x = Variable(0); y = Variable(1) 

sage: x - 15 

x0-15 

sage: 15 - y 

-x1+15 

""" 

return Linear_Expression(self)-Linear_Expression(other) 

  

  

def __mul__(self, other): 

r""" 

Return the product ``self`` * ``other``. 

  

INPUT: 

  

- ``self``, ``other`` -- One must be an integer, the other a 

:class:`Variable`. 

  

OUTPUT: 

  

A :class:`Linear_Expression` representing ``self`` * ``other``. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable 

sage: x = Variable(0); y = Variable(1) 

sage: x * 15 

15*x0 

sage: 15 * y 

15*x1 

""" 

if isinstance(self, Variable): 

return Linear_Expression(self) * other 

else: 

return Linear_Expression(other) * self 

  

  

def __pos__(self): 

r""" 

Return ``self`` as :class:`Linear_Expression` 

  

OUTPUT: 

  

The :class:`Linear_Expression` ``+self`` 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable 

sage: x = Variable(0); x 

x0 

sage: +x 

x0 

""" 

return Linear_Expression(self) 

  

  

def __neg__(self): 

r""" 

Return -``self`` as :class:`Linear_Expression` 

  

OUTPUT: 

  

The :class:`Linear_Expression` ``-self`` 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable 

sage: x = Variable(0); x 

x0 

sage: -x 

-x0 

""" 

return Linear_Expression(self)*(-1) 

  

  

def __richcmp__(self, other, op): 

""" 

Construct :class:`Constraint` from equalities or inequalities. 

  

INPUT: 

  

- ``self``, ``other`` -- anything convertible to a 

:class:`Linear_Expression` 

  

- ``op`` -- the operation. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: x < y 

-x0+x1>0 

sage: x <= 0 

-x0>=0 

sage: x == y-y 

x0==0 

sage: x >= -2 

x0+2>=0 

sage: x > 0 

x0>0 

sage: 0 == 1 # watch out! 

False 

sage: 0*x == 1 

-1==0 

""" 

return _make_Constraint_from_richcmp(self, other, op) 

  

  

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

### Variables_Set ################################## 

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

  

cdef class Variables_Set(object): 

r""" 

Wrapper for PPL's ``Variables_Set`` class. 

  

A set of variables' indexes. 

  

EXAMPLES: 

  

Build the empty set of variable indexes:: 

  

sage: from sage.libs.ppl import Variable, Variables_Set 

sage: Variables_Set() 

Variables_Set of cardinality 0 

  

Build the singleton set of indexes containing the index of the variable:: 

  

sage: v123 = Variable(123) 

sage: Variables_Set(v123) 

Variables_Set of cardinality 1 

  

Build the set of variables' indexes in the range from one variable to 

another variable:: 

  

sage: v127 = Variable(127) 

sage: Variables_Set(v123,v127) 

Variables_Set of cardinality 5 

""" 

  

cdef PPL_Variables_Set *thisptr 

  

def __cinit__(self, *args): 

""" 

The Cython constructor. 

  

See :class:`Variables_Set` for documentation. 

  

TESTS:: 

  

sage: from sage.libs.ppl import Variable, Variables_Set 

sage: Variables_Set() 

Variables_Set of cardinality 0 

""" 

if len(args)==0: 

self.thisptr = new PPL_Variables_Set() 

elif len(args)==1: 

v = <Variable?>args[0] 

self.thisptr = new PPL_Variables_Set(v.thisptr[0]) 

elif len(args)==2: 

v = <Variable?>args[0] 

w = <Variable?>args[1] 

self.thisptr = new PPL_Variables_Set(v.thisptr[0], w.thisptr[0]) 

  

def __dealloc__(self): 

""" 

The Cython destructor 

""" 

del self.thisptr 

  

def OK(self): 

""" 

Checks if all the invariants are satisfied. 

  

OUTPUT: 

  

Boolean. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, Variables_Set 

sage: v123 = Variable(123) 

sage: S = Variables_Set(v123) 

sage: S.OK() 

True 

""" 

return self.thisptr.OK() 

  

def space_dimension(self): 

r""" 

Returns the dimension of the smallest vector space enclosing all the variables whose indexes are in the set. 

  

OUTPUT: 

  

Integer. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, Variables_Set 

sage: v123 = Variable(123) 

sage: S = Variables_Set(v123) 

sage: S.space_dimension() 

124 

""" 

return self.thisptr.space_dimension() 

  

def insert(self, Variable v): 

r""" 

Inserts the index of variable `v` into the set. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, Variables_Set 

sage: S = Variables_Set() 

sage: v123 = Variable(123) 

sage: S.insert(v123) 

sage: S.space_dimension() 

124 

""" 

self.thisptr.insert(v.thisptr[0]) 

  

def ascii_dump(self): 

r""" 

Write an ASCII dump to stderr. 

  

EXAMPLES:: 

  

sage: sage_cmd = 'from sage.libs.ppl import Variable, Variables_Set\n' 

sage: sage_cmd += 'v123 = Variable(123)\n' 

sage: sage_cmd += 'S = Variables_Set(v123)\n' 

sage: sage_cmd += 'S.ascii_dump()\n' 

sage: from sage.tests.cmdline import test_executable 

sage: (out, err, ret) = test_executable(['sage', '-c', sage_cmd], timeout=100) # long time, indirect doctest 

sage: print(err) # long time 

<BLANKLINE> 

variables( 1 ) 

123 

""" 

self.thisptr.ascii_dump() 

  

def __repr__(self): 

""" 

Return a string representation. 

  

OUTPUT: 

  

String. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, Variables_Set 

sage: S = Variables_Set() 

sage: S.__repr__() 

'Variables_Set of cardinality 0' 

""" 

return 'Variables_Set of cardinality {}'.format(self.thisptr.size()) 

  

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

### Linear_Expression ############################## 

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

cdef class Linear_Expression(object): 

r""" 

Wrapper for PPL's ``PPL_Linear_Expression`` class. 

  

INPUT: 

  

The constructor accepts zero, one, or two arguments. 

  

If there are two arguments ``Linear_Expression(a,b)``, they are 

interpreted as 

  

- ``a`` -- an iterable of integer coefficients, for example a 

list. 

  

- ``b`` -- an integer. The inhomogeneous term. 

  

A single argument ``Linear_Expression(arg)`` is interpreted as 

  

- ``arg`` -- something that determines a linear 

expression. Possibilities are: 

  

* a :class:`Variable`: The linear expression given by that 

variable. 

  

* a :class:`Linear_Expression`: The copy constructor. 

  

* an integer: Constructs the constant linear expression. 

  

No argument is the default constructor and returns the zero linear 

expression. 

  

OUTPUT: 

  

A :class:`Linear_Expression` 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, Linear_Expression 

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

x0+2*x1+3*x2+4*x3+5 

sage: Linear_Expression(10) 

10 

sage: Linear_Expression() 

0 

sage: Linear_Expression(10).inhomogeneous_term() 

10 

sage: x = Variable(123) 

sage: expr = x+1; expr 

x123+1 

sage: expr.OK() 

True 

sage: expr.coefficient(x) 

1 

sage: expr.coefficient( Variable(124) ) 

0 

""" 

  

cdef PPL_Linear_Expression *thisptr 

  

  

def __cinit__(self, *args): 

""" 

The Cython constructor. 

  

See :class:`Linear_Expression` for documentation. 

  

TESTS:: 

  

sage: from sage.libs.ppl import Linear_Expression 

sage: Linear_Expression(10) # indirect doctest 

10 

""" 

if len(args)==2: 

a = args[0] 

b = args[1] 

ex = Linear_Expression(0) 

for i in range(0,len(a)): 

ex += Variable(i) * Integer(a[i]) 

arg = ex + b 

elif len(args)==1: 

arg = args[0] 

elif len(args)==0: 

self.thisptr = new PPL_Linear_Expression() 

return 

else: 

assert False, 'Cannot initialize with more than 2 arguments.' 

  

if isinstance(arg, Variable): 

v = <Variable>arg 

self.thisptr = new PPL_Linear_Expression(v.thisptr[0]) 

return 

if isinstance(arg, Linear_Expression): 

e = <Linear_Expression>arg 

self.thisptr = new PPL_Linear_Expression(e.thisptr[0]) 

return 

try: 

c = Integer(arg) 

self.thisptr = new PPL_Linear_Expression(PPL_Coefficient(c.value)) 

return 

except ValueError: 

raise ValueError('Cannot initialize with {}.'.format(args)) 

  

  

def __dealloc__(self): 

""" 

The Cython destructor. 

""" 

del self.thisptr 

  

  

def space_dimension(self): 

""" 

Return the dimension of the vector space necessary for the 

linear expression. 

  

OUTPUT: 

  

Integer. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: ( x+y+1 ).space_dimension() 

2 

sage: ( x+y ).space_dimension() 

2 

sage: ( y+1 ).space_dimension() 

2 

sage: ( x +1 ).space_dimension() 

1 

sage: ( y+1-y ).space_dimension() 

2 

""" 

return self.thisptr.space_dimension() 

  

  

def coefficient(self, Variable v): 

""" 

Return the coefficient of the variable ``v``. 

  

INPUT: 

  

- ``v`` -- a :class:`Variable`. 

  

OUTPUT: 

  

An integer. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable 

sage: x = Variable(0) 

sage: e = 3*x+1 

sage: e.coefficient(x) 

3 

""" 

cdef Integer c = Integer(0) 

mpz_set(c.value, self.thisptr.coefficient(v.thisptr[0]).get_mpz_t()) 

return c 

  

  

def coefficients(self): 

""" 

Return the coefficients of the linear expression. 

  

OUTPUT: 

  

A tuple of integers of length :meth:`space_dimension`. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable 

sage: x = Variable(0); y = Variable(1) 

sage: e = 3*x+5*y+1 

sage: e.coefficients() 

(3, 5) 

""" 

cdef int d = self.space_dimension() 

cdef int i 

cdef Integer c = Integer(0) 

coeffs = [] 

for i in range(0,d): 

mpz_set(c.value, self.thisptr.coefficient(PPL_Variable(i)).get_mpz_t()) 

coeffs.append(Integer(c)) 

return tuple(coeffs) 

  

  

def inhomogeneous_term(self): 

""" 

Return the inhomogeneous term of the linear expression. 

  

OUTPUT: 

  

Integer. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, Linear_Expression 

sage: Linear_Expression(10).inhomogeneous_term() 

10 

""" 

cdef Integer c = Integer(0) 

mpz_set(c.value, self.thisptr.inhomogeneous_term().get_mpz_t()) 

return c 

  

  

def is_zero(self): 

""" 

Test if ``self`` is the zero linear expression. 

  

OUTPUT: 

  

Boolean. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, Linear_Expression 

sage: Linear_Expression(0).is_zero() 

True 

sage: Linear_Expression(10).is_zero() 

False 

""" 

return self.thisptr.is_zero() 

  

  

def all_homogeneous_terms_are_zero(self): 

""" 

Test if ``self`` is a constant linear expression. 

  

OUTPUT: 

  

Boolean. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, Linear_Expression 

sage: Linear_Expression(10).all_homogeneous_terms_are_zero() 

True 

""" 

return self.thisptr.all_homogeneous_terms_are_zero() 

  

  

def ascii_dump(self): 

r""" 

Write an ASCII dump to stderr. 

  

EXAMPLES:: 

  

sage: sage_cmd = 'from sage.libs.ppl import Linear_Expression, Variable\n' 

sage: sage_cmd += 'x = Variable(0)\n' 

sage: sage_cmd += 'y = Variable(1)\n' 

sage: sage_cmd += 'e = 3*x+2*y+1\n' 

sage: sage_cmd += 'e.ascii_dump()\n' 

sage: from sage.tests.cmdline import test_executable 

sage: (out, err, ret) = test_executable(['sage', '-c', sage_cmd], timeout=100) # long time, indirect doctest 

sage: print(err) # long time 

size 3 1 3 2 

""" 

self.thisptr.ascii_dump() 

  

  

def OK(self): 

""" 

Check if all the invariants are satisfied. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Linear_Expression, Variable 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: e = 3*x+2*y+1 

sage: e.OK() 

True 

""" 

return self.thisptr.OK() 

  

  

def __repr__(self): 

r""" 

Return a string representation of the linear expression. 

  

OUTPUT: 

  

A string. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Linear_Expression, Variable 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: x+1 

x0+1 

sage: x+1-x 

1 

sage: 2*x 

2*x0 

sage: x-x-1 

-1 

sage: x-x 

0 

""" 

s = '' 

first = True 

for i in range(0,self.space_dimension()): 

x = Variable(i) 

coeff = self.coefficient(x) 

if coeff==0: continue 

if first and coeff==1: 

s += '%r' % x 

first = False 

elif first and coeff==-1: 

s += '-%r' % x 

first = False 

elif first and coeff!=1: 

s += '%d*%r' % (coeff, x) 

first = False 

elif coeff==1: 

s += '+%r' % x 

elif coeff==-1: 

s += '-%r' % x 

else: 

s += '%+d*%r' % (coeff, x) 

inhomog = self.inhomogeneous_term() 

if inhomog!=0: 

if first: 

s += '%d' % inhomog 

first = False 

else: 

s += '%+d' % inhomog 

if first: 

s = '0' 

return s 

  

  

def __add__(self, other): 

r""" 

Add ``self`` and ``other``. 

  

INPUT: 

  

- ``self``, ``other`` -- anything that can be used to 

construct a :class:`Linear_Expression`. One of them, not 

necessarily ``self``, is guaranteed to be a 

:class:`Linear_Expression`, otherwise Python would not 

have called this method. 

  

OUTPUT: 

  

The sum as a :class:`Linear_Expression` 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Linear_Expression, Variable 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: 9+x+y+(1+x)+y+y 

2*x0+3*x1+10 

""" 

cdef Linear_Expression lhs = Linear_Expression(self) 

cdef Linear_Expression rhs = Linear_Expression(other) 

cdef Linear_Expression result = Linear_Expression() 

result.thisptr[0] = lhs.thisptr[0] + rhs.thisptr[0] 

return result 

  

  

def __sub__(self, other): 

r""" 

Subtract ``other`` from ``self``. 

  

INPUT: 

  

- ``self``, ``other`` -- anything that can be used to 

construct a :class:`Linear_Expression`. One of them, not 

necessarily ``self``, is guaranteed to be a 

:class:`Linear_Expression`, otherwise Python would not 

have called this method. 

  

OUTPUT: 

  

The difference as a :class:`Linear_Expression` 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Linear_Expression, Variable 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: 9-x-y-(1-x)-y-y 

-3*x1+8 

""" 

cdef Linear_Expression lhs = Linear_Expression(self) 

cdef Linear_Expression rhs = Linear_Expression(other) 

cdef Linear_Expression result = Linear_Expression() 

result.thisptr[0] = lhs.thisptr[0] - rhs.thisptr[0] 

return result 

  

  

def __mul__(self, other): 

r""" 

Multiply ``self`` with ``other``. 

  

INPUT: 

  

- ``self``, ``other`` -- anything that can be used to 

construct a :class:`Linear_Expression`. One of them, not 

necessarily ``self``, is guaranteed to be a 

:class:`Linear_Expression`, otherwise Python would not 

have called this method. 

  

OUTPUT: 

  

The product as a :class:`Linear_Expression` 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Linear_Expression, Variable 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: 8*(x+1) 

8*x0+8 

sage: y*8 

8*x1 

""" 

cdef Linear_Expression e 

cdef Integer c 

if isinstance(self, Linear_Expression): 

e = <Linear_Expression>self 

c = Integer(other) 

else: 

e = <Linear_Expression>other 

c = Integer(self) 

  

cdef Linear_Expression result = Linear_Expression() 

result.thisptr[0] = e.thisptr[0] * PPL_Coefficient(c.value) 

return result 

  

  

def __pos__(self): 

""" 

Return ``self``. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, Linear_Expression 

sage: +Linear_Expression(1) 

1 

sage: x = Variable(0) 

sage: +(x+1) 

x0+1 

""" 

return self 

  

  

def __neg__(self): 

""" 

Return the negative of ``self``. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, Linear_Expression 

sage: -Linear_Expression(1) 

-1 

sage: x = Variable(0) 

sage: -(x+1) 

-x0-1 

""" 

return self*(-1) 

  

  

def __richcmp__(self, other, int op): 

""" 

Construct :class:`Constraint`s 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: x+1 < y-2 

-x0+x1-3>0 

sage: x+1 <= y-2 

-x0+x1-3>=0 

sage: x+1 == y-2 

x0-x1+3==0 

sage: x+1 >= y-2 

x0-x1+3>=0 

sage: x+1 > y-2 

x0-x1+3>0 

""" 

return _make_Constraint_from_richcmp(self, other, op) 

  

  

def __reduce__(self): 

""" 

Pickle object 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Linear_Expression 

sage: le = loads(dumps(Linear_Expression([1,2,3],4))) 

sage: le.coefficients() == (1,2,3) 

True 

sage: le.inhomogeneous_term() == 4 

True 

""" 

return (Linear_Expression, (self.coefficients(), self.inhomogeneous_term())) 

  

  

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

### Generator ###################################### 

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

cdef _wrap_Generator(PPL_Generator generator): 

""" 

Wrap a C++ ``PPL_Generator`` into a Cython ``Generator``. 

""" 

cdef Generator g = Generator(True) 

g.thisptr = new PPL_Generator(generator) 

return g 

  

  

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

# C++ static methods not supported 

# Note that the PPL_Generator default constructor is private, hence we must return pointers 

cdef extern from "ppl_shim.hh": 

PPL_Generator* new_line(PPL_Linear_Expression &e) except +ValueError 

PPL_Generator* new_ray(PPL_Linear_Expression &e) except +ValueError 

PPL_Generator* new_point(PPL_Linear_Expression &e, PPL_Coefficient d) except +ValueError 

PPL_Generator* new_closure_point(PPL_Linear_Expression &e, PPL_Coefficient d) except +ValueError 

PPL_Generator* new_MIP_optimizing_point(PPL_MIP_Problem &problem) except +ValueError 

  

  

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

cdef class Generator(object): 

r""" 

Wrapper for PPL's ``Generator`` class. 

  

An object of the class Generator is one of the following: 

  

* a line `\ell = (a_0, \dots, a_{n-1})^T` 

  

* a ray `r = (a_0, \dots, a_{n-1})^T` 

  

* a point `p = (\tfrac{a_0}{d}, \dots, \tfrac{a_{n-1}}{d})^T` 

  

* a closure point `c = (\tfrac{a_0}{d}, \dots, \tfrac{a_{n-1}}{d})^T` 

  

where `n` is the dimension of the space and, for points and 

closure points, `d` is the divisor. 

  

INPUT/OUTPUT: 

  

Use the helper functions :func:`line`, :func:`ray`, :func:`point`, 

and :func:`closure_point` to construct generators. Analogous class 

methods are also available, see :meth:`Generator.line`, 

:meth:`Generator.ray`, :meth:`Generator.point`, 

:meth:`Generator.closure_point`. Do not attempt to construct 

generators manually. 

  

.. NOTE:: 

  

The generators are constructed from linear expressions. The 

inhomogeneous term is always silently discarded. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Generator, Variable 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: Generator.line(5*x-2*y) 

line(5, -2) 

sage: Generator.ray(5*x-2*y) 

ray(5, -2) 

sage: Generator.point(5*x-2*y, 7) 

point(5/7, -2/7) 

sage: Generator.closure_point(5*x-2*y, 7) 

closure_point(5/7, -2/7) 

""" 

  

cdef PPL_Generator *thisptr 

  

  

def __cinit__(self, do_not_construct_manually=False): 

""" 

The Cython constructor. 

  

See :class:`Variable` for documentation. 

  

TESTS:: 

  

sage: from sage.libs.ppl import Variable, line 

sage: x = Variable(0) 

sage: line(x) # indirect doctest 

line(1) 

""" 

assert(do_not_construct_manually) 

self.thisptr = NULL 

  

  

def __dealloc__(self): 

""" 

The Cython destructor. 

""" 

assert self.thisptr!=NULL, 'Do not construct Generators manually!' 

del self.thisptr 

  

  

@classmethod 

def line(cls, expression): 

""" 

Construct a line. 

  

INPUT: 

  

- ``expression`` -- a :class:`Linear_Expression` or something 

convertible to it (:class:`Variable` or integer). 

  

OUTPUT: 

  

A new :class:`Generator` representing the line. 

  

Raises a ``ValueError` if the homogeneous part of 

``expression`` represents the origin of the vector space. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Generator, Variable 

sage: y = Variable(1) 

sage: Generator.line(2*y) 

line(0, 1) 

sage: Generator.line(y) 

line(0, 1) 

sage: Generator.line(1) 

Traceback (most recent call last): 

... 

ValueError: PPL::line(e): 

e == 0, but the origin cannot be a line. 

""" 

cdef Linear_Expression e = Linear_Expression(expression) 

# This does not work as Cython gets confused by the private default ctor 

# return _wrap_Generator(PPL_line(e.thisptr[0])) 

# workaround follows 

cdef Generator g = Generator(True) 

try: 

g.thisptr = new_line(e.thisptr[0]) 

except BaseException: 

# g.thisptr must be set to something valid or g.__dealloc__() will segfault 

g.thisptr = new_point(e.thisptr[0],PPL_Coefficient(1)) 

raise 

return g 

  

  

@classmethod 

def ray(cls, expression): 

""" 

Construct a ray. 

  

INPUT: 

  

- ``expression`` -- a :class:`Linear_Expression` or something 

convertible to it (:class:`Variable` or integer). 

  

OUTPUT: 

  

A new :class:`Generator` representing the ray. 

  

Raises a ``ValueError` if the homogeneous part of 

``expression`` represents the origin of the vector space. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Generator, Variable 

sage: y = Variable(1) 

sage: Generator.ray(2*y) 

ray(0, 1) 

sage: Generator.ray(y) 

ray(0, 1) 

sage: Generator.ray(1) 

Traceback (most recent call last): 

... 

ValueError: PPL::ray(e): 

e == 0, but the origin cannot be a ray. 

""" 

cdef Linear_Expression e = Linear_Expression(expression) 

# This does not work as Cython gets confused by the private default ctor 

# return _wrap_Generator(PPL_ray(e.thisptr[0])) 

# workaround follows 

cdef Generator g = Generator(True) 

try: 

g.thisptr = new_ray(e.thisptr[0]) 

except BaseException: 

# g.thisptr must be set to something valid or g.__dealloc__() will segfault 

g.thisptr = new_point(e.thisptr[0],PPL_Coefficient(1)) 

raise 

return g 

  

  

@classmethod 

def point(cls, expression=0, divisor=1): 

""" 

Construct a point. 

  

INPUT: 

  

- ``expression`` -- a :class:`Linear_Expression` or something 

convertible to it (:class:`Variable` or integer). 

  

- ``divisor`` -- an integer. 

  

OUTPUT: 

  

A new :class:`Generator` representing the point. 

  

Raises a ``ValueError` if ``divisor==0``. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Generator, Variable 

sage: y = Variable(1) 

sage: Generator.point(2*y+7, 3) 

point(0/3, 2/3) 

sage: Generator.point(y+7, 3) 

point(0/3, 1/3) 

sage: Generator.point(7, 3) 

point() 

sage: Generator.point(0, 0) 

Traceback (most recent call last): 

... 

ValueError: PPL::point(e, d): 

d == 0. 

""" 

cdef Linear_Expression e = Linear_Expression(expression) 

cdef Integer d = Integer(divisor) 

# This does not work as Cython gets confused by the private default ctor 

# return _wrap_Generator(PPL_point(e.thisptr[0], PPL_Coefficient(d.value))) 

# workaround follows 

cdef Generator g = Generator(True) 

try: 

g.thisptr = new_point(e.thisptr[0], PPL_Coefficient(d.value)) 

except BaseException: 

# g.thisptr must be set to something valid or g.__dealloc__() will segfault 

g.thisptr = new_point(e.thisptr[0],PPL_Coefficient(1)) 

raise 

return g 

  

  

@classmethod 

def closure_point(cls, expression=0, divisor=1): 

""" 

Construct a closure point. 

  

A closure point is a point of the topological closure of a 

polyhedron that is not a point of the polyhedron itself. 

  

INPUT: 

  

- ``expression`` -- a :class:`Linear_Expression` or something 

convertible to it (:class:`Variable` or integer). 

  

- ``divisor`` -- an integer. 

  

OUTPUT: 

  

A new :class:`Generator` representing the point. 

  

Raises a ``ValueError` if ``divisor==0``. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Generator, Variable 

sage: y = Variable(1) 

sage: Generator.closure_point(2*y+7, 3) 

closure_point(0/3, 2/3) 

sage: Generator.closure_point(y+7, 3) 

closure_point(0/3, 1/3) 

sage: Generator.closure_point(7, 3) 

closure_point() 

sage: Generator.closure_point(0, 0) 

Traceback (most recent call last): 

... 

ValueError: PPL::closure_point(e, d): 

d == 0. 

""" 

cdef Linear_Expression e = Linear_Expression(expression) 

cdef Integer d = Integer(divisor) 

# This does not work as Cython gets confused by the private default ctor 

# return _wrap_Generator(PPL_closure_point(e.thisptr[0], PPL_Coefficient(d.value))) 

# workaround follows 

cdef Generator g = Generator(True) 

try: 

g.thisptr = new_closure_point(e.thisptr[0], PPL_Coefficient(d.value)) 

except BaseException: 

# g.thisptr must be set to something valid or g.__dealloc__() will segfault 

g.thisptr = new_point(e.thisptr[0],PPL_Coefficient(1)) 

raise 

return g 

  

  

def __repr__(self): 

""" 

Return a string representation of the generator. 

  

OUTPUT: 

  

String. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Generator, Variable 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: e = 2*x-y+5 

sage: Generator.line(e) 

line(2, -1) 

sage: Generator.ray(e) 

ray(2, -1) 

sage: Generator.point(e, 3) 

point(2/3, -1/3) 

sage: Generator.closure_point(e, 3) 

closure_point(2/3, -1/3) 

""" 

t = self.type() 

if t=='line': 

s = 'line(' 

div = '' 

elif t=='ray': 

s = 'ray(' 

div = '' 

elif t=='point': 

s = 'point(' 

div = '/'+str(self.divisor()) 

elif t=='closure_point': 

s = 'closure_point(' 

div = '/'+str(self.divisor()) 

else: 

assert(False) 

  

for i in range(0,self.space_dimension()): 

if i>0: 

s += ', ' 

s += str(self.coefficient(Variable(i))) + div 

  

s += ')' 

return s 

  

  

def space_dimension(self): 

r""" 

Return the dimension of the vector space enclosing ``self``. 

  

OUTPUT: 

  

Integer. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, point 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: point(x).space_dimension() 

1 

sage: point(y).space_dimension() 

2 

""" 

return self.thisptr.space_dimension() 

  

  

def type(self): 

r""" 

Return the generator type of ``self``. 

  

OUTPUT: 

  

String. One of ``'line'``, ``'ray'``, ``'point'``, or 

``'closure_point'``. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, point, closure_point, ray, line 

sage: x = Variable(0) 

sage: line(x).type() 

'line' 

sage: ray(x).type() 

'ray' 

sage: point(x,2).type() 

'point' 

sage: closure_point(x,2).type() 

'closure_point' 

""" 

t = self.thisptr.type() 

if t==LINE: 

return 'line' 

elif t==RAY: 

return 'ray' 

elif t==POINT: 

return 'point' 

elif t==CLOSURE_POINT: 

return 'closure_point' 

assert False 

  

  

def is_line(self): 

r""" 

Test whether ``self`` is a line. 

  

OUTPUT: 

  

Boolean. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, point, closure_point, ray, line 

sage: x = Variable(0) 

sage: line(x).is_line() 

True 

sage: ray(x).is_line() 

False 

sage: point(x,2).is_line() 

False 

sage: closure_point(x,2).is_line() 

False 

""" 

return self.thisptr.is_line() 

  

  

def is_ray(self): 

r""" 

Test whether ``self`` is a ray. 

  

OUTPUT: 

  

Boolean. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, point, closure_point, ray, line 

sage: x = Variable(0) 

sage: line(x).is_ray() 

False 

sage: ray(x).is_ray() 

True 

sage: point(x,2).is_ray() 

False 

sage: closure_point(x,2).is_ray() 

False 

""" 

return self.thisptr.is_ray() 

  

  

def is_line_or_ray(self): 

r""" 

Test whether ``self`` is a line or a ray. 

  

OUTPUT: 

  

Boolean. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, point, closure_point, ray, line 

sage: x = Variable(0) 

sage: line(x).is_line_or_ray() 

True 

sage: ray(x).is_line_or_ray() 

True 

sage: point(x,2).is_line_or_ray() 

False 

sage: closure_point(x,2).is_line_or_ray() 

False 

""" 

return self.thisptr.is_line_or_ray() 

  

  

def is_point(self): 

r""" 

Test whether ``self`` is a point. 

  

OUTPUT: 

  

Boolean. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, point, closure_point, ray, line 

sage: x = Variable(0) 

sage: line(x).is_point() 

False 

sage: ray(x).is_point() 

False 

sage: point(x,2).is_point() 

True 

sage: closure_point(x,2).is_point() 

False 

""" 

return self.thisptr.is_point() 

  

  

def is_closure_point(self): 

r""" 

Test whether ``self`` is a closure point. 

  

OUTPUT: 

  

Boolean. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, point, closure_point, ray, line 

sage: x = Variable(0) 

sage: line(x).is_closure_point() 

False 

sage: ray(x).is_closure_point() 

False 

sage: point(x,2).is_closure_point() 

False 

sage: closure_point(x,2).is_closure_point() 

True 

""" 

return self.thisptr.is_closure_point() 

  

  

def coefficient(self, Variable v): 

""" 

Return the coefficient of the variable ``v``. 

  

INPUT: 

  

- ``v`` -- a :class:`Variable`. 

  

OUTPUT: 

  

An integer. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, line 

sage: x = Variable(0) 

sage: line = line(3*x+1) 

sage: line 

line(1) 

sage: line.coefficient(x) 

1 

""" 

cdef Integer c = Integer(0) 

mpz_set(c.value, self.thisptr.coefficient(v.thisptr[0]).get_mpz_t()) 

return c 

  

  

def coefficients(self): 

""" 

Return the coefficients of the generator. 

  

See also :meth:`coefficient`. 

  

OUTPUT: 

  

A tuple of integers of length :meth:`space_dimension`. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, point 

sage: x = Variable(0); y = Variable(1) 

sage: p = point(3*x+5*y+1, 2); p 

point(3/2, 5/2) 

sage: p.coefficients() 

(3, 5) 

""" 

cdef int d = self.space_dimension() 

cdef int i 

cdef Integer c = Integer(0) 

coeffs = [] 

for i in range(0,d): 

mpz_set(c.value, self.thisptr.coefficient(PPL_Variable(i)).get_mpz_t()) 

coeffs.append(Integer(c)) 

return tuple(coeffs) 

  

  

def divisor(self): 

""" 

If ``self`` is either a point or a closure point, return its 

divisor. 

  

OUTPUT: 

  

An integer. If ``self`` is a ray or a line, raises 

``ValueError``. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Generator, Variable 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: point = Generator.point(2*x-y+5) 

sage: point.divisor() 

1 

sage: line = Generator.line(2*x-y+5) 

sage: line.divisor() 

Traceback (most recent call last): 

... 

ValueError: PPL::Generator::divisor(): 

*this is neither a point nor a closure point. 

""" 

cdef Integer c = Integer(0) 

mpz_set(c.value, self.thisptr.divisor().get_mpz_t()) 

return c 

  

  

def is_equivalent_to(self, Generator g): 

r""" 

Test whether ``self`` and ``g`` are equivalent. 

  

INPUT: 

  

- ``g`` -- a :class:`Generator`. 

  

OUTPUT: 

  

Boolean. Returns ``True`` if and only if ``self`` and ``g`` 

are equivalent generators. 

  

Note that generators having different space dimensions are not 

equivalent. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Generator, Variable, point, line 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: point(2*x , 2).is_equivalent_to( point(x) ) 

True 

sage: point(2*x+0*y, 2).is_equivalent_to( point(x) ) 

False 

sage: line(4*x).is_equivalent_to(line(x)) 

True 

""" 

return self.thisptr.is_equivalent_to(g.thisptr[0]) 

  

  

def ascii_dump(self): 

r""" 

Write an ASCII dump to stderr. 

  

EXAMPLES:: 

  

sage: sage_cmd = 'from sage.libs.ppl import Linear_Expression, Variable, point\n' 

sage: sage_cmd += 'x = Variable(0)\n' 

sage: sage_cmd += 'y = Variable(1)\n' 

sage: sage_cmd += 'p = point(3*x+2*y)\n' 

sage: sage_cmd += 'p.ascii_dump()\n' 

sage: from sage.tests.cmdline import test_executable 

sage: (out, err, ret) = test_executable(['sage', '-c', sage_cmd], timeout=100) # long time, indirect doctest 

sage: print(err) # long time 

size 3 1 3 2 P (C) 

""" 

self.thisptr.ascii_dump() 

  

  

def OK(self): 

""" 

Check if all the invariants are satisfied. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Linear_Expression, Variable 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: e = 3*x+2*y+1 

sage: e.OK() 

True 

""" 

return self.thisptr.OK() 

  

  

def __reduce__(self): 

""" 

Pickle object. 

  

TESTS:: 

  

sage: from sage.libs.ppl import Generator, Variable, line, ray, point, closure_point 

sage: x = Variable(0); y = Variable(1); 

sage: loads(dumps(Generator.point(2*x+7*y, 3))) 

point(2/3, 7/3) 

sage: loads(dumps(Generator.closure_point(2*x+7*y, 3))) 

closure_point(2/3, 7/3) 

sage: loads(dumps(Generator.line(2*x+7*y))) 

line(2, 7) 

sage: loads(dumps(Generator.ray(2*x+7*y))) 

ray(2, 7) 

""" 

t = self.thisptr.type() 

le = Linear_Expression(self.coefficients(), 0) 

if t==LINE: 

return (line, (le,)) 

elif t==RAY: 

return (ray, (le,)) 

elif t==POINT: 

return (point, (le, self.divisor())) 

elif t==CLOSURE_POINT: 

return (closure_point, (le, self.divisor())) 

assert False 

  

  

  

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

def line(expression): 

""" 

Constuct a line. 

  

See :meth:`Generator.line` for documentation. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, line 

sage: y = Variable(1) 

sage: line(2*y) 

line(0, 1) 

""" 

return Generator.line(expression) 

  

  

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

def ray(expression): 

""" 

Constuct a ray. 

  

See :meth:`Generator.ray` for documentation. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, ray 

sage: y = Variable(1) 

sage: ray(2*y) 

ray(0, 1) 

""" 

return Generator.ray(expression) 

  

  

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

def point(expression=0, divisor=1): 

""" 

Constuct a point. 

  

See :meth:`Generator.point` for documentation. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, point 

sage: y = Variable(1) 

sage: point(2*y, 5) 

point(0/5, 2/5) 

""" 

return Generator.point(expression, divisor) 

  

  

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

def closure_point(expression=0, divisor=1): 

""" 

Constuct a closure point. 

  

See :meth:`Generator.closure_point` for documentation. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, closure_point 

sage: y = Variable(1) 

sage: closure_point(2*y, 5) 

closure_point(0/5, 2/5) 

""" 

return Generator.closure_point(expression, divisor) 

  

  

  

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

### Generator_System ############################## 

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

cdef _wrap_Generator_System(PPL_Generator_System generator_system): 

""" 

Wrap a C++ ``PPL_Generator_System`` into a Cython ``Generator_System``. 

""" 

cdef Generator_System gs = Generator_System() 

del gs.thisptr 

gs.thisptr = new PPL_Generator_System(generator_system) 

return gs 

  

  

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

cdef class Generator_System(_mutable_or_immutable): 

""" 

Wrapper for PPL's ``Generator_System`` class. 

  

An object of the class Generator_System is a system of generators, 

i.e., a multiset of objects of the class Generator (lines, rays, 

points and closure points). When inserting generators in a system, 

space dimensions are automatically adjusted so that all the 

generators in the system are defined on the same vector space. A 

system of generators which is meant to define a non-empty 

polyhedron must include at least one point: the reason is that 

lines, rays and closure points need a supporting point (lines and 

rays only specify directions while closure points only specify 

points in the topological closure of the NNC polyhedron). 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Generator_System, Variable, line, ray, point, closure_point 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: gs = Generator_System( line(5*x-2*y) ) 

sage: gs.insert( ray(6*x-3*y) ) 

sage: gs.insert( point(2*x-7*y, 5) ) 

sage: gs.insert( closure_point(9*x-1*y, 2) ) 

sage: gs 

Generator_System {line(5, -2), ray(2, -1), point(2/5, -7/5), closure_point(9/2, -1/2)} 

""" 

  

cdef PPL_Generator_System *thisptr 

  

  

def __cinit__(self, arg=None): 

""" 

The Cython constructor. 

  

See :class:`Generator_System` for documentation. 

  

TESTS:: 

  

sage: from sage.libs.ppl import Generator_System 

sage: Generator_System() # indirect doctest 

Generator_System {} 

""" 

if arg is None: 

self.thisptr = new PPL_Generator_System() 

return 

if isinstance(arg, Generator): 

g = <Generator>arg 

self.thisptr = new PPL_Generator_System(g.thisptr[0]) 

return 

if isinstance(arg, Generator_System): 

gs = <Generator_System>arg 

self.thisptr = new PPL_Generator_System(gs.thisptr[0]) 

return 

if isinstance(arg, (list,tuple)): 

self.thisptr = new PPL_Generator_System() 

for generator in arg: 

self.insert(generator) 

return 

raise ValueError('Cannot initialize with '+str(arg)+'.') 

  

  

def __dealloc__(self): 

""" 

The Cython destructor. 

""" 

del self.thisptr 

  

  

def space_dimension(self): 

r""" 

Return the dimension of the vector space enclosing ``self``. 

  

OUTPUT: 

  

Integer. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, Generator_System, point 

sage: x = Variable(0) 

sage: gs = Generator_System( point(3*x) ) 

sage: gs.space_dimension() 

1 

""" 

return self.thisptr.space_dimension() 

  

  

def clear(self): 

r""" 

Removes all generators from the generator system and sets its 

space dimension to 0. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, Generator_System, point 

sage: x = Variable(0) 

sage: gs = Generator_System( point(3*x) ); gs 

Generator_System {point(3/1)} 

sage: gs.clear() 

sage: gs 

Generator_System {} 

""" 

self.assert_mutable('The Generator_System is not mutable!') 

self.thisptr.clear() 

  

  

def insert(self, Generator g): 

""" 

Insert ``g`` into the generator system. 

  

The number of space dimensions of ``self`` is increased, if needed. 

  

INPUT: 

  

- ``g`` -- a :class:`Generator`. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, Generator_System, point 

sage: x = Variable(0) 

sage: gs = Generator_System( point(3*x) ) 

sage: gs.insert( point(-3*x) ) 

sage: gs 

Generator_System {point(3/1), point(-3/1)} 

""" 

self.assert_mutable('The Generator_System is not mutable!') 

self.thisptr.insert(g.thisptr[0]) 

  

  

def empty(self): 

""" 

Return ``True`` if and only if ``self`` has no generators. 

  

OUTPUT: 

  

Boolean. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, Generator_System, point 

sage: x = Variable(0) 

sage: gs = Generator_System() 

sage: gs.empty() 

True 

sage: gs.insert( point(-3*x) ) 

sage: gs.empty() 

False 

""" 

return self.thisptr.empty() 

  

  

def ascii_dump(self): 

r""" 

Write an ASCII dump to stderr. 

  

EXAMPLES:: 

  

sage: sage_cmd = 'from sage.libs.ppl import Generator_System, point, Variable\n' 

sage: sage_cmd += 'x = Variable(0)\n' 

sage: sage_cmd += 'y = Variable(1)\n' 

sage: sage_cmd += 'gs = Generator_System( point(3*x+2*y+1) )\n' 

sage: sage_cmd += 'gs.ascii_dump()\n' 

sage: from sage.tests.cmdline import test_executable 

sage: (out, err, ret) = test_executable(['sage', '-c', sage_cmd], timeout=100) # long time, indirect doctest 

sage: print(err) # long time 

topology NECESSARILY_CLOSED 

1 x 2 SPARSE (sorted) 

index_first_pending 1 

size 3 1 3 2 P (C) 

""" 

self.thisptr.ascii_dump() 

  

  

def OK(self): 

""" 

Check if all the invariants are satisfied. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, Generator_System, point 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: gs = Generator_System( point(3*x+2*y+1) ) 

sage: gs.OK() 

True 

""" 

return self.thisptr.OK() 

  

  

def __len__(self): 

""" 

Return the number of generators in the system. 

  

sage: from sage.libs.ppl import Variable, Generator_System, point 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: gs = Generator_System() 

sage: gs.insert(point(3*x+2*y)) 

sage: gs.insert(point(x)) 

sage: gs.insert(point(y)) 

sage: len(gs) 

3 

""" 

return sum([1 for g in self]) 

  

  

def __iter__(self): 

""" 

Iterate through the generators of the system. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Generator_System, Variable, point 

sage: x = Variable(0) 

sage: gs = Generator_System(point(3*x)) 

sage: iter = gs.__iter__() 

sage: next(iter) 

point(3/1) 

""" 

return Generator_System_iterator(self) 

  

  

def __getitem__(self, int k): 

""" 

Return the ``k``-th generator. 

  

The correct way to read the individual generators is to 

iterate over the generator system. This method is for 

convenience only. 

  

INPUT: 

  

- ``k`` -- integer. The index of the generator. 

  

OUTPUT: 

  

The ``k``-th constraint of the generator system. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Generator_System, Variable, point 

sage: x = Variable(0) 

sage: gs = Generator_System() 

sage: gs.insert(point(3*x)) 

sage: gs.insert(point(-2*x)) 

sage: gs 

Generator_System {point(3/1), point(-2/1)} 

sage: gs[0] 

point(3/1) 

sage: gs[1] 

point(-2/1) 

""" 

if k < 0: 

raise IndexError('index must be nonnegative') 

iterator = iter(self) 

try: 

for i in range(k): 

next(iterator) 

except StopIteration: 

raise IndexError('index is past-the-end') 

return next(iterator) 

  

  

def __repr__(self): 

r""" 

Return a string representation of the generator system. 

  

OUTPUT: 

  

A string. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Generator_System, Variable, point, ray 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: gs = Generator_System(point(3*x+2*y+1)) 

sage: gs.insert(ray(x)) 

sage: gs.__repr__() 

'Generator_System {point(3/1, 2/1), ray(1, 0)}' 

""" 

s = 'Generator_System {' 

s += ', '.join([ repr(g) for g in self ]) 

s += '}' 

return s 

  

  

def __reduce__(self): 

""" 

Pickle object. 

  

TESTS:: 

  

sage: from sage.libs.ppl import Generator_System, Variable, point, ray 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: gs = Generator_System((point(3*x+2*y+1), ray(x))); gs 

Generator_System {point(3/1, 2/1), ray(1, 0)} 

sage: loads(dumps(gs)) 

Generator_System {point(3/1, 2/1), ray(1, 0)} 

""" 

return (Generator_System, (tuple(self), )) 

  

  

  

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

### Generator_System_iterator ###################### 

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

cdef extern from "ppl_shim.hh": 

ctypedef void* gs_iterator_ptr 

cdef gs_iterator_ptr init_gs_iterator(PPL_Generator_System &gs) 

cdef PPL_Generator next_gs_iterator(gs_iterator_ptr) 

cdef bint is_end_gs_iterator(PPL_Generator_System &gs, gs_iterator_ptr gsi_ptr) 

cdef void delete_gs_iterator(gs_iterator_ptr) 

  

  

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

cdef class Generator_System_iterator(object): 

""" 

Wrapper for PPL's ``Generator_System::const_iterator`` class. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Generator_System, Variable, line, ray, point, closure_point, Generator_System_iterator 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: gs = Generator_System( line(5*x-2*y) ) 

sage: gs.insert( ray(6*x-3*y) ) 

sage: gs.insert( point(2*x-7*y, 5) ) 

sage: gs.insert( closure_point(9*x-1*y, 2) ) 

sage: next(Generator_System_iterator(gs)) 

line(5, -2) 

sage: list(gs) 

[line(5, -2), ray(2, -1), point(2/5, -7/5), closure_point(9/2, -1/2)] 

""" 

  

cdef Generator_System gs 

cdef gs_iterator_ptr gsi_ptr 

  

  

def __cinit__(self, Generator_System gs): 

r""" 

The Cython constructor. 

  

TESTS:: 

  

sage: from sage.libs.ppl import Generator_System, Generator_System_iterator 

sage: iter = Generator_System_iterator(Generator_System()) # indirect doctest 

""" 

self.gs = gs 

self.gsi_ptr = init_gs_iterator(gs.thisptr[0]) 

  

  

def __dealloc__(self): 

""" 

The Cython destructor. 

""" 

delete_gs_iterator(self.gsi_ptr) 

  

  

def __next__(Generator_System_iterator self): 

r""" 

The next iteration. 

  

OUTPUT: 

  

A :class:`Generator`. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Generator_System, Variable, point, Generator_System_iterator 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: gs = Generator_System( point(5*x-2*y) ) 

sage: next(Generator_System_iterator(gs)) 

point(5/1, -2/1) 

""" 

if is_end_gs_iterator((<Generator_System>self.gs).thisptr[0], self.gsi_ptr): 

raise StopIteration 

return _wrap_Generator(next_gs_iterator(self.gsi_ptr)) 

  

  

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

### Constraint ###################################### 

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

cdef _wrap_Constraint(PPL_Constraint constraint): 

""" 

Wrap a C++ ``PPL_Constraint`` into a Cython ``Constraint``. 

""" 

cdef Constraint c = Constraint(True) 

c.thisptr = new PPL_Constraint(constraint) 

return c 

  

  

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

cdef _make_Constraint_from_richcmp(lhs_, rhs_, op): 

cdef Linear_Expression lhs = Linear_Expression(lhs_) 

cdef Linear_Expression rhs = Linear_Expression(rhs_) 

if op == Py_LT: 

return _wrap_Constraint(lhs.thisptr[0] < rhs.thisptr[0]) 

elif op == Py_LE: 

return _wrap_Constraint(lhs.thisptr[0] <= rhs.thisptr[0]) 

elif op == Py_EQ: 

return _wrap_Constraint(lhs.thisptr[0] == rhs.thisptr[0]) 

elif op == Py_GT: 

return _wrap_Constraint(lhs.thisptr[0] > rhs.thisptr[0]) 

elif op == Py_GE: 

return _wrap_Constraint(lhs.thisptr[0] >= rhs.thisptr[0]) 

elif op == Py_NE: 

raise NotImplementedError 

else: 

assert(False) 

  

  

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

cdef class Constraint(object): 

""" 

Wrapper for PPL's ``Constraint`` class. 

  

An object of the class ``Constraint`` is either: 

  

* an equality `\sum_{i=0}^{n-1} a_i x_i + b = 0` 

  

* a non-strict inequality `\sum_{i=0}^{n-1} a_i x_i + b \geq 0` 

  

* a strict inequality `\sum_{i=0}^{n-1} a_i x_i + b > 0` 

  

where `n` is the dimension of the space, `a_i` is the integer 

coefficient of variable `x_i`, and `b_i` is the integer 

inhomogeneous term. 

  

INPUT/OUTPUT: 

  

You construct constraints by writing inequalities in 

:class:`Linear_Expression`. Do not attempt to manually construct 

constraints. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Constraint, Variable, Linear_Expression 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: 5*x-2*y > x+y-1 

4*x0-3*x1+1>0 

sage: 5*x-2*y >= x+y-1 

4*x0-3*x1+1>=0 

sage: 5*x-2*y == x+y-1 

4*x0-3*x1+1==0 

sage: 5*x-2*y <= x+y-1 

-4*x0+3*x1-1>=0 

sage: 5*x-2*y < x+y-1 

-4*x0+3*x1-1>0 

sage: x > 0 

x0>0 

  

Special care is needed if the left hand side is a constant:: 

  

sage: 0 == 1 # watch out! 

False 

sage: Linear_Expression(0) == 1 

-1==0 

""" 

  

cdef PPL_Constraint *thisptr 

  

  

def __cinit__(self, do_not_construct_manually=False): 

""" 

The Cython constructor. 

  

See :class:`Constraint` for documentation. 

  

TESTS:: 

  

sage: from sage.libs.ppl import Constraint, Variable, Linear_Expression 

sage: x = Variable(0) 

sage: x>0 # indirect doctest 

x0>0 

""" 

assert(do_not_construct_manually) 

self.thisptr = NULL 

  

  

def __dealloc__(self): 

""" 

The Cython destructor. 

""" 

assert self.thisptr!=NULL, 'Do not construct Constraints manually!' 

del self.thisptr 

  

  

def __repr__(self): 

""" 

Return a string representation of the constraint. 

  

OUTPUT: 

  

String. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Constraint, Variable 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: (2*x-y+5 > x).__repr__() 

'x0-x1+5>0' 

sage: (2*x-y+5 == x).__repr__() 

'x0-x1+5==0' 

sage: (2*x-y+5 >= x).__repr__() 

'x0-x1+5>=0' 

""" 

e = sum([ self.coefficient(x)*x 

for x in [Variable(i) 

for i in range(0,self.space_dimension())] ]) 

e += self.inhomogeneous_term() 

s = repr(e) 

t = self.type() 

if t=='equality': 

s += '==0' 

elif t=='nonstrict_inequality': 

s += '>=0' 

elif t=='strict_inequality': 

s += '>0' 

else: 

assert(False) 

return s 

  

  

def space_dimension(self): 

r""" 

Return the dimension of the vector space enclosing ``self``. 

  

OUTPUT: 

  

Integer. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: (x>=0).space_dimension() 

1 

sage: (y==1).space_dimension() 

2 

""" 

return self.thisptr.space_dimension() 

  

  

def type(self): 

r""" 

Return the constraint type of ``self``. 

  

OUTPUT: 

  

String. One of ``'equality'``, ``'nonstrict_inequality'``, or 

``'strict_inequality'``. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable 

sage: x = Variable(0) 

sage: (x==0).type() 

'equality' 

sage: (x>=0).type() 

'nonstrict_inequality' 

sage: (x>0).type() 

'strict_inequality' 

""" 

t = self.thisptr.type() 

if t==EQUALITY: 

return 'equality' 

elif t==NONSTRICT_INEQUALITY: 

return 'nonstrict_inequality' 

elif t==STRICT_INEQUALITY: 

return 'strict_inequality' 

  

  

def is_equality(self): 

r""" 

Test whether ``self`` is an equality. 

  

OUTPUT: 

  

Boolean. Returns ``True`` if and only if ``self`` is an 

equality constraint. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable 

sage: x = Variable(0) 

sage: (x==0).is_equality() 

True 

sage: (x>=0).is_equality() 

False 

sage: (x>0).is_equality() 

False 

""" 

return self.thisptr.is_equality() 

  

  

def is_inequality(self): 

r""" 

Test whether ``self`` is an inequality. 

  

OUTPUT: 

  

Boolean. Returns ``True`` if and only if ``self`` is an 

inequality constraint, either strict or non-strict. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable 

sage: x = Variable(0) 

sage: (x==0).is_inequality() 

False 

sage: (x>=0).is_inequality() 

True 

sage: (x>0).is_inequality() 

True 

""" 

return self.thisptr.is_inequality() 

  

  

def is_nonstrict_inequality(self): 

r""" 

Test whether ``self`` is a non-strict inequality. 

  

OUTPUT: 

  

Boolean. Returns ``True`` if and only if ``self`` is an 

non-strict inequality constraint. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable 

sage: x = Variable(0) 

sage: (x==0).is_nonstrict_inequality() 

False 

sage: (x>=0).is_nonstrict_inequality() 

True 

sage: (x>0).is_nonstrict_inequality() 

False 

""" 

return self.thisptr.is_nonstrict_inequality() 

  

  

def is_strict_inequality(self): 

r""" 

Test whether ``self`` is a strict inequality. 

  

OUTPUT: 

  

Boolean. Returns ``True`` if and only if ``self`` is an 

strict inequality constraint. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable 

sage: x = Variable(0) 

sage: (x==0).is_strict_inequality() 

False 

sage: (x>=0).is_strict_inequality() 

False 

sage: (x>0).is_strict_inequality() 

True 

""" 

return self.thisptr.is_strict_inequality() 

  

  

def coefficient(self, Variable v): 

""" 

Return the coefficient of the variable ``v``. 

  

INPUT: 

  

- ``v`` -- a :class:`Variable`. 

  

OUTPUT: 

  

An integer. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable 

sage: x = Variable(0) 

sage: ineq = (3*x+1 > 0) 

sage: ineq.coefficient(x) 

3 

""" 

cdef Integer c = Integer(0) 

mpz_set(c.value, self.thisptr.coefficient(v.thisptr[0]).get_mpz_t()) 

return c 

  

  

def coefficients(self): 

""" 

Return the coefficients of the constraint. 

  

See also :meth:`coefficient`. 

  

OUTPUT: 

  

A tuple of integers of length :meth:`space_dimension`. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable 

sage: x = Variable(0); y = Variable(1) 

sage: ineq = ( 3*x+5*y+1 == 2); ineq 

3*x0+5*x1-1==0 

sage: ineq.coefficients() 

(3, 5) 

""" 

cdef int d = self.space_dimension() 

cdef int i 

cdef Integer c = Integer(0) 

coeffs = [] 

for i in range(0,d): 

mpz_set(c.value, self.thisptr.coefficient(PPL_Variable(i)).get_mpz_t()) 

coeffs.append(Integer(c)) 

return tuple(coeffs) 

  

  

def inhomogeneous_term(self): 

""" 

Return the inhomogeneous term of the constraint. 

  

OUTPUT: 

  

Integer. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable 

sage: y = Variable(1) 

sage: ineq = ( 10+y > 9 ) 

sage: ineq 

x1+1>0 

sage: ineq.inhomogeneous_term() 

1 

""" 

cdef Integer c = Integer(0) 

mpz_set(c.value, self.thisptr.inhomogeneous_term().get_mpz_t()) 

return c 

  

  

def is_tautological(self): 

r""" 

Test whether ``self`` is a tautological constraint. 

  

A tautology can have either one of the following forms: 

  

* an equality: `\sum 0 x_i + 0 = 0`, 

  

* a non-strict inequality: `\sum 0 x_i + b \geq 0` with `b\geq 0`, or 

  

* a strict inequality: `\sum 0 x_i + b > 0` with `b> 0`. 

  

OUTPUT: 

  

Boolean. Returns ``True`` if and only if ``self`` is a 

tautological constraint. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable 

sage: x = Variable(0) 

sage: (x==0).is_tautological() 

False 

sage: (0*x>=0).is_tautological() 

True 

""" 

return self.thisptr.is_tautological() 

  

  

def is_inconsistent(self): 

r""" 

Test whether ``self`` is an inconsistent constraint, that is, always false. 

  

An inconsistent constraint can have either one of the 

following forms: 

  

* an equality: `\sum 0 x_i + b = 0` with `b\not=0`, 

  

* a non-strict inequality: `\sum 0 x_i + b \geq 0` with `b< 0`, or 

  

* a strict inequality: `\sum 0 x_i + b > 0` with `b\leq 0`. 

  

OUTPUT: 

  

Boolean. Returns ``True`` if and only if ``self`` is an 

inconsistent constraint. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable 

sage: x = Variable(0) 

sage: (x==1).is_inconsistent() 

False 

sage: (0*x>=1).is_inconsistent() 

True 

""" 

return self.thisptr.is_inconsistent() 

  

  

def is_equivalent_to(self, Constraint c): 

r""" 

Test whether ``self`` and ``c`` are equivalent. 

  

INPUT: 

  

- ``c`` -- a :class:`Constraint`. 

  

OUTPUT: 

  

Boolean. Returns ``True`` if and only if ``self`` and ``c`` 

are equivalent constraints. 

  

Note that constraints having different space dimensions are 

not equivalent. However, constraints having different types 

may nonetheless be equivalent, if they both are tautologies or 

inconsistent. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, Linear_Expression 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: ( x>0 ).is_equivalent_to( Linear_Expression(0)<x ) 

True 

sage: ( x>0 ).is_equivalent_to( 0*y<x ) 

False 

sage: ( 0*x>1 ).is_equivalent_to( 0*x==-2 ) 

True 

""" 

return self.thisptr.is_equivalent_to(c.thisptr[0]) 

  

  

def ascii_dump(self): 

r""" 

Write an ASCII dump to stderr. 

  

EXAMPLES:: 

  

sage: sage_cmd = 'from sage.libs.ppl import Linear_Expression, Variable\n' 

sage: sage_cmd += 'x = Variable(0)\n' 

sage: sage_cmd += 'y = Variable(1)\n' 

sage: sage_cmd += 'e = (3*x+2*y+1 > 0)\n' 

sage: sage_cmd += 'e.ascii_dump()\n' 

sage: from sage.tests.cmdline import test_executable 

sage: (out, err, ret) = test_executable(['sage', '-c', sage_cmd], timeout=100) # long time, indirect doctest 

sage: print(err) # long time 

size 4 1 3 2 -1 > (NNC) 

""" 

self.thisptr.ascii_dump() 

  

  

def OK(self): 

""" 

Check if all the invariants are satisfied. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Linear_Expression, Variable 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: ineq = (3*x+2*y+1>=0) 

sage: ineq.OK() 

True 

""" 

return self.thisptr.OK() 

  

  

def __reduce__(self): 

""" 

Pickle object. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Linear_Expression, Variable 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: loads(dumps(3*x+2*y+1>=5)) 

3*x0+2*x1-4>=0 

sage: loads(dumps(3*x+2*y+1>5)) 

3*x0+2*x1-4>0 

sage: loads(dumps(3*x+2*y+1==5)) 

3*x0+2*x1-4==0 

""" 

le = Linear_Expression(self.coefficients(), self.inhomogeneous_term()) 

if self.is_nonstrict_inequality(): 

return (inequality, (le, )) 

elif self.is_strict_inequality(): 

return (strict_inequality, (le, )) 

elif self.is_equality(): 

return (equation, (le, )) 

else: 

assert False 

  

  

  

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

def inequality(expression): 

""" 

Constuct an inequality. 

  

INPUT: 

  

- ``expression`` -- a :class:`Linear_Expression`. 

  

OUTPUT: 

  

The inequality ``expression`` >= 0. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, inequality 

sage: y = Variable(1) 

sage: 2*y+1 >= 0 

2*x1+1>=0 

sage: inequality(2*y+1) 

2*x1+1>=0 

""" 

return expression >= 0 

  

  

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

def strict_inequality(expression): 

""" 

Constuct a strict inequality. 

  

INPUT: 

  

- ``expression`` -- a :class:`Linear_Expression`. 

  

OUTPUT: 

  

The inequality ``expression`` > 0. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, strict_inequality 

sage: y = Variable(1) 

sage: 2*y+1 > 0 

2*x1+1>0 

sage: strict_inequality(2*y+1) 

2*x1+1>0 

""" 

return expression > 0 

  

  

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

def equation(expression): 

""" 

Constuct an equation. 

  

INPUT: 

  

- ``expression`` -- a :class:`Linear_Expression`. 

  

OUTPUT: 

  

The equation ``expression`` == 0. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, equation 

sage: y = Variable(1) 

sage: 2*y+1 == 0 

2*x1+1==0 

sage: equation(2*y+1) 

2*x1+1==0 

""" 

return expression == 0 

  

  

  

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

### Constraint_System ############################## 

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

cdef _wrap_Constraint_System(PPL_Constraint_System constraint_system): 

""" 

Wrap a C++ ``PPL_Constraint_System`` into a Cython ``Constraint_System``. 

""" 

cdef Constraint_System cs = Constraint_System() 

del cs.thisptr 

cs.thisptr = new PPL_Constraint_System(constraint_system) 

return cs 

  

  

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

cdef class Constraint_System(object): 

""" 

Wrapper for PPL's ``Constraint_System`` class. 

  

An object of the class Constraint_System is a system of 

constraints, i.e., a multiset of objects of the class 

Constraint. When inserting constraints in a system, space 

dimensions are automatically adjusted so that all the constraints 

in the system are defined on the same vector space. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Constraint_System, Variable 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: cs = Constraint_System( 5*x-2*y > 0 ) 

sage: cs.insert( 6*x<3*y ) 

sage: cs.insert( x >= 2*x-7*y ) 

sage: cs 

Constraint_System {5*x0-2*x1>0, -2*x0+x1>0, -x0+7*x1>=0} 

""" 

  

cdef PPL_Constraint_System *thisptr 

  

  

def __cinit__(self, arg=None): 

""" 

The Cython constructor. 

  

See :class:`Constraint_System` for documentation. 

  

TESTS:: 

  

sage: from sage.libs.ppl import Constraint_System 

sage: Constraint_System() 

Constraint_System {} 

""" 

if arg is None: 

self.thisptr = new PPL_Constraint_System() 

return 

if isinstance(arg, Constraint): 

g = <Constraint>arg 

self.thisptr = new PPL_Constraint_System(g.thisptr[0]) 

return 

if isinstance(arg, Constraint_System): 

gs = <Constraint_System>arg 

self.thisptr = new PPL_Constraint_System(gs.thisptr[0]) 

return 

if isinstance(arg, (list,tuple)): 

self.thisptr = new PPL_Constraint_System() 

for constraint in arg: 

self.insert(constraint) 

return 

raise ValueError('Cannot initialize with '+str(arg)+'.') 

  

  

def __dealloc__(self): 

""" 

The Cython destructor. 

""" 

del self.thisptr 

  

  

def space_dimension(self): 

r""" 

Return the dimension of the vector space enclosing ``self``. 

  

OUTPUT: 

  

Integer. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, Constraint_System 

sage: x = Variable(0) 

sage: cs = Constraint_System( x>0 ) 

sage: cs.space_dimension() 

1 

""" 

return self.thisptr.space_dimension() 

  

  

def has_equalities(self): 

r""" 

Tests whether ``self`` contains one or more equality constraints. 

  

OUTPUT: 

  

Boolean. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, Constraint_System 

sage: x = Variable(0) 

sage: cs = Constraint_System() 

sage: cs.insert( x>0 ) 

sage: cs.insert( x<0 ) 

sage: cs.has_equalities() 

False 

sage: cs.insert( x==0 ) 

sage: cs.has_equalities() 

True 

""" 

return self.thisptr.has_equalities() 

  

  

def has_strict_inequalities(self): 

r""" 

Tests whether ``self`` contains one or more strict inequality constraints. 

  

OUTPUT: 

  

Boolean. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, Constraint_System 

sage: x = Variable(0) 

sage: cs = Constraint_System() 

sage: cs.insert( x>=0 ) 

sage: cs.insert( x==-1 ) 

sage: cs.has_strict_inequalities() 

False 

sage: cs.insert( x>0 ) 

sage: cs.has_strict_inequalities() 

True 

""" 

return self.thisptr.has_strict_inequalities() 

  

  

def clear(self): 

r""" 

Removes all constraints from the constraint system and sets its 

space dimension to 0. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, Constraint_System 

sage: x = Variable(0) 

sage: cs = Constraint_System(x>0) 

sage: cs 

Constraint_System {x0>0} 

sage: cs.clear() 

sage: cs 

Constraint_System {} 

""" 

self.assert_mutable('The Constraint_System is not mutable!') 

self.thisptr.clear() 

  

  

def insert(self, Constraint c): 

""" 

Insert ``c`` into the constraint system. 

  

INPUT: 

  

- ``c`` -- a :class:`Constraint`. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, Constraint_System 

sage: x = Variable(0) 

sage: cs = Constraint_System() 

sage: cs.insert( x>0 ) 

sage: cs 

Constraint_System {x0>0} 

""" 

self.assert_mutable('The Constraint_System is not mutable!') 

self.thisptr.insert(c.thisptr[0]) 

  

  

def empty(self): 

""" 

Return ``True`` if and only if ``self`` has no constraints. 

  

OUTPUT: 

  

Boolean. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, Constraint_System, point 

sage: x = Variable(0) 

sage: cs = Constraint_System() 

sage: cs.empty() 

True 

sage: cs.insert( x>0 ) 

sage: cs.empty() 

False 

""" 

return self.thisptr.empty() 

  

  

def ascii_dump(self): 

r""" 

Write an ASCII dump to stderr. 

  

EXAMPLES:: 

  

sage: sage_cmd = 'from sage.libs.ppl import Constraint_System, Variable\n' 

sage: sage_cmd += 'x = Variable(0)\n' 

sage: sage_cmd += 'y = Variable(1)\n' 

sage: sage_cmd += 'cs = Constraint_System( 3*x > 2*y+1 )\n' 

sage: sage_cmd += 'cs.ascii_dump()\n' 

sage: from sage.tests.cmdline import test_executable 

sage: (out, err, ret) = test_executable(['sage', '-c', sage_cmd], timeout=100) # long time, indirect doctest 

sage: print(err) # long time 

topology NOT_NECESSARILY_CLOSED 

1 x 2 SPARSE (sorted) 

index_first_pending 1 

size 4 -1 3 -2 -1 > (NNC) 

""" 

self.thisptr.ascii_dump() 

  

  

def OK(self): 

""" 

Check if all the invariants are satisfied. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, Constraint_System 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: cs = Constraint_System( 3*x+2*y+1 <= 10 ) 

sage: cs.OK() 

True 

""" 

return self.thisptr.OK() 

  

  

def __len__(self): 

""" 

Return the number of constraints in the system. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, Constraint_System 

sage: x = Variable(0) 

sage: cs = Constraint_System( x>0 ) 

sage: cs.insert( x<1 ) 

sage: len(cs) 

2 

""" 

return sum([1 for c in self]) 

  

  

def __iter__(self): 

""" 

Iterate through the constraints of the system. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, Constraint_System 

sage: x = Variable(0) 

sage: cs = Constraint_System( x>0 ) 

sage: iter = cs.__iter__() 

sage: next(iter) 

x0>0 

sage: list(cs) # uses __iter__() internally 

[x0>0] 

""" 

return Constraint_System_iterator(self) 

  

  

def __getitem__(self, int k): 

""" 

Return the k-th constraint. 

  

The correct way to read the individual constraints is to 

iterate over the constraint system. This method is for 

convenience only. 

  

INPUT: 

  

- ``k`` -- integer. The index of the constraint. 

  

OUTPUT: 

  

The `k`-th constraint of the constraint system. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Variable, Constraint_System 

sage: x = Variable(0) 

sage: cs = Constraint_System( x>0 ) 

sage: cs.insert( x<1 ) 

sage: cs 

Constraint_System {x0>0, -x0+1>0} 

sage: cs[0] 

x0>0 

sage: cs[1] 

-x0+1>0 

""" 

if k < 0: 

raise IndexError('index must be nonnegative') 

iterator = iter(self) 

try: 

for i in range(k): 

next(iterator) 

except StopIteration: 

raise IndexError('index is past-the-end') 

return next(iterator) 

  

  

def __repr__(self): 

r""" 

Return a string representation of the constraint system. 

  

OUTPUT: 

  

A string. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Constraint_System, Variable 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: cs = Constraint_System([3*x+2*y+1 < 3, 0*x>x+1]) 

sage: cs.__repr__() 

'Constraint_System {-3*x0-2*x1+2>0, -x0-1>0}' 

""" 

s = 'Constraint_System {' 

s += ', '.join([ repr(c) for c in self ]) 

s += '}' 

return s 

  

  

def __reduce__(self): 

""" 

Pickle object. 

  

TESTS:: 

  

sage: from sage.libs.ppl import Constraint_System, Variable 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: cs = Constraint_System([3*x+2*y+1 < 3, 0*x>x+1]); cs 

Constraint_System {-3*x0-2*x1+2>0, -x0-1>0} 

sage: loads(dumps(cs)) 

Constraint_System {-3*x0-2*x1+2>0, -x0-1>0} 

""" 

return (Constraint_System, (tuple(self), )) 

  

  

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

### Constraint_System_iterator ##################### 

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

cdef extern from "ppl_shim.hh": 

ctypedef void* cs_iterator_ptr 

cdef cs_iterator_ptr init_cs_iterator(PPL_Constraint_System &cs) 

cdef PPL_Constraint next_cs_iterator(cs_iterator_ptr) 

cdef bint is_end_cs_iterator(PPL_Constraint_System &cs, cs_iterator_ptr csi_ptr) 

cdef void delete_cs_iterator(cs_iterator_ptr) 

  

  

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

cdef class Constraint_System_iterator(object): 

""" 

Wrapper for PPL's ``Constraint_System::const_iterator`` class. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Constraint_System, Variable, Constraint_System_iterator 

sage: x = Variable(0) 

sage: y = Variable(1) 

sage: cs = Constraint_System( 5*x < 2*y ) 

sage: cs.insert( 6*x-3*y==0 ) 

sage: cs.insert( x >= 2*x-7*y ) 

sage: next(Constraint_System_iterator(cs)) 

-5*x0+2*x1>0 

sage: list(cs) 

[-5*x0+2*x1>0, 2*x0-x1==0, -x0+7*x1>=0] 

""" 

  

cdef Constraint_System cs 

cdef cs_iterator_ptr csi_ptr 

  

  

def __cinit__(self, Constraint_System cs): 

""" 

The Cython constructor. 

  

See :class:`Constraint_System_iterator` for documentation. 

  

TESTS:: 

  

sage: from sage.libs.ppl import Constraint_System, Constraint_System_iterator 

sage: iter = Constraint_System_iterator( Constraint_System() ) # indirect doctest 

""" 

self.cs = cs 

self.csi_ptr = init_cs_iterator(cs.thisptr[0]) 

  

  

def __dealloc__(self): 

""" 

The Cython destructor. 

""" 

delete_cs_iterator(self.csi_ptr) 

  

  

def __next__(Constraint_System_iterator self): 

r""" 

The next iteration. 

  

OUTPUT: 

  

A :class:`Generator`. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Constraint_System, Variable, Constraint_System_iterator 

sage: x = Variable(0) 

sage: cs = Constraint_System( 5*x > 0 ) 

sage: next(Constraint_System_iterator(cs)) 

x0>0 

""" 

if is_end_cs_iterator((<Constraint_System>self.cs).thisptr[0], self.csi_ptr): 

raise StopIteration 

return _wrap_Constraint(next_cs_iterator(self.csi_ptr)) 

  

  

  

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

### Poly_Gen_Relation ############################## 

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

cdef _wrap_Poly_Gen_Relation(PPL_Poly_Gen_Relation relation): 

""" 

Wrap a C++ ``PPL_Poly_Gen_Relation`` into a Cython ``Poly_Gen_Relation``. 

""" 

cdef Poly_Gen_Relation rel = Poly_Gen_Relation(True) 

rel.thisptr = new PPL_Poly_Gen_Relation(relation) 

return rel 

  

  

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

cdef class Poly_Gen_Relation(object): 

r""" 

Wrapper for PPL's ``Poly_Con_Relation`` class. 

  

INPUT/OUTPUT: 

  

You must not construct :class:`Poly_Gen_Relation` objects 

manually. You will usually get them from 

:meth:`~sage.libs.ppl.Polyhedron.relation_with`. You can also get 

pre-defined relations from the class methods :meth:`nothing` and 

:meth:`subsumes`. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Poly_Gen_Relation 

sage: nothing = Poly_Gen_Relation.nothing(); nothing 

nothing 

sage: subsumes = Poly_Gen_Relation.subsumes(); subsumes 

subsumes 

sage: nothing.implies( subsumes ) 

False 

sage: subsumes.implies( nothing ) 

True 

""" 

  

cdef PPL_Poly_Gen_Relation *thisptr 

  

  

def __cinit__(self, do_not_construct_manually=False): 

""" 

The Cython constructor. 

  

See :class:`Poly_Gen_Relation` for documentation. 

  

TESTS:: 

  

sage: from sage.libs.ppl import Poly_Gen_Relation 

sage: Poly_Gen_Relation.nothing() 

nothing 

""" 

assert(do_not_construct_manually) 

self.thisptr = NULL 

  

  

def __dealloc__(self): 

""" 

The Cython destructor. 

""" 

assert self.thisptr!=NULL, 'Do not construct Poly_Gen_Relation objects manually!' 

del self.thisptr 

  

  

def implies(self, Poly_Gen_Relation y): 

r""" 

Test whether ``self`` implies ``y``. 

  

INPUT: 

  

- ``y`` -- a :class:`Poly_Gen_Relation`. 

  

OUTPUT: 

  

Boolean. ``True`` if and only if ``self`` implies ``y``. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Poly_Gen_Relation 

sage: nothing = Poly_Gen_Relation.nothing() 

sage: nothing.implies( nothing ) 

True 

""" 

return self.thisptr.implies(y.thisptr[0]) 

  

  

@classmethod 

def nothing(cls): 

r""" 

Return the assertion that says nothing. 

  

OUTPUT: 

  

A :class:`Poly_Gen_Relation`. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Poly_Gen_Relation 

sage: Poly_Gen_Relation.nothing() 

nothing 

""" 

return _wrap_Poly_Gen_Relation(PPL_Poly_Gen_Relation_nothing()) 

  

  

@classmethod 

def subsumes(cls): 

r""" 

Return the assertion "Adding the generator would not change 

the polyhedron". 

  

OUTPUT: 

  

A :class:`Poly_Gen_Relation`. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Poly_Gen_Relation 

sage: Poly_Gen_Relation.subsumes() 

subsumes 

""" 

return _wrap_Poly_Gen_Relation(PPL_Poly_Gen_Relation_subsumes()) 

  

  

def ascii_dump(self): 

r""" 

Write an ASCII dump to stderr. 

  

EXAMPLES:: 

  

sage: sage_cmd = 'from sage.libs.ppl import Poly_Gen_Relation\n' 

sage: sage_cmd += 'Poly_Gen_Relation.nothing().ascii_dump()\n' 

sage: from sage.tests.cmdline import test_executable 

sage: (out, err, ret) = test_executable(['sage', '-c', sage_cmd], timeout=100) # long time, indirect doctest 

sage: print(err) # long time 

NOTHING 

""" 

self.thisptr.ascii_dump() 

  

  

def OK(self, check_non_empty=False): 

""" 

Check if all the invariants are satisfied. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Poly_Gen_Relation 

sage: Poly_Gen_Relation.nothing().OK() 

True 

""" 

return self.thisptr.OK() 

  

  

def __repr__(self): 

r""" 

Return a string representation. 

  

OUTPUT: 

  

String. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Poly_Gen_Relation 

sage: Poly_Gen_Relation.nothing().__repr__() 

'nothing' 

""" 

if self.implies(Poly_Gen_Relation.subsumes()): 

return 'subsumes' 

else: 

return 'nothing' 

  

  

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

### Poly_Con_Relation ############################## 

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

cdef _wrap_Poly_Con_Relation(PPL_Poly_Con_Relation relation): 

""" 

Wrap a C++ ``PPL_Poly_Con_Relation`` into a Cython ``Poly_Con_Relation``. 

""" 

cdef Poly_Con_Relation rel = Poly_Con_Relation(True) 

rel.thisptr = new PPL_Poly_Con_Relation(relation) 

return rel 

  

  

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

cdef class Poly_Con_Relation(object): 

r""" 

Wrapper for PPL's ``Poly_Con_Relation`` class. 

  

INPUT/OUTPUT: 

  

You must not construct :class:`Poly_Con_Relation` objects 

manually. You will usually get them from 

:meth:`~sage.libs.ppl.Polyhedron.relation_with`. You can also get 

pre-defined relations from the class methods :meth:`nothing`, 

:meth:`is_disjoint`, :meth:`strictly_intersects`, 

:meth:`is_included`, and :meth:`saturates`. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Poly_Con_Relation 

sage: saturates = Poly_Con_Relation.saturates(); saturates 

saturates 

sage: is_included = Poly_Con_Relation.is_included(); is_included 

is_included 

sage: is_included.implies(saturates) 

False 

sage: saturates.implies(is_included) 

False 

sage: rels = [] 

sage: rels.append( Poly_Con_Relation.nothing() ) 

sage: rels.append( Poly_Con_Relation.is_disjoint() ) 

sage: rels.append( Poly_Con_Relation.strictly_intersects() ) 

sage: rels.append( Poly_Con_Relation.is_included() ) 

sage: rels.append( Poly_Con_Relation.saturates() ) 

sage: rels 

[nothing, is_disjoint, strictly_intersects, is_included, saturates] 

sage: from sage.matrix.constructor import matrix 

sage: m = matrix(5,5) 

sage: for i, rel_i in enumerate(rels): 

....: for j, rel_j in enumerate(rels): 

....: m[i,j] = rel_i.implies(rel_j) 

sage: m 

[1 0 0 0 0] 

[1 1 0 0 0] 

[1 0 1 0 0] 

[1 0 0 1 0] 

[1 0 0 0 1] 

""" 

  

cdef PPL_Poly_Con_Relation *thisptr 

  

  

def __cinit__(self, do_not_construct_manually=False): 

""" 

The Cython constructor. 

  

See :class:`Poly_Con_Relation` for documentation. 

  

TESTS:: 

  

sage: from sage.libs.ppl import Poly_Con_Relation 

sage: Poly_Con_Relation.nothing() 

nothing 

""" 

assert(do_not_construct_manually) 

self.thisptr = NULL 

  

  

def __dealloc__(self): 

""" 

The Cython destructor. 

""" 

assert self.thisptr!=NULL, 'Do not construct Poly_Con_Relation objects manually!' 

del self.thisptr 

  

  

def implies(self, Poly_Con_Relation y): 

r""" 

Test whether ``self`` implies ``y``. 

  

INPUT: 

  

- ``y`` -- a :class:`Poly_Con_Relation`. 

  

OUTPUT: 

  

Boolean. ``True`` if and only if ``self`` implies ``y``. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Poly_Con_Relation 

sage: nothing = Poly_Con_Relation.nothing() 

sage: nothing.implies( nothing ) 

True 

""" 

return self.thisptr.implies(y.thisptr[0]) 

  

  

@classmethod 

def nothing(cls): 

r""" 

Return the assertion that says nothing. 

  

OUTPUT: 

  

A :class:`Poly_Con_Relation`. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Poly_Con_Relation 

sage: Poly_Con_Relation.nothing() 

nothing 

""" 

return _wrap_Poly_Con_Relation(PPL_Poly_Con_Relation_nothing()) 

  

  

@classmethod 

def is_disjoint(cls): 

r""" 

Return the assertion "The polyhedron and the set of points 

satisfying the constraint are disjoint". 

  

OUTPUT: 

  

A :class:`Poly_Con_Relation`. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Poly_Con_Relation 

sage: Poly_Con_Relation.is_disjoint() 

is_disjoint 

""" 

return _wrap_Poly_Con_Relation(PPL_Poly_Con_Relation_is_disjoint()) 

  

  

@classmethod 

def strictly_intersects(cls): 

r""" 

Return the assertion "The polyhedron intersects the set of 

points satisfying the constraint, but it is not included in 

it". 

  

OUTPUT: 

  

A :class:`Poly_Con_Relation`. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Poly_Con_Relation 

sage: Poly_Con_Relation.strictly_intersects() 

strictly_intersects 

""" 

return _wrap_Poly_Con_Relation(PPL_Poly_Con_Relation_strictly_intersects()) 

  

  

@classmethod 

def is_included(cls): 

r""" 

Return the assertion "The polyhedron is included in the set of 

points satisfying the constraint". 

  

OUTPUT: 

  

A :class:`Poly_Con_Relation`. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Poly_Con_Relation 

sage: Poly_Con_Relation.is_included() 

is_included 

""" 

return _wrap_Poly_Con_Relation(PPL_Poly_Con_Relation_is_included()) 

  

  

@classmethod 

def saturates(cls): 

r""" 

Return the assertion "". 

  

OUTPUT: 

  

A :class:`Poly_Con_Relation`. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Poly_Con_Relation 

sage: Poly_Con_Relation.saturates() 

saturates 

""" 

return _wrap_Poly_Con_Relation(PPL_Poly_Con_Relation_saturates()) 

  

  

def ascii_dump(self): 

r""" 

Write an ASCII dump to stderr. 

  

EXAMPLES:: 

  

sage: sage_cmd = 'from sage.libs.ppl import Poly_Con_Relation\n' 

sage: sage_cmd += 'Poly_Con_Relation.nothing().ascii_dump()\n' 

sage: from sage.tests.cmdline import test_executable 

sage: (out, err, ret) = test_executable(['sage', '-c', sage_cmd], timeout=100) # long time, indirect doctest 

sage: print(err) # long time 

NOTHING 

""" 

self.thisptr.ascii_dump() 

  

  

def OK(self, check_non_empty=False): 

""" 

Check if all the invariants are satisfied. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Poly_Con_Relation 

sage: Poly_Con_Relation.nothing().OK() 

True 

""" 

return self.thisptr.OK() 

  

  

def __repr__(self): 

r""" 

Return a string representation. 

  

OUTPUT: 

  

String. 

  

EXAMPLES:: 

  

sage: from sage.libs.ppl import Poly_Con_Relation 

sage: Poly_Con_Relation.nothing().__repr__() 

'nothing' 

""" 

rel = [] 

if self.implies(Poly_Con_Relation.is_disjoint()): 

rel.append('is_disjoint') 

if self.implies(Poly_Con_Relation.strictly_intersects()): 

rel.append('strictly_intersects') 

if self.implies(Poly_Con_Relation.is_included()): 

rel.append('is_included') 

if self.implies(Poly_Con_Relation.saturates()): 

rel.append('saturates') 

  

if len(rel)>0: 

return ', '.join(rel) 

else: 

return 'nothing' 

  

  

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

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

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

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