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

r""" 

(Asymptotic) Growth Groups 

 

This module provides support for (asymptotic) growth groups. 

 

Such groups are equipped with a partial order: the elements can be 

seen as functions, and the behavior as their argument (or arguments) 

gets large (tend to `\infty`) is compared. 

 

Growth groups are used for the calculations done in the 

:doc:`asymptotic ring <asymptotic_ring>`. There, take a look at the 

:ref:`informal definition <asymptotic_ring_definition>`, where 

examples of growth groups and elements are given as well. 

 

 

.. _growth_group_description: 

 

Description of Growth Groups 

============================ 

 

Many growth groups can be described by a string, which can also be used to 

create them. For example, the string ``'x^QQ * log(x)^ZZ * QQ^y * y^QQ'`` 

represents a growth group with the following properties: 

 

- It is a growth group in the two variables `x` and `y`. 

 

- Its elements are of the form 

 

.. MATH:: 

 

x^r \cdot \log(x)^s \cdot a^y \cdot y^q 

 

for `r\in\QQ`, `s\in\ZZ`, `a\in\QQ` and `q\in\QQ`. 

 

- The order is with respect to `x\to\infty` and `y\to\infty` independently 

of each other. 

 

- To compare such elements, they are split into parts belonging to 

only one variable. In the example above, 

 

.. MATH:: 

 

x^{r_1} \cdot \log(x)^{s_1} \leq x^{r_2} \cdot \log(x)^{s_2} 

 

if `(r_1, s_1) \leq (r_2, s_2)` lexicographically. This reflects the fact 

that elements `x^r` are larger than elements `\log(x)^s` as `x\to\infty`. 

The factors belonging to the variable `y` are compared analogously. 

 

The results of these comparisons are then put together using the 

:wikipedia:`product order <Product_order>`, i.e., `\leq` if each component 

satisfies `\leq`. 

 

 

Each description string consists of ordered factors---yes, this means 

``*`` is noncommutative---of strings describing "elementary" growth 

groups (see the examples below). As stated in the example above, these 

factors are split by their variable; factors with the same variable are 

grouped. Reading such factors from left to right determines the order: 

Comparing elements of two factors (growth groups) `L` and `R`, then all 

elements of `L` are considered to be larger than each element of `R`. 

 

 

.. _growth_group_creating: 

 

Creating a Growth Group 

======================= 

 

For many purposes the factory ``GrowthGroup`` (see 

:class:`GrowthGroupFactory`) is the most convenient way to generate a 

growth group. 

:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup 

 

Here are some examples:: 

 

sage: GrowthGroup('z^ZZ') 

Growth Group z^ZZ 

sage: M = GrowthGroup('z^QQ'); M 

Growth Group z^QQ 

 

Each of these two generated groups is a :class:`MonomialGrowthGroup`, 

whose elements are powers of a fixed symbol (above ``'z'``). 

For the order of the elements it is assumed that `z\to\infty`. 

 

.. NOTE:: 

 

Growth groups where the variable tend to some value distinct from 

`\infty` are not yet implemented. 

 

To create elements of `M`, a generator can be used:: 

 

sage: z = M.gen() 

sage: z^(3/5) 

z^(3/5) 

 

Strings can also be parsed:: 

 

sage: M('z^7') 

z^7 

 

Similarly, we can construct logarithmic factors by:: 

 

sage: GrowthGroup('log(z)^QQ') 

Growth Group log(z)^QQ 

 

which again creates a 

:class:`MonomialGrowthGroup`. An :class:`ExponentialGrowthGroup` is generated in the same way. Our factory gives 

:: 

 

sage: E = GrowthGroup('QQ^z'); E 

Growth Group QQ^z 

 

and a typical element looks like this:: 

 

sage: E.an_element() 

(1/2)^z 

 

More complex groups are created in a similar fashion. For example 

:: 

 

sage: C = GrowthGroup('QQ^z * z^QQ * log(z)^QQ'); C 

Growth Group QQ^z * z^QQ * log(z)^QQ 

 

This contains elements of the form 

:: 

 

sage: C.an_element() 

(1/2)^z*z^(1/2)*log(z)^(1/2) 

 

The group `C` itself is a Cartesian product; to be precise a 

:class:`~sage.rings.asymptotic.growth_group_cartesian.UnivariateProduct`. We 

can see its factors:: 

 

sage: C.cartesian_factors() 

(Growth Group QQ^z, Growth Group z^QQ, Growth Group log(z)^QQ) 

 

Multivariate constructions are also possible:: 

 

sage: GrowthGroup('x^QQ * y^QQ') 

Growth Group x^QQ * y^QQ 

 

This gives a 

:class:`~sage.rings.asymptotic.growth_group_cartesian.MultivariateProduct`. 

 

Both these Cartesian products are derived from the class 

:class:`~sage.rings.asymptotic.growth_group_cartesian.GenericProduct`. Moreover 

all growth groups have the abstract base class 

:class:`GenericGrowthGroup` in common. 

 

Some Examples 

^^^^^^^^^^^^^ 

 

:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup 

sage: G_x = GrowthGroup('x^ZZ'); G_x 

Growth Group x^ZZ 

sage: G_xy = GrowthGroup('x^ZZ * y^ZZ'); G_xy 

Growth Group x^ZZ * y^ZZ 

sage: G_xy.an_element() 

x*y 

sage: x = G_xy('x'); y = G_xy('y') 

sage: x^2 

x^2 

sage: elem = x^21*y^21; elem^2 

x^42*y^42 

 

A monomial growth group itself is totally ordered, all elements 

are comparable. However, this does **not** hold for Cartesian 

products:: 

 

sage: e1 = x^2*y; e2 = x*y^2 

sage: e1 <= e2 or e2 <= e1 

False 

 

In terms of uniqueness, we have the following behaviour:: 

 

sage: GrowthGroup('x^ZZ * y^ZZ') is GrowthGroup('y^ZZ * x^ZZ') 

True 

 

The above is ``True`` since the order of the factors does not play a role here; they use different variables. But when using the same variable, it plays a role:: 

 

sage: GrowthGroup('x^ZZ * log(x)^ZZ') is GrowthGroup('log(x)^ZZ * x^ZZ') 

False 

 

In this case the components are ordered lexicographically, which 

means that in the second growth group, ``log(x)`` is assumed to 

grow faster than ``x`` (which is nonsense, mathematically). See 

:class:`CartesianProduct <sage.rings.asymptotic.growth_group_cartesian.CartesianProductFactory>` 

for more details or see :ref:`above <growth_group_description>` 

for a more extensive description. 

 

Short notation also allows the construction of more complicated  

growth groups:: 

 

sage: G = GrowthGroup('QQ^x * x^ZZ * log(x)^QQ * y^QQ') 

sage: G.an_element() 

(1/2)^x*x*log(x)^(1/2)*y^(1/2) 

sage: x, y = var('x y') 

sage: G(2^x * log(x) * y^(1/2)) * G(x^(-5) * 5^x * y^(1/3)) 

10^x*x^(-5)*log(x)*y^(5/6) 

 

AUTHORS: 

 

- Benjamin Hackl (2015) 

- Daniel Krenn (2015) 

- Clemens Heuberger (2016) 

 

ACKNOWLEDGEMENT: 

 

- Benjamin Hackl, Clemens Heuberger and Daniel Krenn are supported by the 

Austrian Science Fund (FWF): P 24644-N26. 

 

- Benjamin Hackl is supported by the Google Summer of Code 2015. 

 

Classes and Methods 

=================== 

""" 

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

# Copyright (C) 2014--2015 Benjamin Hackl <benjamin.hackl@aau.at> 

# 2014--2015 Daniel Krenn <dev@danielkrenn.at> 

# 

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

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

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

# (at your option) any later version. 

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

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

from __future__ import absolute_import 

 

from sage.misc.lazy_import import lazy_import 

lazy_import('sage.rings.asymptotic.growth_group_cartesian', 'CartesianProductGrowthGroups') 

 

from sage.categories.pushout import ConstructionFunctor 

from sage.structure.element import MultiplicativeGroupElement 

from sage.structure.factory import UniqueFactory 

from sage.structure.parent import Parent 

from sage.structure.sage_object import SageObject 

from sage.structure.unique_representation import (CachedRepresentation, 

UniqueRepresentation) 

from sage.structure.richcmp import richcmp_by_eq_and_lt 

 

 

class Variable(CachedRepresentation, SageObject): 

r""" 

A class managing the variable of a growth group. 

 

INPUT: 

 

- ``var`` -- an object whose representation string is used as the 

variable. It has to be a valid Python identifier. ``var`` can 

also be a tuple (or other iterable) of such objects. 

 

- ``repr`` -- (default: ``None``) if specified, then this string 

will be displayed instead of ``var``. Use this to get 

e.g. ``log(x)^ZZ``: ``var`` is then used to specify the variable `x`. 

 

- ``latex_name`` -- (default: ``None``) if specified, then this string 

will be used as LaTeX-representation of ``var``. 

 

- ``ignore`` -- (default: ``None``) a tuple (or other iterable) 

of strings which are not variables. 

 

TESTS:: 

 

sage: from sage.rings.asymptotic.growth_group import Variable 

sage: v = Variable('x'); repr(v), v.variable_names() 

('x', ('x',)) 

sage: v = Variable('x1'); repr(v), v.variable_names() 

('x1', ('x1',)) 

sage: v = Variable('x_42'); repr(v), v.variable_names() 

('x_42', ('x_42',)) 

sage: v = Variable(' x'); repr(v), v.variable_names() 

('x', ('x',)) 

sage: v = Variable('x '); repr(v), v.variable_names() 

('x', ('x',)) 

sage: v = Variable(''); repr(v), v.variable_names() 

('', ()) 

 

:: 

 

sage: v = Variable(('x', 'y')); repr(v), v.variable_names() 

('x, y', ('x', 'y')) 

sage: v = Variable(('x', 'log(y)')); repr(v), v.variable_names() 

('x, log(y)', ('x', 'y')) 

sage: v = Variable(('x', 'log(x)')); repr(v), v.variable_names() 

Traceback (most recent call last): 

... 

ValueError: Variable names ('x', 'x') are not pairwise distinct. 

 

:: 

 

sage: v = Variable('log(x)'); repr(v), v.variable_names() 

('log(x)', ('x',)) 

sage: v = Variable('log(log(x))'); repr(v), v.variable_names() 

('log(log(x))', ('x',)) 

 

:: 

 

sage: v = Variable('x', repr='log(x)'); repr(v), v.variable_names() 

('log(x)', ('x',)) 

 

:: 

 

sage: v = Variable('e^x', ignore=('e',)); repr(v), v.variable_names() 

('e^x', ('x',)) 

 

:: 

 

sage: v = Variable('(e^n)', ignore=('e',)); repr(v), v.variable_names() 

('e^n', ('n',)) 

sage: v = Variable('(e^(n*log(n)))', ignore=('e',)); repr(v), v.variable_names() 

('e^(n*log(n))', ('n',)) 

""" 

def __init__(self, var, repr=None, latex_name=None, ignore=None): 

r""" 

See :class:`Variable` for details. 

 

TESTS:: 

 

sage: from sage.rings.asymptotic.growth_group import Variable 

sage: Variable('blub') 

blub 

sage: Variable('blub') is Variable('blub') 

True 

 

:: 

 

sage: Variable('(:-)') 

Traceback (most recent call last): 

... 

TypeError: Malformed expression: : !!! - 

sage: Variable('(:-)', repr='icecream') 

Traceback (most recent call last): 

... 

ValueError: ':-' is not a valid name for a variable. 

""" 

from sage.symbolic.ring import isidentifier 

from .misc import split_str_by_op 

 

if not isinstance(var, (list, tuple)): 

var = (var,) 

var = tuple(''.join(split_str_by_op(str(v), None)) for v in var) # we strip off parentheses 

 

if ignore is None: 

ignore = tuple() 

 

from sage.misc.latex import latex 

from sage.symbolic.ring import SR 

 

if repr is None: 

var_bases = tuple(i for i in sum(iter( 

self.extract_variable_names(v) 

if not isidentifier(v) else (v,) 

for v in var), tuple()) if i not in ignore) 

var_repr = ', '.join(var) 

if latex_name is None: 

latex_name = ', '.join(latex(SR(v)) for v in var if v) 

else: 

for v in var: 

if not isidentifier(v): 

raise ValueError("'%s' is not a valid name for a variable." % (v,)) 

var_bases = var 

var_repr = str(repr).strip() 

if latex_name is None: 

try: 

latex_name = latex(SR(var_repr)) 

except TypeError: 

latex_name = latex(var_repr) 

 

if len(var_bases) != len(set(var_bases)): 

raise ValueError('Variable names %s are not pairwise distinct.' % 

(var_bases,)) 

 

 

self.var_bases = var_bases 

self.var_repr = var_repr 

 

self.latex_name = latex_name 

 

def __hash__(self): 

r""" 

Return the hash of this variable. 

 

TESTS:: 

 

sage: from sage.rings.asymptotic.growth_group import Variable 

sage: hash(Variable('blub')) # random 

-123456789 

""" 

return hash((self.var_repr,) + self.var_bases) 

 

def __eq__(self, other): 

r""" 

Compare whether this variable equals ``other``. 

 

INPUT: 

 

- ``other`` -- another variable. 

 

OUTPUT: 

 

A boolean. 

 

TESTS:: 

 

sage: from sage.rings.asymptotic.growth_group import Variable 

sage: Variable('x') == Variable('x') 

True 

sage: Variable('x') == Variable('y') 

False 

""" 

return self.var_repr == other.var_repr and self.var_bases == other.var_bases 

 

def __ne__(self, other): 

r""" 

Return whether this variable does not equal ``other``. 

 

INPUT: 

 

- ``other`` -- another variable. 

 

OUTPUT: 

 

A boolean. 

 

TESTS:: 

 

sage: from sage.rings.asymptotic.growth_group import Variable 

sage: Variable('x') != Variable('x') 

False 

sage: Variable('x') != Variable('y') 

True 

""" 

return not self == other 

 

def _repr_(self): 

r""" 

Return a representation string of this variable. 

 

OUTPUT: 

 

A string. 

 

TESTS:: 

 

sage: from sage.rings.asymptotic.growth_group import Variable 

sage: Variable('blub') # indirect doctest 

blub 

""" 

return self.var_repr 

 

def _latex_(self): 

r""" 

Return a LaTeX-representation string of this variable. 

 

OUTPUT: 

 

A string. 

 

TESTS:: 

 

sage: from sage.rings.asymptotic.growth_group import Variable 

sage: latex(Variable('x')) # indirect doctest 

x 

sage: latex(Variable('x1')) # indirect doctest 

x_{1} 

sage: latex(Variable('x_1')) # indirect doctest 

x_{1} 

""" 

return self.latex_name 

 

def variable_names(self): 

r""" 

Return the names of the variables. 

 

OUTPUT: 

 

A tuple of strings. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.growth_group import Variable 

sage: Variable('x').variable_names() 

('x',) 

sage: Variable('log(x)').variable_names() 

('x',) 

""" 

return self.var_bases 

 

def is_monomial(self): 

r""" 

Return whether this is a monomial variable. 

 

OUTPUT: 

 

A boolean. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.growth_group import Variable 

sage: Variable('x').is_monomial() 

True 

sage: Variable('log(x)').is_monomial() 

False 

""" 

return len(self.var_bases) == 1 and self.var_bases[0] == self.var_repr 

 

@staticmethod 

def extract_variable_names(s): 

r""" 

Determine the name of the variable for the given string. 

 

INPUT: 

 

- ``s`` -- a string. 

 

OUTPUT: 

 

A tuple of strings. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.growth_group import Variable 

sage: Variable.extract_variable_names('') 

() 

sage: Variable.extract_variable_names('x') 

('x',) 

sage: Variable.extract_variable_names('exp(x)') 

('x',) 

sage: Variable.extract_variable_names('sin(cos(ln(x)))') 

('x',) 

 

:: 

 

sage: Variable.extract_variable_names('log(77w)') 

('w',) 

sage: Variable.extract_variable_names('log(x') 

Traceback (most recent call last): 

.... 

TypeError: Bad function call: log(x !!! 

sage: Variable.extract_variable_names('x)') 

Traceback (most recent call last): 

.... 

TypeError: Malformed expression: x) !!! 

sage: Variable.extract_variable_names('log)x(') 

Traceback (most recent call last): 

.... 

TypeError: Malformed expression: log) !!! x( 

sage: Variable.extract_variable_names('log(x)+y') 

('x', 'y') 

sage: Variable.extract_variable_names('icecream(summer)') 

('summer',) 

 

:: 

 

sage: Variable.extract_variable_names('a + b') 

('a', 'b') 

sage: Variable.extract_variable_names('a+b') 

('a', 'b') 

sage: Variable.extract_variable_names('a +b') 

('a', 'b') 

sage: Variable.extract_variable_names('+a') 

('a',) 

sage: Variable.extract_variable_names('a+') 

Traceback (most recent call last): 

... 

TypeError: Malformed expression: a+ !!! 

sage: Variable.extract_variable_names('b!') 

('b',) 

sage: Variable.extract_variable_names('-a') 

('a',) 

sage: Variable.extract_variable_names('a*b') 

('a', 'b') 

sage: Variable.extract_variable_names('2^q') 

('q',) 

sage: Variable.extract_variable_names('77') 

() 

 

:: 

 

sage: Variable.extract_variable_names('a + (b + c) + d') 

('a', 'b', 'c', 'd') 

""" 

from sage.symbolic.ring import SR 

if s == '': 

return () 

return tuple(str(s) for s in SR(s).variables()) 

 

def _substitute_(self, rules): 

r""" 

Substitute the given ``rules`` in this variable. 

 

INPUT: 

 

- ``rules`` -- a dictionary. 

 

OUTPUT: 

 

An object. 

 

TESTS:: 

 

sage: from sage.rings.asymptotic.growth_group import Variable 

sage: Variable('x^2')._substitute_({'x': SR.var('z')}) 

z^2 

sage: _.parent() 

Symbolic Ring 

 

:: 

 

sage: Variable('1/x')._substitute_({'x': 'z'}) 

Traceback (most recent call last): 

... 

TypeError: Cannot substitute in 1/x in 

<class 'sage.rings.asymptotic.growth_group.Variable'>. 

> *previous* TypeError: unsupported operand type(s) for /: 

'sage.rings.integer.Integer' and 'str' 

sage: Variable('1/x')._substitute_({'x': 0}) 

Traceback (most recent call last): 

... 

ZeroDivisionError: Cannot substitute in 1/x in 

<class 'sage.rings.asymptotic.growth_group.Variable'>. 

> *previous* ZeroDivisionError: rational division by zero 

""" 

from sage.misc.sage_eval import sage_eval 

try: 

return sage_eval(self.var_repr, locals=rules) 

except (ArithmeticError, TypeError, ValueError) as e: 

from .misc import substitute_raise_exception 

substitute_raise_exception(self, e) 

 

 

# The following function is used in the classes GenericGrowthElement and 

# GenericProduct.Element as a method. 

def _is_lt_one_(self): 

r""" 

Return whether this element is less than `1`. 

 

INPUT: 

 

Nothing. 

 

OUTPUT: 

 

A boolean. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup 

sage: G = GrowthGroup('x^ZZ'); x = G(x) 

sage: (x^42).is_lt_one() # indirect doctest 

False 

sage: (x^(-42)).is_lt_one() # indirect doctest 

True 

""" 

one = self.parent().one() 

return self <= one and self != one 

 

 

# The following function is used in the classes GenericGrowthElement and 

# GenericProduct.Element as a method. 

def _log_(self, base=None): 

r""" 

Return the logarithm of this element. 

 

INPUT: 

 

- ``base`` -- the base of the logarithm. If ``None`` 

(default value) is used, the natural logarithm is taken. 

 

OUTPUT: 

 

A growth element. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup 

sage: G = GrowthGroup('x^ZZ * log(x)^ZZ') 

sage: x, = G.gens_monomial() 

sage: log(x) # indirect doctest 

log(x) 

sage: log(x^5) # indirect doctest 

Traceback (most recent call last): 

... 

ArithmeticError: When calculating log(x^5) a factor 5 != 1 appeared, 

which is not contained in Growth Group x^ZZ * log(x)^ZZ. 

 

:: 

 

sage: G = GrowthGroup('QQ^x * x^ZZ') 

sage: x, = G.gens_monomial() 

sage: el = x.rpow(2); el 

2^x 

sage: log(el) # indirect doctest 

Traceback (most recent call last): 

... 

ArithmeticError: When calculating log(2^x) a factor log(2) != 1 

appeared, which is not contained in Growth Group QQ^x * x^ZZ. 

sage: log(el, base=2) # indirect doctest 

x 

 

:: 

 

sage: from sage.rings.asymptotic.growth_group import GenericGrowthGroup 

sage: x = GenericGrowthGroup(ZZ).an_element() 

sage: log(x) # indirect doctest 

Traceback (most recent call last): 

... 

NotImplementedError: Cannot determine logarithmized factorization of 

GenericGrowthElement(1) in abstract base class. 

 

:: 

 

sage: x = GrowthGroup('x^ZZ').an_element() 

sage: log(x) # indirect doctest 

Traceback (most recent call last): 

... 

ArithmeticError: Cannot build log(x) since log(x) is not in 

Growth Group x^ZZ. 

 

TESTS:: 

 

sage: G = GrowthGroup("(e^x)^QQ * x^ZZ") 

sage: x, = G.gens_monomial() 

sage: log(exp(x)) # indirect doctest 

x 

sage: G.one().log() # indirect doctest 

Traceback (most recent call last): 

... 

ArithmeticError: log(1) is zero, which is not contained in 

Growth Group (e^x)^QQ * x^ZZ. 

 

:: 

 

sage: G = GrowthGroup("(e^x)^ZZ * x^ZZ") 

sage: x, = G.gens_monomial() 

sage: log(exp(x)) # indirect doctest 

x 

sage: G.one().log() # indirect doctest 

Traceback (most recent call last): 

... 

ArithmeticError: log(1) is zero, which is not contained in 

Growth Group (e^x)^ZZ * x^ZZ. 

 

:: 

 

sage: G = GrowthGroup('QQ^x * x^ZZ * log(x)^ZZ * y^ZZ * log(y)^ZZ') 

sage: x, y = G.gens_monomial() 

sage: (x * y).log() # indirect doctest 

Traceback (most recent call last): 

... 

ArithmeticError: Calculating log(x*y) results in a sum, 

which is not contained in 

Growth Group QQ^x * x^ZZ * log(x)^ZZ * y^ZZ * log(y)^ZZ. 

""" 

from .misc import log_string 

 

log_factor = self.log_factor(base=base) 

if not log_factor: 

raise ArithmeticError('%s is zero, ' 

'which is not contained in %s.' % 

(log_string(self, base), self.parent())) 

 

if len(log_factor) != 1: 

raise ArithmeticError('Calculating %s results in a sum, ' 

'which is not contained in %s.' % 

(log_string(self, base), self.parent())) 

g, c = log_factor[0] 

if c != 1: 

raise ArithmeticError('When calculating %s a factor %s != 1 ' 

'appeared, which is not contained in %s.' % 

(log_string(self, base), c, self.parent())) 

return g 

 

 

# The following function is used in the classes GenericGrowthElement and 

# GenericProduct.Element as a method. 

def _log_factor_(self, base=None): 

r""" 

Return the logarithm of the factorization of this 

element. 

 

INPUT: 

 

- ``base`` -- the base of the logarithm. If ``None`` 

(default value) is used, the natural logarithm is taken. 

 

OUTPUT: 

 

A tuple of pairs, where the first entry is a growth 

element and the second a multiplicative coefficient. 

 

ALGORITHM: 

 

This function factors the given element and calculates 

the logarithm of each of these factors. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup 

sage: G = GrowthGroup('QQ^x * x^ZZ * log(x)^ZZ * y^ZZ * log(y)^ZZ') 

sage: x, y = G.gens_monomial() 

sage: (x * y).log_factor() # indirect doctest 

((log(x), 1), (log(y), 1)) 

sage: (x^123).log_factor() # indirect doctest 

((log(x), 123),) 

sage: (G('2^x') * x^2).log_factor(base=2) # indirect doctest 

((x, 1), (log(x), 2/log(2))) 

 

:: 

 

sage: G(1).log_factor() 

() 

 

:: 

 

sage: log(x).log_factor() # indirect doctest 

Traceback (most recent call last): 

... 

ArithmeticError: Cannot build log(log(x)) since log(log(x)) is 

not in Growth Group QQ^x * x^ZZ * log(x)^ZZ * y^ZZ * log(y)^ZZ. 

 

.. SEEALSO:: 

 

:meth:`~sage.rings.asymptotic.growth_group.GenericGrowthElement.factors`, 

:meth:`~sage.rings.asymptotic.growth_group.GenericGrowthElement.log`. 

 

TESTS:: 

 

sage: G = GrowthGroup("(e^x)^ZZ * x^ZZ * log(x)^ZZ") 

sage: x, = G.gens_monomial() 

sage: (exp(x) * x).log_factor() # indirect doctest 

((x, 1), (log(x), 1)) 

""" 

log_factor = self._log_factor_(base=base) 

 

for g, c in log_factor: 

if hasattr(g, 'parent') and \ 

isinstance(g.parent(), GenericGrowthGroup): 

continue 

from .misc import log_string 

raise ArithmeticError('Cannot build %s since %s ' 

'is not in %s.' % (log_string(self, base), 

g, self.parent())) 

 

return log_factor 

 

 

# The following function is used in the classes GenericGrowthElement and 

# GenericProduct.Element as a method. 

def _rpow_(self, base): 

r""" 

Calculate the power of ``base`` to this element. 

 

INPUT: 

 

- ``base`` -- an element. 

 

OUTPUT: 

 

A growth element. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup 

sage: G = GrowthGroup('QQ^x * x^ZZ') 

sage: x = G('x') 

sage: x.rpow(2) # indirect doctest 

2^x 

sage: x.rpow(1/2) # indirect doctest 

(1/2)^x 

 

:: 

 

sage: x.rpow(0) # indirect doctest 

Traceback (most recent call last): 

... 

ValueError: 0 is not an allowed base for calculating the power to x. 

sage: (x^2).rpow(2) # indirect doctest 

Traceback (most recent call last): 

... 

ArithmeticError: Cannot construct 2^(x^2) in Growth Group QQ^x * x^ZZ 

> *previous* TypeError: unsupported operand parent(s) for *: 

'Growth Group QQ^x * x^ZZ' and 'Growth Group ZZ^(x^2)' 

 

:: 

 

sage: G = GrowthGroup('QQ^(x*log(x)) * x^ZZ * log(x)^ZZ') 

sage: x = G('x') 

sage: (x * log(x)).rpow(2) # indirect doctest 

2^(x*log(x)) 

 

:: 

 

sage: n = GrowthGroup('QQ^n * n^QQ')('n') 

sage: n.rpow(2) 

2^n 

sage: _.parent() 

Growth Group QQ^n * n^QQ 

""" 

if base == 0: 

raise ValueError('%s is not an allowed base for calculating the ' 

'power to %s.' % (base, self)) 

 

var = str(self) 

 

try: 

element = self._rpow_element_(base) 

except ValueError: 

if base == 'e': 

from sage.rings.integer_ring import ZZ 

from .misc import repr_op 

M = MonomialGrowthGroup(ZZ, repr_op('e', '^', var), 

ignore_variables=('e',)) 

element = M(raw_element=ZZ(1)) 

else: 

E = ExponentialGrowthGroup(base.parent(), var) 

element = E(raw_element=base) 

 

try: 

return self.parent().one() * element 

except (TypeError, ValueError) as e: 

from .misc import combine_exceptions, repr_op 

raise combine_exceptions( 

ArithmeticError('Cannot construct %s in %s' % 

(repr_op(base, '^', var), self.parent())), e) 

 

 

class GenericGrowthElement(MultiplicativeGroupElement): 

r""" 

A basic implementation of a generic growth element. 

 

Growth elements form a group by multiplication, and (some of) the 

elements can be compared to each other, i.e., all elements form a 

poset. 

 

INPUT: 

 

- ``parent`` -- a :class:`GenericGrowthGroup`. 

 

- ``raw_element`` -- an element from the base of the parent. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.growth_group import (GenericGrowthGroup, 

....: GenericGrowthElement) 

sage: G = GenericGrowthGroup(ZZ) 

sage: g = GenericGrowthElement(G, 42); g 

GenericGrowthElement(42) 

sage: g.parent() 

Growth Group Generic(ZZ) 

sage: G(raw_element=42) == g 

True 

""" 

 

def __init__(self, parent, raw_element): 

r""" 

See :class:`GenericGrowthElement` for more information. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.growth_group import GenericGrowthGroup 

sage: G = GenericGrowthGroup(ZZ) 

sage: G(raw_element=42) 

GenericGrowthElement(42) 

 

TESTS:: 

 

sage: G(raw_element=42).category() 

Category of elements of Growth Group Generic(ZZ) 

 

:: 

 

sage: G = GenericGrowthGroup(ZZ) 

sage: G(raw_element=42).category() 

Category of elements of Growth Group Generic(ZZ) 

 

:: 

 

sage: from sage.rings.asymptotic.growth_group import GenericGrowthElement 

sage: GenericGrowthElement(None, 0) 

Traceback (most recent call last): 

... 

ValueError: The parent must be provided 

""" 

if parent is None: 

raise ValueError('The parent must be provided') 

super(GenericGrowthElement, self).__init__(parent=parent) 

 

self._raw_element_ = parent.base()(raw_element) 

 

def _repr_(self): 

r""" 

A representation string for this generic element. 

 

INPUT: 

 

Nothing. 

 

OUTPUT: 

 

A string. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.growth_group import GenericGrowthGroup 

sage: G = GenericGrowthGroup(ZZ) 

sage: G(raw_element=42) # indirect doctest 

GenericGrowthElement(42) 

sage: H = GenericGrowthGroup(ZZ, 'h') 

sage: H(raw_element=42) # indirect doctest 

GenericGrowthElement(42, h) 

""" 

vars = ', '.join(self.parent()._var_.variable_names()) 

if vars: 

vars = ', ' + vars 

return 'GenericGrowthElement(%s%s)' % (self._raw_element_, vars) 

 

def __hash__(self): 

r""" 

Return the hash of this element. 

 

INPUT: 

 

Nothing. 

 

OUTPUT: 

 

An integer. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.growth_group import GenericGrowthGroup 

sage: G = GenericGrowthGroup(ZZ); 

sage: hash(G(raw_element=42)) # random 

5656565656565656 

""" 

return hash((self.parent(), self._raw_element_)) 

 

def _mul_(self, other): 

r""" 

Abstract multiplication method for generic elements. 

 

INPUT: 

 

- ``other`` -- a :class:`GenericGrowthElement`. 

 

OUTPUT: 

 

A :class:`GenericGrowthElement` representing the product with 

``other``. 

 

.. NOTE:: 

 

Inherited classes must override this. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.growth_group import GenericGrowthGroup 

sage: G = GenericGrowthGroup(ZZ) 

sage: g = G.an_element() 

sage: g*g 

Traceback (most recent call last): 

... 

NotImplementedError: Only implemented in concrete realizations. 

""" 

raise NotImplementedError('Only implemented in concrete realizations.') 

 

def __invert__(self): 

r""" 

Return the inverse of this growth element. 

 

OUTPUT: 

 

An instance of :class:`GenericGrowthElement`. 

 

TESTS:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup 

sage: from sage.rings.asymptotic.growth_group import GenericGrowthGroup 

sage: G = GenericGrowthGroup(ZZ) 

sage: ~G.an_element() 

Traceback (most recent call last): 

... 

NotImplementedError: Inversion of GenericGrowthElement(1) not implemented 

(in this abstract method). 

sage: G.an_element()^7 

Traceback (most recent call last): 

... 

NotImplementedError: Only implemented in concrete realizations. 

sage: P = GrowthGroup('x^ZZ') 

sage: ~P.an_element() 

x^(-1) 

""" 

raise NotImplementedError('Inversion of %s not implemented ' 

'(in this abstract method).' % (self,)) 

 

_richcmp_ = richcmp_by_eq_and_lt("_eq_", "_lt_") 

 

def _eq_(self, other): 

r""" 

Return whether this :class:`GenericGrowthElement` is equal to ``other``. 

 

INPUT: 

 

- ``other`` -- a :class:`GenericGrowthElement` 

 

OUTPUT: 

 

A boolean. 

 

.. NOTE:: 

 

This function compares two instances of 

:class:`GenericGrowthElement`. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.growth_group import GenericGrowthGroup 

sage: G = GenericGrowthGroup(ZZ) 

sage: G.an_element() == G.an_element() 

True 

sage: G(raw_element=42) == G(raw_element=7) 

False 

 

:: 

 

sage: G_ZZ = GenericGrowthGroup(ZZ) 

sage: G_QQ = GenericGrowthGroup(QQ) 

sage: G_ZZ(raw_element=1) == G_QQ(raw_element=1) 

True 

 

:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup 

sage: P_ZZ = GrowthGroup('x^ZZ') 

sage: P_QQ = GrowthGroup('x^QQ') 

sage: P_ZZ.gen() == P_QQ.gen() 

True 

sage: ~P_ZZ.gen() == P_ZZ.gen() 

False 

sage: ~P_ZZ(1) == P_ZZ(1) 

True 

 

TESTS:: 

 

sage: P = GrowthGroup('x^ZZ') 

sage: e1 = P(raw_element=1) 

sage: e1 == P.gen() 

True 

sage: e2 = e1^4 

sage: e2 == e1^2*e1*e1 

True 

sage: e2 == e1 

False 

 

:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup 

sage: G = GrowthGroup('x^ZZ') 

sage: G.one() != G(1) 

False 

sage: G.one() != G.one() 

False 

sage: G(1) != G(1) 

False 

""" 

return self._raw_element_ == other._raw_element_ 

 

def _lt_(self, other): 

r""" 

Return whether this :class:`GenericGrowthElement` is at most (less 

than or equal to) ``other``. 

 

INPUT: 

 

- ``other`` -- a :class:`GenericGrowthElement` 

 

OUTPUT: 

 

A boolean. 

 

.. NOTE:: 

 

This function compares two instances of 

:class:`GenericGrowthElement`. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup 

sage: P_ZZ = GrowthGroup('x^ZZ') 

sage: P_QQ = GrowthGroup('x^QQ') 

sage: P_ZZ.gen() <= P_QQ.gen()^2 

True 

sage: ~P_ZZ.gen() <= P_ZZ.gen() 

True 

 

TESTS:: 

 

sage: from sage.rings.asymptotic.growth_group import GenericGrowthGroup 

sage: G = GenericGrowthGroup(ZZ) 

sage: e1 = G(raw_element=1); e2 = G(raw_element=2) 

sage: e1 <= e2 # indirect doctest 

Traceback (most recent call last): 

... 

NotImplementedError: Only implemented in concrete realizations. 

""" 

raise NotImplementedError('Only implemented in concrete realizations.') 

 

log = _log_ 

log_factor = _log_factor_ 

 

def _log_factor_(self, base=None): 

r""" 

Helper method for calculating the logarithm of the factorization 

of this element. 

 

INPUT: 

 

- ``base`` -- the base of the logarithm. If ``None`` 

(default value) is used, the natural logarithm is taken. 

 

OUTPUT: 

 

A tuple of pairs, where the first entry is either a growth 

element or something out of which we can construct a growth element 

and the second a multiplicative coefficient. 

 

TESTS:: 

 

sage: from sage.rings.asymptotic.growth_group import GenericGrowthGroup 

sage: G = GenericGrowthGroup(QQ) 

sage: G.an_element().log_factor() # indirect doctest 

Traceback (most recent call last): 

... 

NotImplementedError: Cannot determine logarithmized factorization of 

GenericGrowthElement(1/2) in abstract base class. 

""" 

raise NotImplementedError('Cannot determine logarithmized factorization ' 

'of %s in abstract base class.' % (self,)) 

 

rpow = _rpow_ 

 

def _rpow_element_(self, base): 

r""" 

Return an element which is the power of ``base`` to this 

element. 

 

INPUT: 

 

- ``base`` -- an element. 

 

OUTPUT: 

 

Nothing since a ``ValueError`` is raised in this generic method. 

 

TESTS:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup 

sage: G = GrowthGroup('QQ^x') 

sage: x = G(raw_element=3) 

sage: x._rpow_element_(2) is None 

Traceback (most recent call last): 

... 

ValueError: Cannot compute 2 to the generic element 3^x. 

""" 

raise ValueError('Cannot compute %s to the generic element %s.' % 

(base, self)) 

 

def factors(self): 

r""" 

Return the atomic factors of this growth element. An atomic factor 

cannot be split further. 

 

INPUT: 

 

Nothing. 

 

OUTPUT: 

 

A tuple of growth elements. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup 

sage: G = GrowthGroup('x^ZZ') 

sage: G.an_element().factors() 

(x,) 

""" 

return (self,) 

 

is_lt_one = _is_lt_one_ 

 

def _substitute_(self, rules): 

r""" 

Substitute the given ``rules`` in this generic growth element. 

 

INPUT: 

 

- ``rules`` -- a dictionary. 

 

OUTPUT: 

 

An object. 

 

TESTS:: 

 

sage: from sage.rings.asymptotic.growth_group import GenericGrowthGroup 

sage: G = GenericGrowthGroup(ZZ) 

sage: G(raw_element=42)._substitute_({}) 

Traceback (most recent call last): 

... 

TypeError: Cannot substitute in GenericGrowthElement(42) in 

Growth Group Generic(ZZ). 

> *previous* TypeError: Cannot substitute in the abstract base class 

Growth Group Generic(ZZ). 

""" 

from .misc import substitute_raise_exception 

substitute_raise_exception(self, TypeError( 

'Cannot substitute in the abstract ' 

'base class %s.' % (self.parent(),))) 

 

def variable_names(self): 

r""" 

Return the names of the variables of this growth element. 

 

OUTPUT: 

 

A tuple of strings. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup 

sage: G = GrowthGroup('m^QQ') 

sage: G('m^2').variable_names() 

('m',) 

sage: G('m^0').variable_names() 

() 

 

:: 

 

sage: G = GrowthGroup('QQ^m') 

sage: G('2^m').variable_names() 

('m',) 

sage: G('1^m').variable_names() 

() 

 

TESTS:: 

 

sage: from sage.rings.asymptotic.growth_group import GenericGrowthGroup 

sage: G = GenericGrowthGroup(QQ) 

sage: G(raw_element=2).variable_names() 

Traceback (most recent call last): 

... 

AttributeError: 'GenericGrowthGroup_with_category.element_class' object 

has no attribute 'is_one' 

""" 

if self.is_one(): 

return tuple() 

else: 

return self.parent().variable_names() 

 

def _singularity_analysis_(self, var, zeta, precision): 

r""" 

Perform singularity analysis on this growth element. 

 

INPUT: 

 

- ``var`` -- a string denoting the variable 

 

- ``zeta`` -- a number 

 

- ``precision`` -- an integer 

 

OUTPUT: 

 

An asymptotic expansion for `[z^n] f` where `n` is ``var`` 

and `f` has this growth element as a singular expansion 

in `T=\frac{1}{1-\frac{z}{\zeta}}\to \infty` where this element 

is a growth element in `T`. 

 

TESTS:: 

 

sage: from sage.rings.asymptotic.growth_group import GenericGrowthGroup 

sage: G = GenericGrowthGroup(ZZ) 

sage: G(raw_element=2)._singularity_analysis_('n', 2, precision=3) 

Traceback (most recent call last): 

... 

NotImplementedError: singularity analysis of GenericGrowthElement(2) 

not implemented 

""" 

raise NotImplementedError('singularity analysis of {} ' 

'not implemented '.format(self)) 

 

 

class GenericGrowthGroup(UniqueRepresentation, Parent): 

r""" 

A basic implementation for growth groups. 

 

INPUT: 

 

- ``base`` -- one of SageMath's parents, out of which the elements 

get their data (``raw_element``). 

 

- ``category`` -- (default: ``None``) the category of the newly 

created growth group. It has to be a subcategory of ``Join of 

Category of groups and Category of posets``. This is also the 

default category if ``None`` is specified. 

 

- ``ignore_variables`` -- (default: ``None``) a tuple (or other 

iterable) of strings. The specified names are not considered as 

variables. 

 

.. NOTE:: 

 

This class should be derived for concrete implementations. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.growth_group import GenericGrowthGroup 

sage: G = GenericGrowthGroup(ZZ); G 

Growth Group Generic(ZZ) 

 

.. SEEALSO:: 

 

:class:`MonomialGrowthGroup`, 

:class:`ExponentialGrowthGroup` 

""" 

# TODO: implement some sort of 'assume', where basic assumptions 

# for the variables can be stored. --> within the Cartesian product 

 

# enable the category framework for elements 

Element = GenericGrowthElement 

 

 

# set everything up to determine category 

from sage.categories.sets_cat import Sets 

from sage.categories.posets import Posets 

from sage.categories.magmas import Magmas 

from sage.categories.additive_magmas import AdditiveMagmas 

 

_determine_category_subcategory_mapping_ = [ 

(Sets(), Sets(), True), 

(Posets(), Posets(), False)] 

 

_determine_category_axiom_mapping_ = [] 

 

@staticmethod 

def __classcall__(cls, base, var=None, category=None, ignore_variables=None): 

r""" 

Normalizes the input in order to ensure a unique 

representation. 

 

For more information see :class:`GenericGrowthGroup`. 

 

TESTS:: 

 

sage: from sage.rings.asymptotic.growth_group import MonomialGrowthGroup 

sage: P1 = MonomialGrowthGroup(ZZ, 'x') 

sage: P2 = MonomialGrowthGroup(ZZ, ZZ['x'].gen()) 

sage: P3 = MonomialGrowthGroup(ZZ, SR.var('x')) 

sage: P1 is P2 and P2 is P3 

True 

sage: P5 = MonomialGrowthGroup(ZZ, 'x ') 

sage: P1 is P5 

True 

 

:: 

 

sage: L1 = MonomialGrowthGroup(QQ, log(x)) 

sage: L2 = MonomialGrowthGroup(QQ, 'log(x)') 

sage: L1 is L2 

True 

 

Test determining of the category (:class:`GenericGrowthGroup`):: 

 

sage: from sage.rings.asymptotic.growth_group import GenericGrowthGroup 

sage: GenericGrowthGroup(ZZ, 'x').category() # indirect doctest 

Category of posets 

sage: GenericGrowthGroup(ZZ, 'x', category=Groups()).category() # indirect doctest 

Category of groups 

 

Test determining of the category (:class:`MonomialGrowthGroup`):: 

 

sage: from sage.rings.asymptotic.growth_group import MonomialGrowthGroup 

sage: MonomialGrowthGroup(ZZ, 'x').category() # indirect doctest 

Join of Category of commutative groups and Category of posets 

sage: MonomialGrowthGroup(ZZ, 'x', category=Monoids()).category() # indirect doctest 

Category of monoids 

sage: W = Words([0, 1]) 

sage: W.category() 

Category of sets 

sage: MonomialGrowthGroup(W, 'x').category() # indirect doctest 

Category of sets 

 

Test determining of the category (:class:`ExponentialGrowthGroup`):: 

 

sage: from sage.rings.asymptotic.growth_group import ExponentialGrowthGroup 

sage: ExponentialGrowthGroup(ZZ, 'x').category() # indirect doctest 

Join of Category of commutative monoids and Category of posets 

sage: ExponentialGrowthGroup(QQ, 'x').category() # indirect doctest 

Join of Category of commutative groups and Category of posets 

sage: ExponentialGrowthGroup(ZZ, 'x', category=Groups()).category() # indirect doctest 

Category of groups 

sage: ExponentialGrowthGroup(QQ, 'x', category=Monoids()).category() # indirect doctest 

Category of monoids 

 

:: 

 

sage: MonomialGrowthGroup(AsymptoticRing('z^ZZ', QQ), 'x') 

Traceback (most recent call last): 

... 

TypeError: Asymptotic Ring <z^ZZ> over Rational Field is not a valid base. 

""" 

from .asymptotic_ring import AsymptoticRing 

if not isinstance(base, Parent) or \ 

isinstance(base, AsymptoticRing): 

raise TypeError('%s is not a valid base.' % (base,)) 

 

if var is None: 

var = Variable('') 

elif not isinstance(var, Variable): 

var = Variable(var, ignore=ignore_variables) 

 

from sage.categories.posets import Posets 

if category is None: 

# The following block can be removed once #19269 is fixed. 

from sage.rings.integer_ring import ZZ 

from sage.rings.rational_field import QQ 

from sage.rings.polynomial.polynomial_ring import is_PolynomialRing 

if base is ZZ or base is QQ or \ 

is_PolynomialRing(base) and \ 

(base.base_ring() is ZZ or base.base_ring() is QQ): 

initial_category = Posets() 

else: 

initial_category = None 

 

from .misc import transform_category 

category = transform_category( 

base.category(), 

cls._determine_category_subcategory_mapping_, 

cls._determine_category_axiom_mapping_, 

initial_category=initial_category) 

 

return super(GenericGrowthGroup, cls).__classcall__( 

cls, base, var, category) 

 

def __init__(self, base, var, category): 

r""" 

See :class:`GenericGrowthElement` for more information. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.growth_group import GenericGrowthGroup 

sage: GenericGrowthGroup(ZZ).category() 

Category of posets 

 

:: 

 

sage: from sage.rings.asymptotic.growth_group import MonomialGrowthGroup 

sage: MonomialGrowthGroup(ZZ, 'x') 

Growth Group x^ZZ 

sage: MonomialGrowthGroup(QQ, SR.var('n')) 

Growth Group n^QQ 

sage: MonomialGrowthGroup(ZZ, ZZ['y'].gen()) 

Growth Group y^ZZ 

sage: MonomialGrowthGroup(QQ, 'log(x)') 

Growth Group log(x)^QQ 

 

:: 

 

sage: from sage.rings.asymptotic.growth_group import ExponentialGrowthGroup 

sage: ExponentialGrowthGroup(QQ, 'x') 

Growth Group QQ^x 

sage: ExponentialGrowthGroup(SR, ZZ['y'].gen()) 

Growth Group SR^y 

 

TESTS:: 

 

sage: G = GenericGrowthGroup(ZZ) 

sage: G.is_parent_of(G(raw_element=42)) 

True 

sage: G2 = GenericGrowthGroup(ZZ, category=FiniteGroups() & Posets()) 

sage: G2.category() 

Join of Category of finite groups and Category of finite posets 

 

:: 

 

sage: G = GenericGrowthGroup('42') 

Traceback (most recent call last): 

... 

TypeError: 42 is not a valid base. 

 

:: 

 

sage: MonomialGrowthGroup('x', ZZ) 

Traceback (most recent call last): 

... 

TypeError: x is not a valid base. 

sage: MonomialGrowthGroup('x', 'y') 

Traceback (most recent call last): 

... 

TypeError: x is not a valid base. 

 

:: 

 

sage: ExponentialGrowthGroup('x', ZZ) 

Traceback (most recent call last): 

... 

TypeError: x is not a valid base. 

sage: ExponentialGrowthGroup('x', 'y') 

Traceback (most recent call last): 

... 

TypeError: x is not a valid base. 

 

""" 

self._var_ = var 

super(GenericGrowthGroup, self).__init__(category=category, 

base=base) 

 

def _repr_short_(self): 

r""" 

A short representation string of this abstract growth group. 

 

INPUT: 

 

Nothing. 

 

OUTPUT: 

 

A string. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.growth_group import GenericGrowthGroup 

sage: GenericGrowthGroup(QQ)._repr_short_() 

'Generic(QQ)' 

sage: GenericGrowthGroup(QQ) 

Growth Group Generic(QQ) 

sage: GenericGrowthGroup(QQ, ('a', 'b')) 

Growth Group Generic(QQ, a, b) 

""" 

from .misc import parent_to_repr_short 

vars = ', '.join(self._var_.variable_names()) 

if vars: 

vars = ', ' + vars 

return 'Generic(%s%s)' % (parent_to_repr_short(self.base()), vars) 

 

def _repr_(self, condense=False): 

r""" 

A representations string of this growth group. 

 

INPUT: 

 

- ``condense`` -- (default: ``False``) if set, then a shorter 

output is returned, e.g. the prefix-string ``Growth Group`` 

is not show in this case. 

 

OUTPUT: 

 

A string. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup 

sage: GrowthGroup('x^ZZ') # indirect doctest 

Growth Group x^ZZ 

sage: GrowthGroup('log(x)^QQ') # indirect doctest 

Growth Group log(x)^QQ 

 

TESTS:: 

 

sage: GrowthGroup('log(x)^QQ')._repr_(condense=True) 

'log(x)^QQ' 

""" 

pre = 'Growth Group ' if not condense else '' 

return '%s%s' % (pre, self._repr_short_()) 

 

def __hash__(self): 

r""" 

Return the hash of this group. 

 

INPUT: 

 

Nothing. 

 

OUTPUT: 

 

An integer. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.growth_group import (GenericGrowthGroup, 

....: GrowthGroup) 

sage: hash(GenericGrowthGroup(ZZ)) # random 

4242424242424242 

 

:: 

 

sage: P = GrowthGroup('x^ZZ') 

sage: hash(P) # random 

-1234567890123456789 

 

:: 

 

sage: P = GrowthGroup('QQ^x') 

sage: hash(P) # random 

-1234567890123456789 

""" 

return hash((self.__class__, self.base(), self._var_)) 

 

def _an_element_(self): 

r""" 

Return an element of ``self``. 

 

INPUT: 

 

Nothing. 

 

OUTPUT: 

 

An element of ``self``. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.growth_group import (GenericGrowthGroup, 

....: GrowthGroup) 

sage: GenericGrowthGroup(ZZ).an_element() # indirect doctest 

GenericGrowthElement(1) 

sage: GrowthGroup('z^ZZ').an_element() # indirect doctest 

z 

sage: GrowthGroup('log(z)^QQ').an_element() # indirect doctest 

log(z)^(1/2) 

sage: GrowthGroup('QQ^(x*log(x))').an_element() # indirect doctest 

(1/2)^(x*log(x)) 

""" 

return self.element_class(self, self.base().an_element()) 

 

def some_elements(self): 

r""" 

Return some elements of this growth group. 

 

See :class:`TestSuite` for a typical use case. 

 

INPUT: 

 

Nothing. 

 

OUTPUT: 

 

An iterator. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup 

sage: tuple(GrowthGroup('z^ZZ').some_elements()) 

(1, z, z^(-1), z^2, z^(-2), z^3, z^(-3), 

z^4, z^(-4), z^5, z^(-5), ...) 

sage: tuple(GrowthGroup('z^QQ').some_elements()) 

(z^(1/2), z^(-1/2), z^2, z^(-2), 

1, z, z^(-1), z^42, 

z^(2/3), z^(-2/3), z^(3/2), z^(-3/2), 

z^(4/5), z^(-4/5), z^(5/4), z^(-5/4), ...) 

""" 

return iter(self.element_class(self, e) 

for e in self.base().some_elements()) 

 

def _create_element_in_extension_(self, raw_element): 

r""" 

Create an element in an extension of this growth group which 

is chosen according to the input ``raw_element``. 

 

INPUT: 

 

- ``raw_element`` -- the element data. 

 

OUTPUT: 

 

An element. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup 

sage: G = GrowthGroup('z^ZZ') 

sage: G._create_element_in_extension_(3).parent() 

Growth Group z^ZZ 

sage: G._create_element_in_extension_(1/2).parent() 

Growth Group z^QQ 

""" 

if raw_element.parent() is self.base(): 

parent = self 

else: 

parent = self._underlying_class()(raw_element.parent(), self._var_, 

category=self.category()) 

return parent(raw_element=raw_element) 

 

def le(self, left, right): 

r""" 

Return whether the growth of ``left`` is at most (less than or 

equal to) the growth of ``right``. 

 

INPUT: 

 

- ``left`` -- an element. 

 

- ``right`` -- an element. 

 

OUTPUT: 

 

A boolean. 

 

.. NOTE:: 

 

This function uses the coercion model to find a common 

parent for the two operands. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup 

sage: G = GrowthGroup('x^ZZ') 

sage: x = G.gen() 

sage: G.le(x, x^2) 

True 

sage: G.le(x^2, x) 

False 

sage: G.le(x^0, 1) 

True 

""" 

return self(left) <= self(right) 

 

def _element_constructor_(self, data, raw_element=None): 

r""" 

Convert a given object to this growth group. 

 

INPUT: 

 

- ``data`` -- an object representing the element to be 

initialized. 

 

- ``raw_element`` -- (default: ``None``) if given, then this is 

directly passed to the element constructor (i.e., no conversion 

is performed). 

 

OUTPUT: 

 

An element of this growth group. 

 

.. NOTE:: 

 

Either ``data`` or ``raw_element`` has to be given. If 

``raw_element`` is specified, then no positional argument 

may be passed. 

 

This method calls :meth:`_convert_`, which does the actual 

conversion from ``data``. 

 

TESTS:: 

 

sage: from sage.rings.asymptotic.growth_group import GenericGrowthGroup 

sage: G_ZZ = GenericGrowthGroup(ZZ) 

sage: z = G_ZZ(raw_element=42); z # indirect doctest 

GenericGrowthElement(42) 

sage: z is G_ZZ(z) # indirect doctest 

True 

 

:: 

 

sage: G_QQ = GenericGrowthGroup(QQ) 

sage: q = G_QQ(raw_element=42) # indirect doctest 

sage: q is z 

False 

sage: G_ZZ(q) # indirect doctest 

GenericGrowthElement(42) 

sage: G_QQ(z) # indirect doctest 

GenericGrowthElement(42) 

sage: q is G_ZZ(q) # indirect doctest 

False 

 

:: 

 

sage: G_ZZ() 

Traceback (most recent call last): 

... 

ValueError: No input specified. Cannot continue. 

sage: G_ZZ('blub') # indirect doctest 

Traceback (most recent call last): 

... 

ValueError: blub is not in Growth Group Generic(ZZ). 

sage: G_ZZ('x', raw_element=42) # indirect doctest 

Traceback (most recent call last): 

... 

ValueError: Input is ambigous: x as well as raw_element=42 are specified. 

 

:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup 

sage: x = GrowthGroup('x^ZZ')(raw_element=1) # indirect doctest 

sage: G_y = GrowthGroup('y^ZZ') 

sage: G_y(x) # indirect doctest 

Traceback (most recent call last): 

... 

ValueError: x is not in Growth Group y^ZZ. 

 

:: 

 

sage: GrowthGroup('QQ^x')(GrowthGroup('ZZ^x')('2^x')) 

2^x 

""" 

from .misc import combine_exceptions 

 

if raw_element is None: 

if isinstance(data, int) and data == 0: 

raise ValueError('No input specified. Cannot continue.') 

 

elif isinstance(data, self.element_class): 

if data.parent() == self: 

return data 

if self._var_ != data.parent()._var_: 

raise ValueError('%s is not in %s.' % (data, self)) 

raw_element = data._raw_element_ 

 

elif isinstance(data, self.Element): 

if self._var_ == data.parent()._var_: 

try: 

raw_element = self.base()(data._raw_element_) 

except (TypeError, ValueError) as e: 

raise combine_exceptions( 

ValueError('%s is not in %s.' % (data, self)), e) 

 

elif isinstance(data, GenericGrowthElement): 

if data.is_one(): 

return self.one() 

 

else: 

raw_element = self._convert_(data) 

 

if raw_element is None: 

raise ValueError('%s is not in %s.' % (data, self)) 

elif not isinstance(data, int) or data != 0: 

raise ValueError('Input is ambigous: ' 

'%s as well as raw_element=%s ' 

'are specified.' % (data, raw_element)) 

 

return self.element_class(self, raw_element) 

 

def _convert_(self, data): 

r""" 

Convert ``data`` to something the constructor of the 

element class accepts (``raw_element``). 

 

INPUT: 

 

- ``data`` -- an object. 

 

OUTPUT: 

 

An element of the base ring or ``None`` (when no such element 

can be constructed). 

 

.. NOTE:: 

 

This method always returns ``None`` in this abstract base 

class, and should be overridden in inherited class. 

 

TESTS:: 

 

sage: from sage.rings.asymptotic.growth_group import GenericGrowthGroup 

sage: G = GenericGrowthGroup(ZZ) 

sage: G._convert_('icecream') is None 

True 

""" 

pass 

 

def _coerce_map_from_(self, S): 

r""" 

Return whether ``S`` coerces into this growth group. 

 

INPUT: 

 

- ``S`` -- a parent. 

 

OUTPUT: 

 

A boolean. 

 

TESTS:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup 

sage: G_ZZ = GrowthGroup('x^ZZ') 

sage: G_QQ = GrowthGroup('x^QQ') 

sage: G_ZZ.has_coerce_map_from(G_QQ) # indirect doctest 

False 

sage: G_QQ.has_coerce_map_from(G_ZZ) # indirect doctest 

True 

 

:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup 

sage: P_x_ZZ = GrowthGroup('x^ZZ') 

sage: P_x_QQ = GrowthGroup('x^QQ') 

sage: P_x_ZZ.has_coerce_map_from(P_x_QQ) # indirect doctest 

False 

sage: P_x_QQ.has_coerce_map_from(P_x_ZZ) # indirect doctest 

True 

sage: P_y_ZZ = GrowthGroup('y^ZZ') 

sage: P_y_ZZ.has_coerce_map_from(P_x_ZZ) # indirect doctest 

False 

sage: P_x_ZZ.has_coerce_map_from(P_y_ZZ) # indirect doctest 

False 

sage: P_y_ZZ.has_coerce_map_from(P_x_QQ) # indirect doctest 

False 

sage: P_x_QQ.has_coerce_map_from(P_y_ZZ) # indirect doctest 

False 

 

:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup 

sage: P_x_ZZ = GrowthGroup('ZZ^x') 

sage: P_x_QQ = GrowthGroup('QQ^x') 

sage: P_x_ZZ.has_coerce_map_from(P_x_QQ) # indirect doctest 

False 

sage: P_x_QQ.has_coerce_map_from(P_x_ZZ) # indirect doctest 

True 

sage: P_y_ZZ = GrowthGroup('ZZ^y') 

sage: P_y_ZZ.has_coerce_map_from(P_x_ZZ) # indirect doctest 

False 

sage: P_x_ZZ.has_coerce_map_from(P_y_ZZ) # indirect doctest 

False 

sage: P_y_ZZ.has_coerce_map_from(P_x_QQ) # indirect doctest 

False 

sage: P_x_QQ.has_coerce_map_from(P_y_ZZ) # indirect doctest 

False 

 

:: 

 

sage: GrowthGroup('x^QQ').has_coerce_map_from(GrowthGroup('QQ^x')) # indirect doctest 

False 

""" 

if isinstance(S, self._underlying_class()) and self._var_ == S._var_: 

if self.base().has_coerce_map_from(S.base()): 

return True 

 

def _pushout_(self, other): 

r""" 

Construct the pushout of this and the other growth group. This is called by 

:func:`sage.categories.pushout.pushout`. 

 

TESTS:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup 

sage: from sage.categories.pushout import pushout 

sage: cm = sage.structure.element.get_coercion_model() 

sage: A = GrowthGroup('QQ^x') 

sage: B = GrowthGroup('y^ZZ') 

 

When using growth groups with disjoint variable lists, then a 

pushout can be constructed:: 

 

sage: A._pushout_(B) 

Growth Group QQ^x * y^ZZ 

sage: cm.common_parent(A, B) 

Growth Group QQ^x * y^ZZ 

 

In general, growth groups of the same variable cannot be 

combined automatically, since there is no order relation between the two factors:: 

 

sage: C = GrowthGroup('x^QQ') 

sage: cm.common_parent(A, C) 

Traceback (most recent call last): 

... 

TypeError: no common canonical parent for objects with parents: 

'Growth Group QQ^x' and 'Growth Group x^QQ' 

 

However, combining is possible if the factors with the same variable 

overlap:: 

 

sage: cm.common_parent(GrowthGroup('x^ZZ * log(x)^ZZ'), GrowthGroup('exp(x)^ZZ * x^ZZ')) 

Growth Group exp(x)^ZZ * x^ZZ * log(x)^ZZ 

sage: cm.common_parent(GrowthGroup('x^ZZ * log(x)^ZZ'), GrowthGroup('y^ZZ * x^ZZ')) 

Growth Group x^ZZ * log(x)^ZZ * y^ZZ 

 

:: 

 

sage: cm.common_parent(GrowthGroup('x^ZZ'), GrowthGroup('y^ZZ')) 

Growth Group x^ZZ * y^ZZ 

 

:: 

 

sage: cm.record_exceptions() 

sage: cm.common_parent(GrowthGroup('x^ZZ'), GrowthGroup('y^ZZ')) 

Growth Group x^ZZ * y^ZZ 

sage: sage.structure.element.coercion_traceback() # not tested 

""" 

if not isinstance(other, GenericGrowthGroup) and \ 

not (other.construction() is not None and 

isinstance(other.construction()[0], AbstractGrowthGroupFunctor)): 

return 

 

if set(self.variable_names()).isdisjoint(set(other.variable_names())): 

from sage.categories.cartesian_product import cartesian_product 

return cartesian_product([self, other]) 

 

def gens_monomial(self): 

r""" 

Return a tuple containing monomial generators of this growth 

group. 

 

INPUT: 

 

Nothing. 

 

OUTPUT: 

 

An empty tuple. 

 

.. NOTE:: 

 

A generator is called monomial generator if the variable 

of the underlying growth group is a valid identifier. For 

example, ``x^ZZ`` has ``x`` as a monomial generator, 

while ``log(x)^ZZ`` or ``icecream(x)^ZZ`` do not have 

monomial generators. 

 

TESTS:: 

 

sage: from sage.rings.asymptotic.growth_group import GenericGrowthGroup 

sage: GenericGrowthGroup(ZZ).gens_monomial() 

() 

 

:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup 

sage: GrowthGroup('x^QQ').gens_monomial() 

(x,) 

sage: GrowthGroup('QQ^x').gens_monomial() 

() 

""" 

return tuple() 

 

def gens(self): 

r""" 

Return a tuple of all generators of this growth group. 

 

INPUT: 

 

Nothing. 

 

OUTPUT: 

 

A tuple whose entries are growth elements. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup 

sage: P = GrowthGroup('x^ZZ') 

sage: P.gens() 

(x,) 

sage: GrowthGroup('log(x)^ZZ').gens() 

(log(x),) 

""" 

return (self(raw_element=self.base().one()),) 

 

def gen(self, n=0): 

r""" 

Return the `n`-th generator (as a group) of this growth group. 

 

INPUT: 

 

- ``n`` -- default: `0`. 

 

OUTPUT: 

 

A :class:`MonomialGrowthElement`. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup 

sage: P = GrowthGroup('x^ZZ') 

sage: P.gen() 

x 

 

:: 

 

sage: P = GrowthGroup('QQ^x') 

sage: P.gen() 

Traceback (most recent call last): 

... 

IndexError: tuple index out of range 

""" 

return self.gens()[n] 

 

def ngens(self): 

r""" 

Return the number of generators (as a group) of this growth group. 

 

INPUT: 

 

Nothing. 

 

OUTPUT: 

 

A Python integer. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup 

sage: P = GrowthGroup('x^ZZ') 

sage: P.ngens() 

1 

sage: GrowthGroup('log(x)^ZZ').ngens() 

1 

 

:: 

 

sage: P = GrowthGroup('QQ^x') 

sage: P.ngens() 

0 

""" 

return len(self.gens()) 

 

def variable_names(self): 

r""" 

Return the names of the variables of this growth group. 

 

OUTPUT: 

 

A tuple of strings. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.growth_group import GenericGrowthGroup 

sage: GenericGrowthGroup(ZZ).variable_names() 

() 

 

:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup 

sage: GrowthGroup('x^ZZ').variable_names() 

('x',) 

sage: GrowthGroup('log(x)^ZZ').variable_names() 

('x',) 

 

:: 

 

sage: GrowthGroup('QQ^x').variable_names() 

('x',) 

sage: GrowthGroup('QQ^(x*log(x))').variable_names() 

('x',) 

""" 

return self._var_.variable_names() 

 

CartesianProduct = CartesianProductGrowthGroups 

 

 

class AbstractGrowthGroupFunctor(ConstructionFunctor): 

r""" 

A base class for the functors constructing growth groups. 

 

INPUT: 

 

- ``var`` -- a string or list of strings (or anything else 

:class:`Variable` accepts). 

 

- ``domain`` -- a category. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup 

sage: GrowthGroup('z^QQ').construction()[0] # indirect doctest 

MonomialGrowthGroup[z] 

 

.. SEEALSO:: 

 

:doc:`asymptotic_ring`, 

:class:`ExponentialGrowthGroupFunctor`, 

:class:`MonomialGrowthGroupFunctor`, 

:class:`sage.rings.asymptotic.asymptotic_ring.AsymptoticRingFunctor`, 

:class:`sage.categories.pushout.ConstructionFunctor`. 

""" 

 

_functor_name = 'AbstractGrowthGroup' 

 

rank = 13 

 

def __init__(self, var, domain): 

r""" 

See :class:`AbstractGrowthGroupFunctor` for details. 

 

TESTS:: 

 

sage: from sage.rings.asymptotic.growth_group import AbstractGrowthGroupFunctor 

sage: AbstractGrowthGroupFunctor('x', Groups()) 

AbstractGrowthGroup[x] 

""" 

from sage.categories.monoids import Monoids 

from sage.categories.posets import Posets 

 

if var is None: 

var = Variable('') 

elif not isinstance(var, Variable): 

var = Variable(var) 

self.var = var 

super(ConstructionFunctor, self).__init__( 

domain, Monoids() & Posets()) 

 

def _repr_(self): 

r""" 

Return a representation string of this functor. 

 

OUTPUT: 

 

A string. 

 

TESTS:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup 

sage: GrowthGroup('QQ^t').construction()[0] # indirect doctest 

ExponentialGrowthGroup[t] 

""" 

return '%s[%s]' % (self._functor_name, self.var) 

 

def merge(self, other): 

r""" 

Merge this functor with ``other`` of possible. 

 

INPUT: 

 

- ``other`` -- a functor. 

 

OUTPUT: 

 

A functor or ``None``. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup 

sage: F = GrowthGroup('QQ^t').construction()[0] 

sage: G = GrowthGroup('t^QQ').construction()[0] 

sage: F.merge(F) 

ExponentialGrowthGroup[t] 

sage: F.merge(G) is None 

True 

""" 

if self == other: 

return self 

 

def __eq__(self, other): 

r""" 

Return whether this functor is equal to ``other``. 

 

INPUT: 

 

- ``other`` -- a functor. 

 

OUTPUT: 

 

A boolean. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup 

sage: F = GrowthGroup('QQ^t').construction()[0] 

sage: G = GrowthGroup('t^QQ').construction()[0] 

sage: F == F 

True 

sage: F == G 

False 

""" 

return type(self) == type(other) and self.var == other.var 

 

def __ne__(self, other): 

r""" 

Return whether this functor is not equal to ``other``. 

 

INPUT: 

 

- ``other`` -- a functor. 

 

OUTPUT: 

 

A boolean. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup 

sage: F = GrowthGroup('QQ^t').construction()[0] 

sage: G = GrowthGroup('t^QQ').construction()[0] 

sage: F != F 

False 

sage: F != G 

True 

""" 

return not self == other 

 

 

class MonomialGrowthElement(GenericGrowthElement): 

r""" 

An implementation of monomial growth elements. 

 

INPUT: 

 

- ``parent`` -- a :class:`MonomialGrowthGroup`. 

 

- ``raw_element`` -- an element from the base ring of the parent. 

 

This ``raw_element`` is the exponent of the created monomial 

growth element. 

 

A monomial growth element represents a term of the type 

`\operatorname{variable}^{\operatorname{exponent}}`. The multiplication 

corresponds to the addition of the exponents. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.growth_group import MonomialGrowthGroup 

sage: P = MonomialGrowthGroup(ZZ, 'x') 

sage: e1 = P(1); e1 

1 

sage: e2 = P(raw_element=2); e2 

x^2 

sage: e1 == e2 

False 

sage: P.le(e1, e2) 

True 

sage: P.le(e1, P.gen()) and P.le(P.gen(), e2) 

True 

""" 

 

@property 

def exponent(self): 

r""" 

The exponent of this growth element. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup 

sage: P = GrowthGroup('x^ZZ') 

sage: P(x^42).exponent 

42 

""" 

return self._raw_element_ 

 

def _repr_(self, latex=False): 

r""" 

A representation string for this monomial growth element. 

 

INPUT: 

 

- ``latex`` -- (default: ``False``) a boolean. If set, then 

LaTeX-output is returned. 

 

OUTPUT: 

 

A string. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup 

sage: P = GrowthGroup('x^QQ') 

sage: P(1)._repr_() 

'1' 

sage: P(x^5) # indirect doctest 

x^5 

sage: P(x^(1/2)) # indirect doctest 

x^(1/2) 

 

TESTS:: 

 

sage: P(x^-1) # indirect doctest 

x^(-1) 

sage: P(x^-42) # indirect doctest 

x^(-42) 

""" 

if latex: 

from sage.misc.latex import latex as latex_repr 

f = latex_repr 

else: 

f = repr 

 

from sage.rings.integer_ring import ZZ 

from .misc import repr_op 

 

var = f(self.parent()._var_) 

if self.exponent.is_zero(): 

return '1' 

elif self.exponent.is_one(): 

return var 

elif latex: 

return repr_op(var, '^', latex=True) + \ 

'{' + latex_repr(self.exponent)._latex_() + '}' 

elif self.exponent in ZZ and self.exponent > 0: 

return repr_op(var, '^') + str(self.exponent) 

else: 

return repr_op(var, '^') + '(' + str(self.exponent) + ')' 

 

def _latex_(self): 

r""" 

A LaTeX-representation string for this monomial growth element. 

 

OUTPUT: 

 

A string. 

 

TESTS:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup 

sage: P = GrowthGroup('x^QQ') 

sage: latex(P(1)) # indirect doctest 

1 

sage: latex(P(x^5)) # indirect doctest 

x^{5} 

sage: latex(P(x^(1/2))) # indirect doctest 

x^{\frac{1}{2}} 

 

:: 

 

sage: latex(P(x^-1)) # indirect doctest 

x^{-1} 

sage: latex(P(x^-42)) # indirect doctest 

x^{-42} 

""" 

return self._repr_(latex=True) 

 

def _mul_(self, other): 

r""" 

Multiply this monomial growth element with another. 

 

INPUT: 

 

- ``other`` -- a :class:`MonomialGrowthElement` 

 

OUTPUT: 

 

The product as a :class:`MonomialGrowthElement`. 

 

.. NOTE:: 

 

Two monomial growth elements are multiplied by adding 

their exponents. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup 

sage: P = GrowthGroup('x^ZZ') 

sage: a = P(x^2) 

sage: b = P(x^3) 

sage: c = a._mul_(b); c 

x^5 

sage: c == a*b 

True 

sage: a*b*a # indirect doctest 

x^7 

""" 

return self.parent()(raw_element=self.exponent + other.exponent) 

 

def __invert__(self): 

r""" 

Return the multiplicative inverse of this monomial growth element. 

 

INPUT: 

 

Nothing. 

 

OUTPUT: 

 

The multiplicative inverse as a :class:`MonomialGrowthElement`. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup 

sage: P = GrowthGroup('x^ZZ') 

sage: e1 = P(raw_element=2) 

sage: e2 = e1.__invert__(); e2 

x^(-2) 

sage: e2 == ~e1 

True 

sage: Q = GrowthGroup('x^NN'); Q 

Growth Group x^(Non negative integer semiring) 

sage: e3 = ~Q('x'); e3 

x^(-1) 

sage: e3.parent() 

Growth Group x^ZZ 

""" 

return self.parent()._create_element_in_extension_(-self.exponent) 

 

def __pow__(self, exponent): 

r""" 

Calculate the power of this growth element to the given ``exponent``. 

 

INPUT: 

 

- ``exponent`` -- a number. This can be anything that is a 

valid right hand side of ``*`` with elements of the 

parent's base. 

 

OUTPUT: 

 

The result of this exponentiation, a :class:`MonomialGrowthElement`. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup 

sage: P = GrowthGroup('x^ZZ') 

sage: x = P.gen() 

sage: a = x^7; a 

x^7 

sage: a^(1/2) 

x^(7/2) 

sage: (a^(1/2)).parent() 

Growth Group x^QQ 

sage: a^(1/7) 

x 

sage: (a^(1/7)).parent() 

Growth Group x^QQ 

sage: P = GrowthGroup('x^QQ') 

sage: b = P.gen()^(7/2); b 

x^(7/2) 

sage: b^12 

x^42 

""" 

return self.parent()._create_element_in_extension_(self.exponent * exponent) 

 

def _log_factor_(self, base=None): 

r""" 

Helper method for calculating the logarithm of the factorization 

of this element. 

 

INPUT: 

 

- ``base`` -- the base of the logarithm. If ``None`` 

(default value) is used, the natural logarithm is taken. 

 

OUTPUT: 

 

A tuple of pairs, where the first entry is either a growth 

element or something out of which we can construct a growth element 

and the second a multiplicative coefficient. 

 

TESTS:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup 

sage: G = GrowthGroup('x^QQ') 

sage: G('x').log_factor() # indirect doctest 

Traceback (most recent call last): 

... 

ArithmeticError: Cannot build log(x) since log(x) is not in 

Growth Group x^QQ. 

 

:: 

 

sage: G = GrowthGroup('exp(x)^ZZ * x^ZZ') 

sage: log(G('exp(x)'), base=2) 

Traceback (most recent call last): 

... 

ArithmeticError: When calculating log(exp(x), base=2) a factor 

1/log(2) != 1 appeared, which is not contained in 

Growth Group exp(x)^ZZ * x^ZZ. 

""" 

if self.is_one(): 

return tuple() 

coefficient = self.exponent 

 

var = str(self.parent()._var_) 

 

from .misc import split_str_by_op 

split = split_str_by_op(var, '^') 

if len(split) == 2: 

b, e = split 

if base is None and b == 'e' or \ 

base is not None and b == str(base): 

return ((e, coefficient),) 

 

if var.startswith('exp('): 

assert(var[-1] == ')') 

v = var[4:-1] 

else: 

v = 'log(%s)' % (var,) 

 

if base is not None: 

from sage.functions.log import log 

coefficient = coefficient / log(base) 

return ((v, coefficient),) 

 

def _rpow_element_(self, base): 

r""" 

Return an element which is the power of ``base`` to this 

element. 

 

INPUT: 

 

- ``base`` -- an element. 

 

OUTPUT: 

 

A growth element. 

 

.. NOTE:: 

 

The parent of the result can be different from the parent 

of this element. 

 

A ``ValueError`` is raised if the calculation is not possible 

within this method. (Then the calling method should take care 

of the calculation.) 

 

TESTS:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup 

sage: G = GrowthGroup('x^ZZ') 

sage: x = G('x') 

sage: x._rpow_element_(2) 

Traceback (most recent call last): 

... 

ValueError: Variable x is not a log of something. 

 

The previous example does not work since the result would not 

live in a monomial growth group. When using 

:meth:`~GenericGrowthElement.rpow`, this 

case is handeled by the calling method :meth:`_rpow_`. 

 

:: 

 

sage: G = GrowthGroup('log(x)^ZZ') 

sage: lx = G(raw_element=1); lx 

log(x) 

sage: rp = lx._rpow_element_('e'); rp 

x 

sage: rp.parent() 

Growth Group x^ZZ 

 

:: 

 

sage: G = GrowthGroup('log(x)^SR') 

sage: lx = G('log(x)') 

sage: lx._rpow_element_(2) 

x^(log(2)) 

""" 

var = str(self.parent()._var_) 

if not(var.startswith('log(') and self.exponent.is_one()): 

raise ValueError('Variable %s is not a log of something.' % (var,)) 

new_var = var[4:-1] 

if base == 'e': 

from sage.rings.integer_ring import ZZ 

M = MonomialGrowthGroup(ZZ, new_var) 

return M(raw_element=ZZ(1)) 

else: 

from sage.functions.log import log 

new_exponent = log(base) 

M = MonomialGrowthGroup(new_exponent.parent(), new_var) 

return M(raw_element=new_exponent) 

 

def _lt_(self, other): 

r""" 

Return whether this :class:`MonomialGrowthElement` is 

less than ``other``. 

 

INPUT: 

 

- ``other`` -- a :class:`MonomialGrowthElement` 

 

OUTPUT: 

 

A boolean. 

 

.. NOTE:: 

 

This function compares two instances of 

:class:`MonomialGrowthElement`. 

 

TESTS:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup 

sage: P_ZZ = GrowthGroup('x^ZZ') 

sage: P_QQ = GrowthGroup('x^QQ') 

sage: P_ZZ.gen() <= P_QQ.gen()^2 # indirect doctest 

True 

""" 

return self.exponent < other.exponent 

 

def _substitute_(self, rules): 

r""" 

Substitute the given ``rules`` in this monomial growth element. 

 

INPUT: 

 

- ``rules`` -- a dictionary. 

The neutral element of the group is replaced by the value 

to key ``'_one_'``. 

 

OUTPUT: 

 

An object. 

 

TESTS:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup 

sage: G = GrowthGroup('x^ZZ') 

sage: G(x^42)._substitute_({'x': SR.var('z')}) 

z^42 

sage: _.parent() 

Symbolic Ring 

sage: G(x^3)._substitute_({'x': 2}) 

8 

sage: _.parent() 

Integer Ring 

sage: G(1 / x)._substitute_({'x': 0}) 

Traceback (most recent call last): 

... 

ZeroDivisionError: Cannot substitute in x^(-1) in Growth Group x^ZZ. 

> *previous* ZeroDivisionError: rational division by zero 

sage: G(1)._substitute_({'_one_': 'one'}) 

'one' 

""" 

if self.is_one(): 

return rules['_one_'] 

try: 

return self.parent()._var_._substitute_(rules) ** self.exponent 

except (ArithmeticError, TypeError, ValueError) as e: 

from .misc import substitute_raise_exception 

substitute_raise_exception(self, e) 

 

def _singularity_analysis_(self, var, zeta, precision): 

r""" 

Perform singularity analysis on this monomial growth element. 

 

INPUT: 

 

- ``var`` -- a string denoting the variable 

 

- ``zeta`` -- a number 

 

- ``precision`` -- an integer 

 

OUTPUT: 

 

An asymptotic expansion for `[z^n] f` where `n` is ``var`` 

and `f` has this growth element as a singular expansion 

in `T=\frac{1}{1-\frac{z}{\zeta}}\to \infty` where this element 

is a growth element in `T`. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup 

sage: G = GrowthGroup('x^QQ') 

sage: G(x^(1/2))._singularity_analysis_('n', 2, precision=2) 

1/sqrt(pi)*(1/2)^n*n^(-1/2) - 1/8/sqrt(pi)*(1/2)^n*n^(-3/2) 

+ O((1/2)^n*n^(-5/2)) 

sage: G = GrowthGroup('log(x)^QQ') 

sage: G(log(x))._singularity_analysis_('n', 1, precision=5) 

n^(-1) + O(n^(-3)) 

sage: G(log(x)^2)._singularity_analysis_('n', 2, precision=3) 

2*(1/2)^n*n^(-1)*log(n) + 2*euler_gamma*(1/2)^n*n^(-1) 

+ O((1/2)^n*n^(-2)*log(n)^2) 

 

TESTS:: 

 

sage: G(log(x)^(1/2))._singularity_analysis_('n', 2, precision=3) 

Traceback (most recent call last): 

... 

NotImplementedError: singularity analysis of log(x)^(1/2) 

not implemented since exponent 1/2 is not an integer 

sage: G = GrowthGroup('log(log(x))^QQ') 

sage: G(log(log(x))^(1/2))._singularity_analysis_('n', 2, precision=3) 

Traceback (most recent call last): 

... 

NotImplementedError: singularity analysis of log(log(x))^(1/2) 

not implemented 

""" 

from sage.rings.integer_ring import ZZ 

 

if self.parent()._var_.is_monomial(): 

from sage.rings.asymptotic.asymptotic_expansion_generators import \ 

asymptotic_expansions 

return asymptotic_expansions.SingularityAnalysis( 

var=var, zeta=zeta, alpha=self.exponent, beta=0, delta=0, 

precision=precision) 

elif self.parent().gens_logarithmic(): 

if self.exponent not in ZZ: 

raise NotImplementedError( 

'singularity analysis of {} not implemented ' 

'since exponent {} is not an integer'.format( 

self, self.exponent)) 

from sage.rings.asymptotic.asymptotic_expansion_generators import \ 

asymptotic_expansions 

return asymptotic_expansions.SingularityAnalysis( 

var=var, zeta=zeta, alpha=0, beta=ZZ(self.exponent), delta=0, 

precision=precision, normalized=False) 

else: 

raise NotImplementedError( 

'singularity analysis of {} not implemented'.format(self)) 

 

 

class MonomialGrowthGroup(GenericGrowthGroup): 

r""" 

A growth group dealing with powers of a fixed object/symbol. 

 

The elements :class:`MonomialGrowthElement` of this group represent powers 

of a fixed base; the group law is the multiplication, which corresponds 

to the addition of the exponents of the monomials. 

 

INPUT: 

 

- ``base`` -- one of SageMath's parents, out of which the elements 

get their data (``raw_element``). 

 

As monomials are represented by this group, the elements in 

``base`` are the exponents of these monomials. 

 

- ``var`` -- an object. 

 

The string representation of ``var`` acts as a base of the 

monomials represented by this group. 

 

- ``category`` -- (default: ``None``) the category of the newly 

created growth group. It has to be a subcategory of ``Join of 

Category of groups and Category of posets``. This is also the 

default category if ``None`` is specified. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.growth_group import MonomialGrowthGroup 

sage: P = MonomialGrowthGroup(ZZ, 'x'); P 

Growth Group x^ZZ 

sage: MonomialGrowthGroup(ZZ, log(SR.var('y'))) 

Growth Group log(y)^ZZ 

 

.. SEEALSO:: 

 

:class:`GenericGrowthGroup` 

 

TESTS:: 

 

sage: L1 = MonomialGrowthGroup(QQ, log(x)) 

sage: L2 = MonomialGrowthGroup(QQ, 'log(x)') 

sage: L1 is L2 

True 

""" 

 

# enable the category framework for elements 

Element = MonomialGrowthElement 

 

# set everything up to determine category 

from sage.categories.sets_cat import Sets 

from sage.categories.posets import Posets 

from sage.categories.magmas import Magmas 

from sage.categories.additive_magmas import AdditiveMagmas 

 

_determine_category_subcategory_mapping_ = [ 

(Sets(), Sets(), True), 

(Posets(), Posets(), False), 

(AdditiveMagmas(), Magmas(), False)] 

 

_determine_category_axiom_mapping_ = [ 

('AdditiveAssociative', 'Associative', False), 

('AdditiveUnital', 'Unital', False), 

('AdditiveInverse', 'Inverse', False), 

('AdditiveCommutative', 'Commutative', False)] 

 

def _repr_short_(self): 

r""" 

A short representation string of this monomial growth group. 

 

INPUT: 

 

Nothing. 

 

OUTPUT: 

 

A string. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.growth_group import MonomialGrowthGroup 

sage: MonomialGrowthGroup(ZZ, 'a') # indirect doctest 

Growth Group a^ZZ 

 

 

TESTS:: 

 

sage: MonomialGrowthGroup(ZZ, 'a')._repr_short_() 

'a^ZZ' 

sage: MonomialGrowthGroup(QQ, 'a')._repr_short_() 

'a^QQ' 

sage: MonomialGrowthGroup(PolynomialRing(QQ, 'x'), 'a')._repr_short_() 

'a^QQ[x]' 

""" 

from .misc import parent_to_repr_short, repr_op 

return repr_op(self._var_, '^', parent_to_repr_short(self.base())) 

 

def _convert_(self, data): 

r""" 

Convert ``data`` to something the constructor of the 

element class accepts (``raw_element``). 

 

INPUT: 

 

- ``data`` -- an object. 

 

OUTPUT: 

 

An element of the base ring or ``None`` (when no such element 

can be constructed). 

 

TESTS:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup 

sage: P = GrowthGroup('x^ZZ') 

sage: P._convert_('icecream') is None 

True 

sage: P(1) # indirect doctest 

1 

sage: P('x') # indirect doctest 

x 

 

:: 

 

sage: P(x) # indirect doctest 

x 

sage: P(x^-333) # indirect doctest 

x^(-333) 

sage: P(log(x)^2) # indirect doctest 

Traceback (most recent call last): 

... 

ValueError: log(x)^2 is not in Growth Group x^ZZ. 

 

:: 

 

sage: PR.<x> = ZZ[]; x.parent() 

Univariate Polynomial Ring in x over Integer Ring 

sage: P(x^2) # indirect doctest 

x^2 

 

:: 

 

sage: PSR.<x> = ZZ[[]] 

sage: P(x^42) # indirect doctest 

x^42 

sage: P(x^12 + O(x^17)) 

Traceback (most recent call last): 

... 

ValueError: x^12 + O(x^17) is not in Growth Group x^ZZ. 

 

:: 

 

sage: R.<w,x> = ZZ[] 

sage: P(x^4242) # indirect doctest 

x^4242 

sage: P(w^4242) # indirect doctest 

Traceback (most recent call last): 

... 

ValueError: w^4242 is not in Growth Group x^ZZ. 

 

:: 

 

sage: PSR.<w,x> = ZZ[[]] 

sage: P(x^7) # indirect doctest 

x^7 

sage: P(w^7) # indirect doctest 

Traceback (most recent call last): 

... 

ValueError: w^7 is not in Growth Group x^ZZ. 

 

:: 

 

sage: P('x^7') 

x^7 

sage: P('1/x') 

x^(-1) 

sage: P('x^(-2)') 

x^(-2) 

sage: P('x^-2') 

x^(-2) 

 

:: 

 

sage: P('1') 

1 

 

:: 

 

sage: GrowthGroup('x^QQ')(GrowthGroup('x^ZZ')(1)) 

1 

""" 

if data == 1 or data == '1': 

return self.base().zero() 

var = repr(self._var_) 

if str(data) == var: 

return self.base().one() 

 

try: 

P = data.parent() 

except AttributeError: 

if var not in str(data): 

return # this has to end here 

from sage.symbolic.ring import SR 

return self._convert_(SR(data)) 

 

from sage.symbolic.ring import SymbolicRing 

from sage.rings.polynomial.polynomial_ring import PolynomialRing_general 

from sage.rings.polynomial.multi_polynomial_ring_generic import \ 

MPolynomialRing_generic 

from sage.rings.power_series_ring import PowerSeriesRing_generic 

import operator 

if isinstance(P, SymbolicRing): 

if data.operator() == operator.pow: 

base, exponent = data.operands() 

if str(base) == var: 

return exponent 

elif isinstance(P, (PolynomialRing_general, MPolynomialRing_generic)): 

if data.is_monomial() and len(data.variables()) == 1: 

if var == str(data.variables()[0]): 

return data.degree() 

elif isinstance(P, PowerSeriesRing_generic): 

if hasattr(data, 'variables') and len(data.variables()) == 1: 

from sage.rings.integer_ring import ZZ 

if data.is_monomial() and data.precision_absolute() not in ZZ: 

if var == str(data.variables()[0]): 

return data.degree() 

elif len(P.variable_names()) == 1 and \ 

var == str(data.variable()[0]): 

from sage.rings.integer_ring import ZZ 

if data.is_monomial() and data.precision_absolute() not in ZZ: 

return data.degree() 

 

def gens_monomial(self): 

r""" 

Return a tuple containing monomial generators of this growth 

group. 

 

INPUT: 

 

Nothing. 

 

OUTPUT: 

 

A tuple containing elements of this growth group. 

 

.. NOTE:: 

 

A generator is called monomial generator if the variable 

of the underlying growth group is a valid identifier. For 

example, ``x^ZZ`` has ``x`` as a monomial generator, 

while ``log(x)^ZZ`` or ``icecream(x)^ZZ`` do not have 

monomial generators. 

 

TESTS:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup 

sage: GrowthGroup('x^ZZ').gens_monomial() 

(x,) 

sage: GrowthGroup('log(x)^QQ').gens_monomial() 

() 

""" 

if not self._var_.is_monomial(): 

return tuple() 

return (self(raw_element=self.base().one()),) 

 

def gens_logarithmic(self): 

r""" 

Return a tuple containing logarithmic generators of this growth 

group. 

 

INPUT: 

 

Nothing. 

 

OUTPUT: 

 

A tuple containing elements of this growth group. 

 

.. NOTE:: 

 

A generator is called logarithmic generator if the variable 

of the underlying growth group is the logarithm of a valid 

identifier. For 

example, ``x^ZZ`` has no logarithmic generator, 

while ``log(x)^ZZ`` has ``log(x)`` as 

logarithmic generator. 

 

TESTS:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup 

sage: GrowthGroup('x^ZZ').gens_logarithmic() 

() 

sage: GrowthGroup('log(x)^QQ').gens_logarithmic() 

(log(x),) 

""" 

if str(self.gen()) == "log({})".format(self.variable_name()): 

return (self(raw_element=self.base().one()),) 

else: 

return tuple() 

 

def construction(self): 

r""" 

Return the construction of this growth group. 

 

OUTPUT: 

 

A pair whose first entry is a 

:class:`monomial construction functor <MonomialGrowthGroupFunctor>` 

and its second entry the base. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup 

sage: GrowthGroup('x^ZZ').construction() 

(MonomialGrowthGroup[x], Integer Ring) 

""" 

return MonomialGrowthGroupFunctor(self._var_), self.base() 

 

 

class MonomialGrowthGroupFunctor(AbstractGrowthGroupFunctor): 

r""" 

A :class:`construction functor <sage.categories.pushout.ConstructionFunctor>` 

for :class:`monomial growth groups <MonomialGrowthGroup>`. 

 

INPUT: 

 

- ``var`` -- a string or list of strings (or anything else 

:class:`Variable` accepts). 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup, MonomialGrowthGroupFunctor 

sage: GrowthGroup('z^QQ').construction()[0] 

MonomialGrowthGroup[z] 

 

.. SEEALSO:: 

 

:doc:`asymptotic_ring`, 

:class:`AbstractGrowthGroupFunctor`, 

:class:`ExponentialGrowthGroupFunctor`, 

:class:`sage.rings.asymptotic.asymptotic_ring.AsymptoticRingFunctor`, 

:class:`sage.categories.pushout.ConstructionFunctor`. 

 

TESTS:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup, MonomialGrowthGroupFunctor 

sage: cm = sage.structure.element.get_coercion_model() 

sage: A = GrowthGroup('x^QQ') 

sage: B = MonomialGrowthGroupFunctor('x')(ZZ['t']) 

sage: cm.common_parent(A, B) 

Growth Group x^QQ[t] 

""" 

 

_functor_name = 'MonomialGrowthGroup' 

 

def __init__(self, var): 

r""" 

See :class:`MonomialGrowthGroupFunctor` for details. 

 

TESTS:: 

 

sage: from sage.rings.asymptotic.growth_group import MonomialGrowthGroupFunctor 

sage: MonomialGrowthGroupFunctor('x') 

MonomialGrowthGroup[x] 

""" 

from sage.categories.commutative_additive_monoids import CommutativeAdditiveMonoids 

 

super(MonomialGrowthGroupFunctor, self).__init__(var, 

CommutativeAdditiveMonoids()) 

 

def _apply_functor(self, base): 

r""" 

Apply this functor to the given ``base``. 

 

INPUT: 

 

- ``base`` - anything :class:`MonomialGrowthGroup` accepts. 

 

OUTPUT: 

 

A monomial growth group. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup 

sage: F, R = GrowthGroup('z^QQ').construction() 

sage: F(R) # indirect doctest 

Growth Group z^QQ 

""" 

return MonomialGrowthGroup(base, self.var) 

 

 

class ExponentialGrowthElement(GenericGrowthElement): 

r""" 

An implementation of exponential growth elements. 

 

INPUT: 

 

- ``parent`` -- an :class:`ExponentialGrowthGroup`. 

 

- ``raw_element`` -- an element from the base ring of the parent. 

 

This ``raw_element`` is the base of the created exponential 

growth element. 

 

An exponential growth element represents a term of the type 

`\operatorname{base}^{\operatorname{variable}}`. The multiplication 

corresponds to the multiplication of the bases. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup 

sage: P = GrowthGroup('ZZ^x') 

sage: e1 = P(1); e1 

1 

sage: e2 = P(raw_element=2); e2 

2^x 

sage: e1 == e2 

False 

sage: P.le(e1, e2) 

True 

sage: P.le(e1, P(1)) and P.le(P(1), e2) 

True 

""" 

 

@property 

def base(self): 

r""" 

The base of this exponential growth element. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup 

sage: P = GrowthGroup('ZZ^x') 

sage: P(42^x).base 

42 

""" 

return self._raw_element_ 

 

def _repr_(self, latex=False): 

r""" 

A representation string for this exponential growth element. 

 

INPUT: 

 

- ``latex`` -- (default: ``False``) a boolean. If set, then 

LaTeX-output is returned. 

 

OUTPUT: 

 

A string. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup 

sage: P = GrowthGroup('QQ^x') 

sage: P(1)._repr_() 

'1' 

sage: P(5^x) # indirect doctest 

5^x 

sage: P((1/2)^x) # indirect doctest 

(1/2)^x 

 

TESTS:: 

 

sage: P((-1)^x) # indirect doctest 

(-1)^x 

 

:: 

 

sage: from sage.rings.asymptotic.growth_group import ExponentialGrowthGroup 

sage: G = ExponentialGrowthGroup(ZZ['x'], 'y'); G 

Growth Group ZZ[x]^y 

sage: G('(1-x)^y') 

(-x + 1)^y 

sage: G('(1+x)^y') 

(x + 1)^y 

""" 

if latex: 

from sage.misc.latex import latex as latex_repr 

f = latex_repr 

else: 

f = repr 

 

from .misc import repr_op 

 

var = f(self.parent()._var_) 

if self.base.is_one(): 

return '1' 

if latex: 

return repr_op(latex_repr(self.base)._latex_(), '^', latex=True) + \ 

'{' + latex_repr(var)._latex_() + '}' 

else: 

return repr_op(str(self.base), '^', var) 

 

def _latex_(self): 

r""" 

A LaTeX-representation string for this exponential growth element. 

 

OUTPUT: 

 

A string. 

 

TESTS:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup 

sage: P = GrowthGroup('QQ^x') 

sage: latex(P(1)) 

1 

sage: latex(P(5^x)) # indirect doctest 

5^{x} 

sage: latex(P((1/2)^x)) # indirect doctest 

\left(\frac{1}{2}\right)^{x} 

 

:: 

 

sage: latex(P((-1)^x)) # indirect doctest 

\left(-1\right)^{x} 

 

:: 

 

sage: from sage.rings.asymptotic.growth_group import ExponentialGrowthGroup 

sage: G = ExponentialGrowthGroup(ZZ['x'], 'y'); G 

Growth Group ZZ[x]^y 

sage: latex(G('(1-x)^y')) 

\left(-x + 1\right)^{y} 

sage: latex(G('(1+x)^y')) 

\left(x + 1\right)^{y} 

""" 

return self._repr_(latex=True) 

 

def _mul_(self, other): 

r""" 

Multiply this exponential growth element with another. 

 

INPUT: 

 

- ``other`` -- a :class:`ExponentialGrowthElement` 

 

OUTPUT: 

 

The product as a :class:`ExponentialGrowthElement`. 

 

.. NOTE:: 

 

Two exponential growth elements are multiplied by 

multiplying their bases. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup 

sage: P = GrowthGroup('ZZ^x') 

sage: a = P(2^x) 

sage: b = P(3^x) 

sage: c = a._mul_(b); c 

6^x 

sage: c == a*b 

True 

sage: a*b*a # indirect doctest 

12^x 

""" 

return self.parent()(raw_element=self.base * other.base) 

 

def __invert__(self): 

r""" 

Return the multiplicative inverse of this exponential growth element. 

 

INPUT: 

 

Nothing. 

 

OUTPUT: 

 

The multiplicative inverse as a :class:`ExponentialGrowthElement`. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup 

sage: P = GrowthGroup('ZZ^x') 

sage: e1 = P(raw_element=2) 

sage: e2 = e1.__invert__(); e2 

(1/2)^x 

sage: e2 == ~e1 

True 

sage: e2.parent() 

Growth Group QQ^x 

 

:: 

 

sage: (~P(raw_element=1)).parent() 

Growth Group QQ^x 

""" 

return self.parent()._create_element_in_extension_(1 / self.base) 

 

def __pow__(self, exponent): 

r""" 

Calculate the power of this growth element to the given ``exponent``. 

 

INPUT: 

 

- ``exponent`` -- a number. This can be anything that is valid to be 

on the right hand side of ``*`` with an elements of the 

parent's base. 

 

OUTPUT: 

 

The result of this exponentiation as an :class:`ExponentialGrowthElement`. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup 

sage: P = GrowthGroup('ZZ^x') 

sage: a = P(7^x); a 

7^x 

sage: b = a^(1/2); b 

sqrt(7)^x 

sage: b.parent() 

Growth Group SR^x 

sage: b^12 

117649^x 

""" 

return self.parent()._create_element_in_extension_(self.base ** exponent) 

 

def _log_factor_(self, base=None): 

r""" 

Helper method for calculating the logarithm of the factorization 

of this element. 

 

INPUT: 

 

- ``base`` -- the base of the logarithm. If ``None`` 

(default value) is used, the natural logarithm is taken. 

 

OUTPUT: 

 

A tuple of pairs, where the first entry is either a growth 

element or something out of which we can construct a growth element 

and the second is a multiplicative coefficient. 

 

TESTS:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup 

sage: G = GrowthGroup('QQ^x') 

sage: G('4^x').log_factor(base=2) # indirect doctest 

Traceback (most recent call last): 

... 

ArithmeticError: Cannot build log(4^x, base=2) since x is not in 

Growth Group QQ^x. 

""" 

if self.is_one(): 

return tuple() 

b = self.base 

if base is None and hasattr(b, 'is_monomial') and b.is_monomial() and \ 

b.variable_name() == 'e': 

coefficient = b.valuation() 

elif base is None and str(b) == 'e': 

coefficient = self.parent().base().one() 

else: 

from sage.functions.log import log 

coefficient = log(b, base=base) 

 

return ((str(self.parent()._var_), coefficient),) 

 

def _lt_(self, other): 

r""" 

Return whether this :class:`ExponentialGrowthElement` is 

less than ``other``. 

 

INPUT: 

 

- ``other`` -- a :class:`ExponentialGrowthElement` 

 

OUTPUT: 

 

A boolean. 

 

.. NOTE:: 

 

This function compares two instances of 

:class:`ExponentialGrowthElement`. 

 

TESTS:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup 

sage: P_ZZ = GrowthGroup('ZZ^x') 

sage: P_SR = GrowthGroup('SR^x') 

sage: P_ZZ(2^x) <= P_SR(sqrt(3)^x)^2 # indirect doctest 

True 

 

Check that :trac:`19999` is fixed:: 

 

sage: P_ZZ((-2)^x) <= P_ZZ(2^x) or P_ZZ(2^x) <= P_ZZ((-2)^x) 

False 

""" 

return bool(abs(self.base) < abs(other.base)) 

 

def _substitute_(self, rules): 

r""" 

Substitute the given ``rules`` in this exponential growth element. 

 

INPUT: 

 

- ``rules`` -- a dictionary. 

The neutral element of the group is replaced by the value 

to key ``'_one_'``. 

 

OUTPUT: 

 

An object. 

 

TESTS:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup 

sage: G = GrowthGroup('QQ^x') 

sage: G((1/2)^x)._substitute_({'x': SR.var('z')}) 

(1/2)^z 

sage: _.parent() 

Symbolic Ring 

sage: G((1/2)^x)._substitute_({'x': 2}) 

1/4 

sage: _.parent() 

Rational Field 

sage: G(1)._substitute_({'_one_': 'one'}) 

'one' 

""" 

if self.is_one(): 

return rules['_one_'] 

try: 

return self.base ** self.parent()._var_._substitute_(rules) 

except (ArithmeticError, TypeError, ValueError) as e: 

from .misc import substitute_raise_exception 

substitute_raise_exception(self, e) 

 

 

class ExponentialGrowthGroup(GenericGrowthGroup): 

r""" 

A growth group dealing with expressions involving a fixed 

variable/symbol as the exponent. 

 

The elements :class:`ExponentialGrowthElement` of this group 

represent exponential functions with bases from a fixed base 

ring; the group law is the multiplication. 

 

INPUT: 

 

- ``base`` -- one of SageMath's parents, out of which the elements 

get their data (``raw_element``). 

 

As exponential expressions are represented by this group, 

the elements in ``base`` are the bases of these exponentials. 

 

- ``var`` -- an object. 

 

The string representation of ``var`` acts as an exponent of the 

elements represented by this group. 

 

- ``category`` -- (default: ``None``) the category of the newly 

created growth group. It has to be a subcategory of ``Join of 

Category of groups and Category of posets``. This is also the 

default category if ``None`` is specified. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.growth_group import ExponentialGrowthGroup 

sage: P = ExponentialGrowthGroup(QQ, 'x'); P 

Growth Group QQ^x 

 

.. SEEALSO:: 

 

:class:`GenericGrowthGroup` 

""" 

 

# enable the category framework for elements 

Element = ExponentialGrowthElement 

 

# set everything up to determine category 

from sage.categories.sets_cat import Sets 

from sage.categories.posets import Posets 

from sage.categories.magmas import Magmas 

from sage.categories.groups import Groups 

from sage.categories.division_rings import DivisionRings 

 

_determine_category_subcategory_mapping_ = [ 

(Sets(), Sets(), True), 

(Posets(), Posets(), False), 

(Magmas(), Magmas(), False), 

(DivisionRings(), Groups(), False)] 

 

_determine_category_axiom_mapping_ = [ 

('Associative', 'Associative', False), 

('Unital', 'Unital', False), 

('Inverse', 'Inverse', False), 

('Commutative', 'Commutative', False)] 

 

def _repr_short_(self): 

r""" 

A short representation string of this exponential growth group. 

 

INPUT: 

 

Nothing. 

 

OUTPUT: 

 

A string. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.growth_group import ExponentialGrowthGroup 

sage: ExponentialGrowthGroup(QQ, 'a') # indirect doctest 

Growth Group QQ^a 

 

 

TESTS:: 

 

sage: ExponentialGrowthGroup(QQ, 'a')._repr_short_() 

'QQ^a' 

sage: ExponentialGrowthGroup(PolynomialRing(QQ, 'x'), 'a')._repr_short_() 

'QQ[x]^a' 

""" 

from .misc import parent_to_repr_short, repr_op 

return repr_op(parent_to_repr_short(self.base()), '^', self._var_) 

 

def _convert_(self, data): 

r""" 

Converts given ``data`` to something the constructor of the 

element class accepts (``raw_element``). 

 

INPUT: 

 

- ``data`` -- an object. 

 

OUTPUT: 

 

An element of the base ring or ``None`` (when no such element 

can be constructed). 

 

TESTS:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup 

sage: P = GrowthGroup('QQ^x') 

sage: P._convert_('icecream') is None 

True 

sage: P(1) # indirect doctest 

1 

sage: P('2^x') # indirect doctest 

2^x 

 

:: 

 

sage: P(2^x) # indirect doctest 

2^x 

sage: P((-333)^x) # indirect doctest 

(-333)^x 

sage: P(0) # indirect doctest 

Traceback (most recent call last): 

... 

ValueError: 0 is not in Growth Group QQ^x. 

 

:: 

 

sage: P('7^x') 

7^x 

sage: P('(-2)^x') 

(-2)^x 

 

:: 

 

sage: P = GrowthGroup('SR^x') 

sage: P(sqrt(3)^x) 

sqrt(3)^x 

sage: P((3^(1/3))^x) 

(3^(1/3))^x 

sage: P(e^x) 

e^x 

sage: P(exp(2*x)) 

(e^2)^x 

 

:: 

 

sage: GrowthGroup('QQ^x')(GrowthGroup('ZZ^x')(1)) 

1 

""" 

if data == '1' or isinstance(data, int) and data == 1: 

return self.base().one() 

var = repr(self._var_) 

try: 

P = data.parent() 

except AttributeError: 

if data == 1: 

return self.base().one() 

s = str(data) 

if var not in s: 

return # this has to end here 

 

elif s.endswith('^' + var): 

return self.base()(s.replace('^' + var, '') 

.replace('(', '').replace(')', '')) 

else: 

return # end of parsing 

 

import operator 

from sage.functions.log import Function_exp 

from sage.symbolic.operators import mul_vararg 

from sage.symbolic.ring import SymbolicRing 

 

if isinstance(P, SymbolicRing): 

op = data.operator() 

if op == operator.pow: 

base, exponent = data.operands() 

if str(exponent) == var: 

return base 

elif exponent.operator() == mul_vararg: 

return base ** (exponent / P(var)) 

elif isinstance(op, Function_exp): 

from sage.functions.log import exp 

base = exp(1) 

exponent = data.operands()[0] 

if str(exponent) == var: 

return base 

elif exponent.operator() == mul_vararg: 

return base ** (exponent / P(var)) 

 

elif data == 1: # can be expensive, so let's put it at the end 

return self.base().one() 

 

def some_elements(self): 

r""" 

Return some elements of this exponential growth group. 

 

See :class:`TestSuite` for a typical use case. 

 

INPUT: 

 

Nothing. 

 

OUTPUT: 

 

An iterator. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup 

sage: tuple(GrowthGroup('QQ^z').some_elements()) 

((1/2)^z, (-1/2)^z, 2^z, (-2)^z, 1, (-1)^z, 

42^z, (2/3)^z, (-2/3)^z, (3/2)^z, (-3/2)^z, ...) 

""" 

return iter(self.element_class(self, e) 

for e in self.base().some_elements() if e != 0) 

 

def gens(self): 

r""" 

Return a tuple of all generators of this exponential growth 

group. 

 

INPUT: 

 

Nothing. 

 

OUTPUT: 

 

An empty tuple. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup 

sage: E = GrowthGroup('ZZ^x') 

sage: E.gens() 

() 

""" 

return tuple() 

 

def construction(self): 

r""" 

Return the construction of this growth group. 

 

OUTPUT: 

 

A pair whose first entry is an 

:class:`exponential construction functor <ExponentialGrowthGroupFunctor>` 

and its second entry the base. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup 

sage: GrowthGroup('QQ^x').construction() 

(ExponentialGrowthGroup[x], Rational Field) 

""" 

return ExponentialGrowthGroupFunctor(self._var_), self.base() 

 

 

class ExponentialGrowthGroupFunctor(AbstractGrowthGroupFunctor): 

r""" 

A :class:`construction functor <sage.categories.pushout.ConstructionFunctor>` 

for :class:`exponential growth groups <ExponentialGrowthGroup>`. 

 

INPUT: 

 

- ``var`` -- a string or list of strings (or anything else 

:class:`Variable` accepts). 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup, ExponentialGrowthGroupFunctor 

sage: GrowthGroup('QQ^z').construction()[0] 

ExponentialGrowthGroup[z] 

 

.. SEEALSO:: 

 

:doc:`asymptotic_ring`, 

:class:`AbstractGrowthGroupFunctor`, 

:class:`MonomialGrowthGroupFunctor`, 

:class:`sage.rings.asymptotic.asymptotic_ring.AsymptoticRingFunctor`, 

:class:`sage.categories.pushout.ConstructionFunctor`. 

 

TESTS:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup, ExponentialGrowthGroupFunctor 

sage: cm = sage.structure.element.get_coercion_model() 

sage: A = GrowthGroup('QQ^x') 

sage: B = ExponentialGrowthGroupFunctor('x')(ZZ['t']) 

sage: cm.common_parent(A, B) 

Growth Group QQ[t]^x 

""" 

 

_functor_name = 'ExponentialGrowthGroup' 

 

def __init__(self, var): 

r""" 

See :class:`ExponentialGrowthGroupFunctor` for details. 

 

TESTS:: 

 

sage: from sage.rings.asymptotic.growth_group import ExponentialGrowthGroupFunctor 

sage: ExponentialGrowthGroupFunctor('x') 

ExponentialGrowthGroup[x] 

""" 

from sage.categories.monoids import Monoids 

 

super(ExponentialGrowthGroupFunctor, self).__init__(var, 

Monoids()) 

 

def _apply_functor(self, base): 

r""" 

Apply this functor to the given ``base``. 

 

INPUT: 

 

- ``base`` - anything :class:`ExponentialGrowthGroup` accepts. 

 

OUTPUT: 

 

An exponential growth group. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup 

sage: F, R = GrowthGroup('QQ^z').construction() 

sage: F(R) # indirect doctest 

Growth Group QQ^z 

""" 

return ExponentialGrowthGroup(base, self.var) 

 

 

class GrowthGroupFactory(UniqueFactory): 

r""" 

A factory creating asymptotic growth groups. 

 

INPUT: 

 

- ``specification`` -- a string. 

 

- keyword arguments are passed on to the growth group 

constructor. 

If the keyword ``ignore_variables`` is not specified, then 

``ignore_variables=('e',)`` (to ignore ``e`` as a variable name) 

is used. 

 

OUTPUT: 

 

An asymptotic growth group. 

 

.. NOTE:: 

 

An instance of this factory is available as ``GrowthGroup``. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup 

sage: GrowthGroup('x^ZZ') 

Growth Group x^ZZ 

sage: GrowthGroup('log(x)^QQ') 

Growth Group log(x)^QQ 

 

This factory can also be used to construct Cartesian products 

of growth groups:: 

 

sage: GrowthGroup('x^ZZ * y^ZZ') 

Growth Group x^ZZ * y^ZZ 

sage: GrowthGroup('x^ZZ * log(x)^ZZ') 

Growth Group x^ZZ * log(x)^ZZ 

sage: GrowthGroup('x^ZZ * log(x)^ZZ * y^QQ') 

Growth Group x^ZZ * log(x)^ZZ * y^QQ 

sage: GrowthGroup('QQ^x * x^ZZ * y^QQ * QQ^z') 

Growth Group QQ^x * x^ZZ * y^QQ * QQ^z 

sage: GrowthGroup('exp(x)^ZZ * x^ZZ') 

Growth Group exp(x)^ZZ * x^ZZ 

sage: GrowthGroup('(e^x)^ZZ * x^ZZ') 

Growth Group (e^x)^ZZ * x^ZZ 

 

TESTS:: 

 

sage: G = GrowthGroup('(e^(n*log(n)))^ZZ') 

sage: G, G._var_ 

(Growth Group (e^(n*log(n)))^ZZ, e^(n*log(n))) 

sage: G = GrowthGroup('(e^n)^ZZ') 

sage: G, G._var_ 

(Growth Group (e^n)^ZZ, e^n) 

sage: G = GrowthGroup('(e^(n*log(n)))^ZZ * (e^n)^ZZ * n^ZZ * log(n)^ZZ') 

sage: G, tuple(F._var_ for F in G.cartesian_factors()) 

(Growth Group (e^(n*log(n)))^ZZ * (e^n)^ZZ * n^ZZ * log(n)^ZZ, 

(e^(n*log(n)), e^n, n, log(n))) 

 

sage: TestSuite(GrowthGroup('x^ZZ')).run(verbose=True) # long time 

running ._test_an_element() . . . pass 

running ._test_associativity() . . . pass 

running ._test_cardinality() . . . pass 

running ._test_category() . . . pass 

running ._test_elements() . . . 

Running the test suite of self.an_element() 

running ._test_category() . . . pass 

running ._test_eq() . . . pass 

running ._test_new() . . . pass 

running ._test_not_implemented_methods() . . . pass 

running ._test_pickling() . . . pass 

pass 

running ._test_elements_eq_reflexive() . . . pass 

running ._test_elements_eq_symmetric() . . . pass 

running ._test_elements_eq_transitive() . . . pass 

running ._test_elements_neq() . . . pass 

running ._test_eq() . . . pass 

running ._test_inverse() . . . pass 

running ._test_new() . . . pass 

running ._test_not_implemented_methods() . . . pass 

running ._test_one() . . . pass 

running ._test_pickling() . . . pass 

running ._test_prod() . . . pass 

running ._test_some_elements() . . . pass 

 

:: 

 

sage: TestSuite(GrowthGroup('QQ^y')).run(verbose=True) # long time 

running ._test_an_element() . . . pass 

running ._test_associativity() . . . pass 

running ._test_cardinality() . . . pass 

running ._test_category() . . . pass 

running ._test_elements() . . . 

Running the test suite of self.an_element() 

running ._test_category() . . . pass 

running ._test_eq() . . . pass 

running ._test_new() . . . pass 

running ._test_not_implemented_methods() . . . pass 

running ._test_pickling() . . . pass 

pass 

running ._test_elements_eq_reflexive() . . . pass 

running ._test_elements_eq_symmetric() . . . pass 

running ._test_elements_eq_transitive() . . . pass 

running ._test_elements_neq() . . . pass 

running ._test_eq() . . . pass 

running ._test_inverse() . . . pass 

running ._test_new() . . . pass 

running ._test_not_implemented_methods() . . . pass 

running ._test_one() . . . pass 

running ._test_pickling() . . . pass 

running ._test_prod() . . . pass 

running ._test_some_elements() . . . pass 

 

:: 

 

sage: TestSuite(GrowthGroup('x^QQ * log(x)^ZZ')).run(verbose=True) # long time 

running ._test_an_element() . . . pass 

running ._test_associativity() . . . pass 

running ._test_cardinality() . . . pass 

running ._test_category() . . . pass 

running ._test_elements() . . . 

Running the test suite of self.an_element() 

running ._test_category() . . . pass 

running ._test_eq() . . . pass 

running ._test_new() . . . pass 

running ._test_not_implemented_methods() . . . pass 

running ._test_pickling() . . . pass 

pass 

running ._test_elements_eq_reflexive() . . . pass 

running ._test_elements_eq_symmetric() . . . pass 

running ._test_elements_eq_transitive() . . . pass 

running ._test_elements_neq() . . . pass 

running ._test_eq() . . . pass 

running ._test_inverse() . . . pass 

running ._test_new() . . . pass 

running ._test_not_implemented_methods() . . . pass 

running ._test_one() . . . pass 

running ._test_pickling() . . . pass 

running ._test_prod() . . . pass 

running ._test_some_elements() . . . pass 

""" 

 

def create_key_and_extra_args(self, specification, **kwds): 

r""" 

Given the arguments and keyword, create a key that uniquely 

determines this object. 

 

TESTS:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup 

sage: GrowthGroup.create_key_and_extra_args('asdf') 

Traceback (most recent call last): 

... 

ValueError: 'asdf' is not a valid substring of 'asdf' describing a growth group. 

""" 

from .misc import split_str_by_op 

factors = split_str_by_op(specification, '*') 

factors = tuple(f.replace('**', '^') for f in factors) 

 

for f in factors: 

if '^' not in f: 

raise ValueError("'%s' is not a valid substring of '%s' describing " 

"a growth group." % (f, specification)) 

 

kwds.setdefault('ignore_variables', ('e',)) 

 

return factors, kwds 

 

def create_object(self, version, factors, **kwds): 

r""" 

Create an object from the given arguments. 

 

TESTS:: 

 

sage: from sage.rings.asymptotic.growth_group import GrowthGroup 

sage: GrowthGroup('as^df') # indirect doctest 

Traceback (most recent call last): 

... 

ValueError: 'as^df' is not a valid substring of as^df 

describing a growth group. 

> *previous* ValueError: Cannot create a parent out of 'as'. 

>> *previous* SyntaxError: unexpected EOF while parsing (<string>, line 1) 

> *and* ValueError: Cannot create a parent out of 'df'. 

>> *previous* NameError: name 'df' is not defined 

sage: GrowthGroup('x^y^z') 

Traceback (most recent call last): 

... 

ValueError: 'x^y^z' is an ambigous substring of 

a growth group description of 'x^y^z'. 

Use parentheses to make it unique. 

sage: GrowthGroup('(x^y)^z') 

Traceback (most recent call last): 

... 

ValueError: '(x^y)^z' is not a valid substring of (x^y)^z 

describing a growth group. 

> *previous* ValueError: Cannot create a parent out of 'x^y'. 

>> *previous* NameError: name 'x' is not defined 

> *and* ValueError: Cannot create a parent out of 'z'. 

>> *previous* NameError: name 'z' is not defined 

sage: GrowthGroup('x^(y^z)') 

Traceback (most recent call last): 

... 

ValueError: 'x^(y^z)' is not a valid substring of x^(y^z) 

describing a growth group. 

> *previous* ValueError: Cannot create a parent out of 'x'. 

>> *previous* NameError: name 'x' is not defined 

> *and* ValueError: Cannot create a parent out of 'y^z'. 

>> *previous* NameError: name 'y' is not defined 

""" 

from .misc import repr_short_to_parent, split_str_by_op 

groups = [] 

for factor in factors: 

split = split_str_by_op(factor, '^') 

if len(split) != 2: 

raise ValueError("'%s' is an ambigous substring of a growth group " 

"description of '%s'. Use parentheses to make it " 

"unique." % (factor, ' * '.join(factors))) 

 

b, e = split 

try: 

B = repr_short_to_parent(b) 

except ValueError as exc_b: 

B = None 

try: 

E = repr_short_to_parent(e) 

except ValueError as exc_e: 

E = None 

 

if B is None and E is None: 

from .misc import combine_exceptions 

raise combine_exceptions( 

ValueError("'%s' is not a valid substring of %s describing " 

"a growth group." % (factor, ' * '.join(factors))), 

exc_b, exc_e) 

elif B is None and E is not None: 

groups.append(MonomialGrowthGroup(E, b, **kwds)) 

elif B is not None and E is None: 

groups.append(ExponentialGrowthGroup(B, e, **kwds)) 

else: 

raise ValueError("'%s' is an ambigous substring of a growth group " 

"description of '%s'." % (factor, ' * '.join(factors))) 

 

if len(groups) == 1: 

return groups[0] 

 

from sage.categories.cartesian_product import cartesian_product 

return cartesian_product(groups) 

 

 

GrowthGroup = GrowthGroupFactory("GrowthGroup") 

r""" 

A factory for growth groups. 

This is an instance of :class:`GrowthGroupFactory` whose documentation 

provides more details. 

"""