Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

286

287

288

289

290

291

292

293

294

295

296

297

298

299

300

301

302

303

304

305

306

307

308

309

310

311

312

313

314

315

316

317

318

319

320

321

322

323

324

325

326

327

328

329

330

331

332

333

334

335

336

337

338

339

340

341

342

343

344

345

346

347

348

349

350

351

352

353

354

355

356

357

358

359

360

361

362

363

364

365

366

367

368

369

370

371

372

373

374

375

376

377

378

379

380

381

382

383

384

385

386

387

388

389

390

391

392

393

394

395

396

397

398

399

400

401

402

403

404

405

406

407

408

409

410

411

412

413

414

415

416

417

418

419

420

421

422

423

424

425

426

427

428

429

430

431

432

433

434

435

436

437

438

439

440

441

442

443

444

445

446

447

448

449

450

451

452

453

454

455

456

457

458

459

460

461

462

463

464

465

466

467

468

469

470

471

472

473

474

475

476

477

478

479

480

481

482

483

484

485

486

487

488

489

490

491

492

493

494

495

496

497

498

499

500

501

502

503

504

505

506

507

508

509

510

511

512

513

514

515

516

517

518

519

520

521

522

523

524

525

526

527

528

529

530

531

532

533

534

535

536

537

538

539

540

541

542

543

544

545

546

547

548

549

550

551

552

553

554

555

556

557

558

559

560

561

562

563

564

565

566

567

568

569

570

571

572

573

574

575

576

577

578

579

580

581

582

583

584

585

586

587

588

589

590

591

592

593

594

595

596

597

598

599

600

601

602

603

604

605

606

607

608

609

610

611

612

613

614

615

616

617

618

619

620

621

622

623

624

625

626

627

628

629

630

631

632

633

634

635

636

637

638

639

640

641

642

643

644

645

646

647

648

649

650

651

652

653

654

655

656

657

658

659

660

661

662

663

664

665

666

667

668

669

670

671

672

673

674

675

676

677

678

679

680

681

682

683

684

685

686

687

688

689

690

691

692

693

694

695

696

697

698

699

700

701

702

703

704

705

706

707

708

709

710

711

712

713

714

715

716

717

718

719

720

721

722

723

724

725

726

727

728

729

730

731

732

733

734

735

736

737

738

739

740

741

742

743

744

745

746

747

748

749

750

751

752

753

754

755

756

757

758

759

760

761

762

763

764

765

766

767

768

769

770

771

772

773

774

775

776

777

778

779

780

781

782

783

784

785

786

787

788

789

790

791

792

793

794

795

796

797

798

799

800

801

802

803

804

805

806

807

808

809

810

811

812

813

814

815

816

817

818

819

820

821

822

823

824

825

826

827

828

829

830

831

832

833

834

835

836

837

838

839

840

841

842

843

844

845

846

847

848

849

850

851

852

853

854

855

856

857

858

859

860

861

862

863

864

865

866

867

868

869

870

871

872

873

874

875

876

877

878

879

880

881

882

883

884

885

886

887

888

889

890

891

892

893

894

895

896

897

898

899

900

901

902

903

904

905

906

907

908

909

910

911

912

913

914

915

916

917

918

919

920

921

922

923

924

925

926

927

928

929

930

931

932

933

934

935

936

937

938

939

940

941

942

943

944

945

946

947

948

949

950

951

952

953

954

955

956

957

958

959

960

961

962

963

964

965

966

967

968

969

970

971

972

973

974

975

976

977

978

979

980

981

982

983

984

985

986

987

988

989

990

991

992

993

994

995

996

997

998

999

1000

1001

1002

1003

1004

1005

1006

1007

1008

1009

1010

1011

1012

1013

1014

1015

1016

1017

1018

1019

1020

1021

1022

1023

1024

1025

1026

1027

1028

1029

1030

1031

1032

1033

1034

1035

1036

1037

1038

1039

1040

1041

1042

1043

1044

1045

1046

1047

1048

1049

1050

1051

1052

1053

1054

1055

1056

1057

1058

1059

1060

1061

1062

1063

1064

1065

1066

1067

1068

1069

1070

1071

1072

1073

1074

1075

1076

1077

1078

1079

1080

1081

1082

1083

1084

1085

1086

1087

1088

1089

1090

1091

1092

1093

1094

1095

1096

1097

1098

1099

1100

1101

1102

1103

1104

1105

1106

1107

1108

1109

1110

1111

1112

1113

1114

1115

1116

1117

1118

1119

1120

1121

1122

1123

1124

1125

1126

1127

1128

1129

1130

1131

1132

1133

1134

1135

1136

1137

1138

1139

1140

1141

1142

1143

1144

1145

1146

1147

1148

1149

1150

1151

1152

1153

1154

1155

1156

1157

1158

1159

1160

1161

1162

1163

1164

1165

1166

1167

1168

1169

1170

1171

1172

1173

1174

1175

1176

1177

1178

1179

1180

1181

1182

1183

1184

1185

1186

1187

1188

1189

1190

1191

1192

1193

1194

1195

1196

1197

1198

1199

1200

1201

1202

1203

1204

1205

1206

1207

1208

1209

1210

1211

1212

1213

1214

1215

1216

1217

1218

1219

1220

1221

1222

1223

1224

1225

1226

1227

1228

1229

1230

1231

1232

1233

1234

1235

1236

1237

1238

1239

1240

1241

1242

1243

1244

1245

1246

1247

1248

1249

1250

1251

1252

1253

1254

1255

1256

1257

1258

1259

1260

1261

1262

1263

1264

1265

1266

1267

1268

1269

1270

1271

1272

1273

1274

1275

1276

1277

1278

1279

1280

1281

1282

1283

1284

1285

1286

1287

1288

1289

1290

1291

1292

1293

1294

1295

1296

1297

1298

1299

1300

1301

1302

1303

1304

1305

1306

1307

1308

1309

1310

1311

1312

1313

1314

1315

1316

1317

1318

1319

1320

1321

1322

1323

1324

1325

1326

1327

1328

1329

1330

1331

1332

1333

1334

1335

1336

1337

1338

1339

1340

1341

1342

1343

1344

1345

1346

1347

1348

1349

1350

1351

1352

1353

1354

1355

1356

1357

1358

1359

1360

1361

1362

1363

1364

1365

1366

1367

1368

1369

1370

1371

1372

1373

1374

1375

1376

1377

1378

1379

1380

1381

1382

1383

1384

1385

1386

1387

1388

1389

1390

1391

1392

1393

1394

1395

1396

1397

1398

1399

1400

1401

1402

1403

1404

1405

1406

1407

1408

1409

1410

1411

1412

1413

1414

1415

1416

1417

1418

1419

1420

1421

1422

1423

1424

1425

1426

1427

1428

1429

1430

1431

1432

1433

1434

1435

1436

1437

1438

1439

1440

1441

1442

1443

1444

1445

1446

1447

1448

1449

1450

1451

1452

1453

1454

1455

1456

1457

1458

1459

1460

1461

1462

1463

1464

1465

1466

1467

1468

1469

1470

1471

1472

1473

1474

1475

1476

1477

1478

1479

1480

1481

1482

1483

1484

1485

1486

1487

1488

1489

1490

1491

1492

1493

1494

1495

1496

1497

1498

1499

1500

1501

1502

1503

1504

1505

1506

1507

1508

1509

1510

1511

1512

1513

1514

1515

1516

1517

1518

1519

1520

1521

1522

1523

1524

1525

1526

1527

1528

1529

1530

1531

1532

1533

1534

1535

1536

1537

1538

1539

1540

1541

1542

1543

1544

1545

1546

1547

1548

1549

1550

1551

1552

1553

1554

1555

1556

1557

1558

1559

1560

1561

1562

1563

1564

1565

1566

1567

1568

1569

1570

1571

1572

1573

1574

1575

1576

1577

1578

1579

1580

1581

1582

1583

1584

1585

1586

1587

1588

1589

1590

1591

1592

1593

1594

1595

1596

1597

1598

1599

1600

1601

1602

1603

1604

1605

1606

1607

1608

1609

1610

1611

1612

1613

1614

1615

1616

1617

1618

1619

1620

1621

1622

1623

1624

1625

1626

1627

1628

1629

1630

1631

1632

1633

1634

1635

1636

1637

1638

1639

1640

1641

1642

1643

1644

1645

1646

1647

1648

1649

1650

1651

1652

1653

1654

1655

1656

1657

1658

1659

1660

1661

1662

1663

1664

1665

1666

1667

1668

1669

1670

1671

1672

1673

1674

1675

1676

1677

1678

1679

1680

1681

1682

1683

1684

1685

1686

1687

1688

1689

1690

1691

1692

1693

1694

1695

1696

1697

1698

1699

1700

1701

1702

1703

1704

1705

1706

1707

1708

1709

1710

1711

1712

1713

1714

1715

1716

1717

1718

1719

1720

1721

1722

1723

1724

1725

1726

1727

1728

1729

1730

1731

1732

1733

1734

1735

1736

1737

1738

1739

1740

1741

1742

1743

1744

1745

1746

1747

1748

1749

1750

1751

1752

1753

1754

1755

1756

1757

1758

1759

1760

1761

1762

1763

1764

1765

1766

1767

1768

1769

1770

1771

1772

1773

1774

1775

1776

1777

1778

1779

1780

1781

1782

1783

1784

1785

1786

1787

1788

1789

1790

1791

1792

1793

1794

1795

1796

1797

1798

1799

1800

1801

1802

1803

1804

1805

1806

1807

1808

1809

1810

1811

1812

1813

1814

1815

1816

1817

1818

1819

1820

1821

1822

1823

1824

1825

1826

1827

1828

1829

1830

1831

1832

1833

1834

1835

1836

1837

1838

1839

1840

1841

1842

1843

1844

1845

1846

1847

1848

1849

1850

1851

1852

1853

1854

1855

1856

1857

1858

1859

1860

1861

1862

1863

1864

1865

1866

1867

1868

1869

1870

1871

1872

1873

1874

1875

1876

1877

1878

1879

1880

1881

1882

1883

1884

1885

1886

1887

1888

1889

1890

1891

1892

1893

1894

1895

1896

1897

1898

1899

1900

1901

1902

1903

1904

1905

1906

1907

1908

1909

1910

1911

1912

1913

1914

1915

1916

1917

1918

1919

1920

1921

1922

1923

1924

1925

1926

1927

1928

1929

1930

1931

1932

1933

1934

1935

1936

1937

1938

1939

1940

1941

1942

1943

1944

1945

1946

1947

1948

1949

1950

1951

1952

1953

1954

1955

1956

1957

1958

1959

1960

1961

1962

1963

1964

1965

1966

1967

1968

1969

1970

1971

1972

1973

1974

1975

1976

1977

1978

1979

1980

1981

1982

1983

1984

1985

1986

1987

1988

1989

1990

1991

1992

1993

1994

1995

1996

1997

1998

1999

2000

2001

2002

2003

2004

2005

2006

2007

2008

2009

2010

2011

2012

2013

2014

2015

2016

2017

2018

2019

2020

2021

2022

2023

2024

2025

2026

2027

2028

2029

2030

2031

2032

2033

2034

2035

2036

2037

2038

2039

2040

2041

2042

2043

2044

2045

2046

2047

2048

2049

2050

2051

2052

2053

2054

2055

2056

2057

2058

2059

2060

2061

2062

2063

2064

2065

2066

2067

2068

2069

2070

2071

2072

2073

2074

2075

2076

2077

2078

2079

2080

2081

2082

2083

2084

2085

2086

2087

2088

2089

2090

2091

2092

2093

2094

2095

2096

2097

2098

2099

2100

2101

2102

2103

2104

2105

2106

2107

2108

2109

2110

2111

2112

2113

2114

2115

2116

2117

2118

2119

2120

2121

2122

2123

2124

2125

2126

2127

2128

2129

2130

2131

2132

2133

2134

2135

2136

2137

2138

2139

2140

2141

2142

2143

2144

2145

2146

2147

2148

2149

2150

2151

2152

2153

2154

2155

2156

2157

2158

2159

2160

2161

2162

2163

2164

2165

2166

2167

2168

2169

2170

2171

2172

2173

2174

2175

2176

2177

2178

2179

2180

2181

2182

2183

2184

2185

2186

2187

2188

2189

2190

2191

2192

2193

2194

2195

2196

2197

2198

2199

2200

2201

2202

2203

2204

2205

2206

2207

2208

2209

2210

2211

2212

2213

2214

2215

2216

2217

2218

2219

2220

2221

2222

2223

2224

2225

2226

2227

2228

2229

2230

2231

2232

2233

2234

2235

2236

2237

2238

2239

2240

2241

2242

2243

2244

2245

2246

2247

2248

2249

2250

2251

2252

2253

2254

2255

2256

2257

2258

2259

2260

2261

2262

2263

2264

2265

2266

2267

2268

2269

2270

2271

2272

2273

2274

2275

2276

2277

2278

2279

2280

2281

2282

2283

2284

2285

2286

2287

2288

2289

2290

2291

2292

2293

2294

2295

2296

2297

2298

2299

2300

2301

2302

2303

2304

2305

2306

2307

2308

2309

2310

2311

2312

2313

2314

2315

2316

2317

2318

2319

2320

2321

2322

2323

2324

2325

2326

2327

2328

2329

2330

2331

2332

2333

2334

2335

2336

2337

2338

2339

2340

2341

2342

2343

2344

2345

2346

2347

2348

2349

2350

2351

2352

2353

2354

2355

2356

2357

2358

2359

2360

2361

2362

2363

2364

2365

2366

2367

2368

2369

2370

2371

2372

2373

2374

2375

2376

2377

2378

2379

2380

2381

2382

2383

2384

2385

2386

2387

2388

2389

2390

2391

2392

2393

2394

2395

2396

2397

2398

2399

2400

2401

2402

2403

2404

2405

2406

2407

2408

2409

2410

2411

2412

2413

2414

2415

2416

2417

2418

2419

2420

2421

2422

2423

2424

2425

2426

2427

2428

2429

2430

2431

2432

2433

2434

2435

2436

2437

2438

2439

2440

2441

2442

2443

2444

2445

2446

2447

2448

2449

2450

2451

2452

2453

2454

2455

2456

2457

2458

2459

2460

2461

2462

2463

2464

2465

2466

2467

2468

2469

2470

2471

2472

2473

2474

2475

2476

2477

2478

2479

2480

2481

2482

2483

2484

2485

2486

2487

2488

2489

2490

2491

2492

2493

2494

2495

2496

2497

2498

2499

2500

2501

2502

2503

2504

2505

2506

2507

2508

2509

2510

2511

2512

2513

2514

2515

2516

2517

2518

2519

2520

2521

2522

2523

2524

2525

2526

2527

2528

2529

2530

2531

2532

2533

2534

2535

2536

2537

2538

2539

2540

2541

2542

2543

2544

2545

2546

2547

2548

2549

2550

2551

2552

2553

2554

2555

2556

2557

2558

2559

2560

2561

2562

2563

2564

2565

2566

2567

2568

2569

2570

2571

2572

2573

2574

2575

2576

2577

2578

2579

2580

2581

2582

2583

2584

2585

2586

2587

2588

2589

2590

2591

2592

2593

2594

2595

2596

2597

2598

2599

2600

2601

2602

2603

2604

2605

2606

2607

2608

2609

2610

2611

2612

2613

2614

2615

2616

2617

2618

2619

2620

2621

2622

2623

2624

2625

2626

2627

2628

2629

2630

2631

2632

2633

2634

2635

2636

2637

2638

2639

2640

2641

2642

2643

2644

2645

2646

2647

2648

2649

2650

2651

2652

2653

2654

2655

2656

2657

2658

2659

2660

2661

2662

2663

2664

2665

2666

2667

2668

2669

2670

2671

2672

2673

2674

2675

2676

2677

2678

2679

2680

2681

2682

2683

2684

2685

2686

2687

2688

2689

2690

2691

2692

2693

2694

2695

2696

2697

2698

2699

2700

2701

2702

2703

2704

2705

2706

2707

2708

2709

2710

2711

2712

2713

2714

2715

2716

2717

2718

2719

2720

2721

2722

2723

2724

2725

2726

2727

2728

2729

2730

2731

2732

2733

2734

2735

2736

2737

2738

2739

2740

2741

2742

2743

2744

2745

2746

2747

2748

2749

2750

2751

2752

2753

2754

2755

2756

2757

2758

2759

2760

2761

2762

2763

2764

2765

2766

2767

2768

2769

2770

2771

2772

2773

2774

2775

2776

2777

2778

2779

2780

2781

2782

2783

2784

2785

2786

2787

2788

2789

2790

2791

2792

2793

2794

2795

2796

2797

2798

2799

2800

2801

2802

2803

2804

2805

2806

2807

2808

2809

2810

2811

2812

2813

2814

2815

2816

2817

2818

2819

2820

2821

2822

2823

2824

2825

2826

2827

2828

2829

2830

2831

2832

2833

2834

2835

2836

2837

2838

2839

2840

2841

2842

2843

2844

2845

2846

2847

2848

2849

2850

2851

2852

2853

2854

2855

2856

2857

2858

2859

2860

2861

2862

2863

2864

2865

2866

2867

2868

2869

2870

2871

2872

2873

2874

2875

2876

2877

2878

2879

2880

2881

2882

2883

2884

2885

2886

2887

2888

2889

2890

2891

2892

2893

2894

2895

2896

2897

2898

2899

2900

2901

2902

2903

2904

2905

2906

2907

2908

2909

2910

2911

2912

2913

2914

2915

2916

2917

2918

2919

2920

2921

2922

2923

2924

2925

2926

2927

2928

2929

2930

2931

2932

2933

2934

2935

2936

2937

2938

2939

2940

2941

2942

2943

2944

2945

2946

2947

2948

2949

2950

2951

2952

2953

2954

2955

2956

2957

2958

2959

2960

2961

2962

2963

2964

2965

2966

2967

2968

2969

2970

2971

2972

2973

2974

2975

2976

2977

2978

2979

2980

2981

2982

2983

2984

2985

2986

2987

2988

2989

2990

2991

2992

2993

2994

2995

2996

2997

2998

2999

3000

3001

3002

3003

3004

3005

3006

3007

3008

3009

3010

3011

3012

3013

3014

3015

3016

3017

3018

3019

3020

3021

3022

3023

3024

3025

3026

3027

3028

3029

3030

3031

3032

3033

3034

3035

3036

3037

3038

3039

3040

3041

3042

3043

3044

3045

3046

3047

3048

3049

3050

3051

3052

3053

3054

3055

3056

3057

3058

3059

3060

3061

3062

3063

3064

3065

3066

3067

3068

3069

3070

3071

3072

3073

3074

3075

3076

3077

3078

3079

3080

3081

3082

3083

3084

3085

3086

3087

3088

3089

3090

3091

3092

3093

3094

3095

3096

3097

3098

3099

3100

3101

3102

3103

3104

3105

3106

3107

3108

3109

3110

3111

3112

3113

3114

3115

3116

3117

3118

3119

3120

3121

3122

3123

3124

3125

3126

3127

3128

3129

3130

3131

3132

3133

3134

3135

3136

3137

3138

3139

3140

3141

3142

3143

3144

3145

3146

3147

3148

3149

3150

3151

3152

3153

3154

3155

3156

3157

3158

3159

3160

3161

3162

3163

3164

3165

3166

3167

3168

3169

3170

3171

3172

3173

3174

3175

3176

3177

3178

3179

3180

3181

3182

3183

3184

3185

3186

3187

3188

3189

3190

3191

3192

3193

3194

3195

3196

3197

3198

3199

3200

3201

3202

3203

3204

3205

3206

3207

3208

3209

3210

3211

3212

3213

3214

3215

3216

3217

3218

3219

3220

3221

3222

3223

3224

3225

3226

3227

3228

3229

3230

3231

3232

3233

3234

3235

3236

3237

3238

3239

3240

3241

3242

3243

3244

3245

3246

3247

3248

3249

3250

3251

3252

3253

3254

3255

3256

3257

3258

3259

3260

3261

3262

3263

3264

3265

3266

3267

3268

3269

3270

3271

3272

3273

3274

3275

3276

3277

3278

3279

3280

3281

3282

3283

3284

3285

3286

3287

3288

3289

3290

3291

3292

3293

3294

3295

3296

3297

3298

3299

3300

3301

3302

3303

3304

3305

3306

3307

3308

3309

3310

3311

3312

3313

3314

3315

3316

3317

3318

3319

3320

3321

3322

3323

3324

3325

3326

3327

3328

3329

3330

3331

3332

3333

3334

3335

3336

3337

3338

3339

3340

3341

3342

3343

3344

3345

3346

3347

3348

3349

3350

3351

3352

3353

3354

3355

3356

3357

3358

3359

3360

3361

3362

3363

3364

3365

3366

3367

3368

3369

3370

3371

3372

3373

3374

3375

3376

3377

3378

3379

3380

3381

3382

3383

3384

3385

3386

3387

3388

3389

3390

3391

3392

3393

3394

3395

3396

3397

3398

3399

3400

3401

3402

3403

3404

3405

3406

3407

3408

3409

3410

3411

3412

3413

3414

3415

3416

3417

3418

3419

3420

3421

3422

3423

3424

3425

3426

3427

3428

3429

3430

3431

3432

3433

3434

3435

3436

3437

3438

3439

3440

3441

3442

3443

3444

3445

3446

3447

3448

3449

3450

3451

3452

3453

3454

3455

3456

3457

3458

3459

3460

3461

3462

3463

3464

3465

3466

3467

3468

3469

3470

3471

3472

3473

3474

3475

3476

3477

3478

3479

3480

3481

3482

3483

3484

3485

3486

3487

3488

3489

3490

3491

3492

3493

3494

3495

3496

3497

3498

3499

3500

3501

3502

3503

3504

3505

3506

3507

3508

3509

3510

3511

3512

3513

3514

3515

3516

3517

3518

3519

3520

3521

3522

3523

3524

3525

3526

3527

3528

3529

3530

3531

3532

3533

3534

3535

3536

3537

3538

3539

3540

3541

3542

3543

3544

3545

3546

3547

3548

3549

3550

3551

3552

3553

3554

3555

3556

3557

3558

3559

3560

3561

3562

3563

3564

3565

3566

3567

3568

3569

3570

3571

3572

3573

3574

3575

3576

3577

3578

3579

3580

3581

3582

3583

3584

3585

3586

3587

3588

3589

3590

3591

3592

3593

3594

3595

3596

3597

3598

3599

3600

3601

3602

3603

3604

3605

3606

3607

3608

3609

3610

3611

3612

3613

3614

3615

3616

3617

3618

3619

3620

3621

3622

3623

3624

3625

3626

3627

3628

3629

3630

3631

3632

3633

3634

3635

3636

3637

3638

3639

3640

3641

3642

3643

3644

3645

3646

3647

3648

3649

3650

3651

3652

3653

3654

3655

3656

3657

3658

3659

3660

3661

3662

3663

3664

3665

3666

3667

3668

3669

3670

3671

3672

3673

3674

3675

3676

3677

3678

3679

3680

3681

3682

3683

3684

3685

3686

3687

3688

3689

3690

3691

3692

3693

3694

3695

3696

3697

3698

3699

3700

3701

3702

3703

3704

3705

3706

3707

3708

3709

3710

3711

3712

3713

3714

3715

3716

3717

3718

3719

3720

3721

3722

3723

3724

3725

3726

3727

3728

3729

3730

3731

3732

3733

3734

3735

3736

3737

3738

3739

3740

3741

3742

3743

3744

3745

3746

3747

3748

3749

3750

3751

3752

3753

3754

3755

3756

3757

3758

3759

3760

3761

3762

3763

3764

3765

3766

3767

3768

3769

3770

3771

3772

3773

3774

3775

3776

3777

3778

3779

3780

3781

3782

3783

3784

3785

3786

3787

3788

3789

3790

3791

3792

3793

3794

3795

3796

3797

3798

3799

3800

3801

3802

3803

3804

3805

3806

3807

3808

3809

3810

3811

3812

3813

3814

3815

3816

3817

3818

3819

3820

3821

3822

3823

3824

3825

3826

3827

3828

3829

3830

3831

3832

3833

3834

3835

3836

3837

3838

3839

3840

3841

3842

3843

3844

3845

3846

3847

3848

3849

3850

3851

3852

3853

3854

3855

3856

3857

3858

3859

3860

3861

3862

3863

3864

3865

3866

3867

3868

3869

3870

3871

3872

3873

3874

3875

3876

3877

3878

3879

3880

3881

3882

3883

3884

3885

3886

3887

3888

3889

3890

3891

3892

3893

3894

3895

3896

3897

3898

3899

3900

3901

3902

3903

3904

3905

3906

3907

3908

3909

3910

3911

3912

3913

3914

3915

3916

3917

3918

3919

3920

3921

3922

3923

3924

3925

3926

3927

3928

3929

3930

3931

3932

3933

3934

3935

3936

3937

3938

3939

3940

3941

3942

3943

3944

3945

3946

3947

3948

3949

3950

3951

3952

3953

3954

3955

3956

3957

3958

3959

3960

3961

3962

3963

3964

3965

3966

3967

3968

3969

3970

3971

3972

3973

3974

3975

3976

3977

3978

3979

3980

3981

3982

3983

3984

3985

3986

3987

3988

3989

3990

3991

3992

3993

3994

3995

3996

3997

3998

3999

4000

4001

4002

4003

4004

4005

4006

4007

4008

4009

4010

4011

4012

4013

4014

4015

4016

4017

4018

4019

4020

4021

4022

4023

4024

4025

4026

4027

4028

4029

4030

4031

4032

4033

4034

4035

4036

4037

4038

4039

4040

4041

4042

4043

4044

4045

4046

4047

4048

4049

4050

4051

4052

4053

4054

4055

4056

4057

4058

4059

4060

4061

4062

4063

4064

4065

4066

4067

4068

4069

4070

4071

4072

4073

4074

4075

4076

4077

4078

4079

4080

4081

4082

4083

4084

4085

4086

4087

4088

4089

4090

4091

4092

4093

4094

4095

4096

4097

4098

4099

4100

4101

4102

4103

4104

4105

4106

4107

4108

4109

4110

4111

4112

4113

4114

4115

4116

4117

4118

4119

4120

4121

4122

4123

4124

4125

4126

4127

4128

4129

4130

4131

4132

4133

4134

4135

4136

4137

4138

4139

4140

4141

4142

4143

4144

4145

4146

4147

4148

4149

4150

4151

4152

4153

4154

4155

4156

4157

4158

4159

4160

4161

4162

4163

4164

4165

4166

4167

4168

4169

4170

4171

4172

4173

4174

4175

4176

4177

4178

4179

4180

4181

4182

4183

4184

4185

4186

4187

4188

4189

4190

4191

4192

4193

4194

4195

4196

4197

4198

4199

4200

4201

4202

4203

4204

4205

4206

4207

4208

4209

4210

4211

4212

4213

4214

4215

4216

4217

4218

4219

4220

4221

4222

4223

4224

4225

4226

4227

4228

4229

4230

4231

4232

4233

4234

4235

4236

4237

4238

4239

4240

4241

4242

4243

4244

4245

4246

4247

4248

4249

4250

4251

4252

4253

4254

4255

4256

4257

4258

4259

4260

4261

4262

4263

4264

4265

4266

4267

4268

4269

4270

4271

4272

4273

4274

4275

4276

4277

4278

4279

4280

4281

4282

4283

4284

4285

4286

4287

4288

4289

4290

4291

4292

4293

4294

4295

4296

4297

4298

4299

4300

4301

r""" 

Asymptotics of Multivariate Generating Series 

 

Let `F(x) = \sum_{\nu \in \NN^d} F_{\nu} x^\nu` be a multivariate power series 

with complex coefficients that converges in a neighborhood of the origin. 

Assume that `F = G/H` for some functions `G` and `H` holomorphic in a 

neighborhood of the origin. Assume also that `H` is a polynomial. 

 

This computes asymptotics for the coefficients `F_{r \alpha}` as `r \to \infty` 

with `r \alpha \in \NN^d` for `\alpha` in a permissible subset of `d`-tuples of 

positive reals. More specifically, it computes arbitrary terms of the 

asymptotic expansion for `F_{r \alpha}` when the asymptotics are controlled by 

a strictly minimal multiple point of the algebraic variety `H = 0`. 

 

The algorithms and formulas implemented here come from [RaWi2008a]_ 

and [RaWi2012]_. For a general reference take a look in the book [PeWi2013]. 

 

.. [AiYu1983] \I.A. Aizenberg and A.P. Yuzhakov. 

*Integral representations and residues in multidimensional complex analysis*. 

Translations of Mathematical Monographs, **58**. American Mathematical 

Society, Providence, RI. (1983). x+283 pp. ISBN: 0-8218-4511-X. 

 

.. [Raic2012] Alexander Raichev. 

*Leinartas's partial fraction decomposition*. 

:arxiv:`1206.4740`. 

 

.. [RaWi2008a] Alexander Raichev and Mark C. Wilson. *Asymptotics of 

coefficients of multivariate generating functions: improvements for 

smooth points*, Electronic Journal of Combinatorics, Vol. 15 (2008). 

R89 :arxiv:`0803.2914`. 

 

.. [RaWi2012] Alexander Raichev and Mark C. Wilson. *Asymptotics of 

coefficients of multivariate generating functions: improvements for 

smooth points*. Online Journal of Analytic Combinatorics. 

Issue 6, (2011). :arxiv:`1009.5715`. 

 

.. [PeWi2013] Robin Pemantle and Mark C. Wilson. 

*Analytic Combinatorics in Several Variables*. 

Cambridge University Press, 2013. 

 

 

Introductory Examples 

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

 

:: 

 

sage: from sage.rings.asymptotic.asymptotics_multivariate_generating_functions import FractionWithFactoredDenominatorRing 

 

A univariate smooth point example:: 

 

sage: R.<x> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R, SR) 

sage: H = (x - 1/2)^3 

sage: Hfac = H.factor() 

sage: G = -1/(x + 3)/Hfac.unit() 

sage: F = FFPD(G, Hfac) 

sage: F 

(-1/(x + 3), [(x - 1/2, 3)]) 

sage: alpha = [1] 

sage: decomp = F.asymptotic_decomposition(alpha) 

sage: decomp 

(0, []) + 

(-1/2*r^2*(x^2/(x^5 + 9*x^4 + 27*x^3 + 27*x^2) 

+ 6*x/(x^5 + 9*x^4 + 27*x^3 + 27*x^2) 

+ 9/(x^5 + 9*x^4 + 27*x^3 + 27*x^2)) 

- 1/2*r*(5*x^2/(x^5 + 9*x^4 + 27*x^3 + 27*x^2) 

+ 24*x/(x^5 + 9*x^4 + 27*x^3 + 27*x^2) 

+ 27/(x^5 + 9*x^4 + 27*x^3 + 27*x^2)) 

- 3*x^2/(x^5 + 9*x^4 + 27*x^3 + 27*x^2) 

- 9*x/(x^5 + 9*x^4 + 27*x^3 + 27*x^2) 

- 9/(x^5 + 9*x^4 + 27*x^3 + 27*x^2), 

[(x - 1/2, 1)]) 

sage: F1 = decomp[1] 

sage: p = {x: 1/2} 

sage: asy = F1.asymptotics(p, alpha, 3) 

sage: asy 

(8/343*(49*r^2 + 161*r + 114)*2^r, 2, 8/7*r^2 + 184/49*r + 912/343) 

sage: F.relative_error(asy[0], alpha, [1, 2, 4, 8, 16], asy[1]) 

[((1,), 7.555555556, [7.556851312], [-0.0001714971672]), 

((2,), 14.74074074, [14.74052478], [0.00001465051901]), 

((4,), 35.96502058, [35.96501458], [1.667911934e-7]), 

((8,), 105.8425656, [105.8425656], [4.399565380e-11]), 

((16,), 355.3119534, [355.3119534], [0.0000000000])] 

 

Another smooth point example (Example 5.4 of [RaWi2008a]_):: 

 

sage: R.<x,y> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R) 

sage: q = 1/2 

sage: qq = q.denominator() 

sage: H = 1 - q*x + q*x*y - x^2*y 

sage: Hfac = H.factor() 

sage: G = (1 - q*x)/Hfac.unit() 

sage: F = FFPD(G, Hfac) 

sage: alpha = list(qq*vector([2, 1 - q])) 

sage: alpha 

[4, 1] 

sage: I = F.smooth_critical_ideal(alpha) 

sage: I 

Ideal (y^2 - 2*y + 1, x + 1/4*y - 5/4) of 

Multivariate Polynomial Ring in x, y over Rational Field 

sage: s = solve([SR(z) for z in I.gens()], 

....: [SR(z) for z in R.gens()], solution_dict=true) 

sage: s == [{SR(x): 1, SR(y): 1}] 

True 

sage: p = s[0] 

sage: asy = F.asymptotics(p, alpha, 1, verbose=True) 

Creating auxiliary functions... 

Computing derivatives of auxiliary functions... 

Computing derivatives of more auxiliary functions... 

Computing second order differential operator actions... 

sage: asy 

(1/24*2^(2/3)*(sqrt(3) + 4/(sqrt(3) + I) + I)*gamma(1/3)/(pi*r^(1/3)), 

1, 

1/24*2^(2/3)*(sqrt(3) + 4/(sqrt(3) + I) + I)*gamma(1/3)/(pi*r^(1/3))) 

sage: r = SR('r') 

sage: tuple((a*r^(1/3)).full_simplify() / r^(1/3) for a in asy) # make nicer coefficients 

(1/12*sqrt(3)*2^(2/3)*gamma(1/3)/(pi*r^(1/3)), 

1, 

1/12*sqrt(3)*2^(2/3)*gamma(1/3)/(pi*r^(1/3))) 

sage: F.relative_error(asy[0], alpha, [1, 2, 4, 8, 16], asy[1]) 

[((4, 1), 0.1875000000, [0.1953794675...], [-0.042023826...]), 

((8, 2), 0.1523437500, [0.1550727862...], [-0.017913673...]), 

((16, 4), 0.1221771240, [0.1230813519...], [-0.0074009592...]), 

((32, 8), 0.09739671811, [0.09768973377...], [-0.0030084757...]), 

((64, 16), 0.07744253816, [0.07753639308...], [-0.0012119297...])] 

 

A multiple point example (Example 6.5 of [RaWi2012]_):: 

 

sage: R.<x,y> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R, SR) 

sage: H = (1 - 2*x - y)**2 * (1 - x - 2*y)**2 

sage: Hfac = H.factor() 

sage: G = 1/Hfac.unit() 

sage: F = FFPD(G, Hfac) 

sage: F 

(1, [(x + 2*y - 1, 2), (2*x + y - 1, 2)]) 

sage: I = F.singular_ideal() 

sage: I 

Ideal (x - 1/3, y - 1/3) of 

Multivariate Polynomial Ring in x, y over Rational Field 

sage: p = {x: 1/3, y: 1/3} 

sage: F.is_convenient_multiple_point(p) 

(True, 'convenient in variables [x, y]') 

sage: alpha = (var('a'), var('b')) 

sage: decomp = F.asymptotic_decomposition(alpha); decomp 

(0, []) + 

(-1/9*r^2*(2*a^2/x^2 + 2*b^2/y^2 - 5*a*b/(x*y)) 

- 1/9*r*(6*a/x^2 + 6*b/y^2 - 5*a/(x*y) - 5*b/(x*y)) 

- 4/9/x^2 - 4/9/y^2 + 5/9/(x*y), 

[(x + 2*y - 1, 1), (2*x + y - 1, 1)]) 

sage: F1 = decomp[1] 

sage: F1.asymptotics(p, alpha, 2) 

(-3*((2*a^2 - 5*a*b + 2*b^2)*r^2 + (a + b)*r + 3)*((1/3)^(-a)*(1/3)^(-b))^r, 

(1/3)^(-a)*(1/3)^(-b), -3*(2*a^2 - 5*a*b + 2*b^2)*r^2 - 3*(a + b)*r - 9) 

sage: alpha = [4, 3] 

sage: decomp = F.asymptotic_decomposition(alpha) 

sage: F1 = decomp[1] 

sage: asy = F1.asymptotics(p, alpha, 2) 

sage: asy 

(3*(10*r^2 - 7*r - 3)*2187^r, 2187, 30*r^2 - 21*r - 9) 

sage: F.relative_error(asy[0], alpha, [1, 2, 4, 8], asy[1]) 

[((4, 3), 30.72702332, [0.0000000000], [1.000000000]), 

((8, 6), 111.9315678, [69.00000000], [0.3835519207]), 

((16, 12), 442.7813138, [387.0000000], [0.1259793763]), 

((32, 24), 1799.879232, [1743.000000], [0.03160169385])] 

 

TESTS:: 

 

sage: R.<x,y> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R) 

sage: H = (1 - 2*x - y) * (1 - x - 2*y) 

sage: G = 1 

sage: Hfac = H.factor() 

sage: G = G / Hfac.unit() 

sage: F = FFPD(G, Hfac); F 

(1, [(x + 2*y - 1, 1), (2*x + y - 1, 1)]) 

sage: p = {x: 1, y: 1} 

sage: alpha = [1, 1] 

sage: F.asymptotics(p, alpha, 1) 

(1/3, 1, 1/3) 

 

:: 

 

sage: R.<x,y,t> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R) 

sage: H = (1 - y) * (1 + x^2) * (1 - t*(1 + x^2 + x*y^2)) 

sage: G = (1 + x) * (1 + x^2 - x*y^2) 

sage: Hfac = H.factor() 

sage: G = G / Hfac.unit() 

sage: F = FFPD(G, Hfac); F 

(-x^2*y^2 + x^3 - x*y^2 + x^2 + x + 1, 

[(y - 1, 1), (x^2 + 1, 1), (x*y^2*t + x^2*t + t - 1, 1)]) 

sage: p = {x: 1, y: 1, t: 1/3} 

sage: alpha = [1, 1, 1] 

sage: F.asymptotics_multiple(p, alpha, 1, var('r')) # not tested - see #19989 

 

 

Various 

======= 

 

AUTHORS: 

 

- Alexander Raichev (2008) 

- Daniel Krenn (2014, 2016) 

 

 

Classes and Methods 

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

""" 

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

# Copyright (C) 2008 Alexander Raichev <tortoise.said@gmail.com> 

# Copyright (C) 2014, 2016 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 print_function 

from six.moves import range 

 

from functools import total_ordering 

from itertools import combinations_with_replacement 

from sage.structure.element import RingElement 

from sage.structure.unique_representation import UniqueRepresentation 

from sage.rings.ring import Ring 

from sage.calculus.var import var 

from sage.calculus.functional import diff 

from sage.symbolic.ring import SR 

from sage.misc.misc_c import prod 

from sage.rings.integer import Integer 

from sage.rings.integer_ring import ZZ 

from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing 

from sage.categories.rings import Rings 

from sage.structure.richcmp import richcmp_by_eq_and_lt 

 

 

@total_ordering 

class FractionWithFactoredDenominator(RingElement): 

r""" 

This element represents a fraction with a factored polynomial 

denominator. See also its parent 

:class:`FractionWithFactoredDenominatorRing` for details. 

 

Represents a fraction with factored polynomial denominator (FFPD) 

`p/(q_1^{e_1} \cdots q_n^{e_n})` by storing the parts `p` and 

`[(q_1, e_1), \ldots, (q_n, e_n)]`. 

Here `q_1, \ldots, q_n` are elements of a 0- or multi-variate factorial 

polynomial ring `R` , `q_1, \ldots, q_n` are distinct irreducible elements 

of `R` , `e_1, \ldots, e_n` are positive integers, and `p` is a function 

of the indeterminates of `R` (e.g., a Sage symbolic expression). An 

element `r` with no polynomial denominator is represented as ``(r, [])``. 

 

INPUT: 

 

- ``numerator`` -- an element `p`; this can be of any ring from which 

parent's base has coercion in 

- ``denominator_factored`` -- a list of the form 

`[(q_1, e_1), \ldots, (q_n, e_n)]`, where the `q_1, \ldots, q_n` are 

distinct irreducible elements of `R` and the `e_i` are positive 

integers 

- ``reduce`` -- (optional) if ``True``, then represent 

`p/(q_1^{e_1} \cdots q_n^{e_n})` in lowest terms, otherwise 

this won't attempt to divide `p` by any of the `q_i` 

 

OUTPUT: 

 

An element representing the rational expression 

`p/(q_1^{e_1} \cdots q_n^{e_n})`. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.asymptotics_multivariate_generating_functions import FractionWithFactoredDenominatorRing 

sage: R.<x,y> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R) 

sage: df = [x, 1], [y, 1], [x*y+1, 1] 

sage: f = FFPD(x, df) 

sage: f 

(1, [(y, 1), (x*y + 1, 1)]) 

sage: ff = FFPD(x, df, reduce=False) 

sage: ff 

(x, [(y, 1), (x, 1), (x*y + 1, 1)]) 

 

sage: f = FFPD(x + y, [(x + y, 1)]) 

sage: f 

(1, []) 

 

:: 

 

sage: R.<x> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R) 

sage: f = 5*x^3 + 1/x + 1/(x-1) + 1/(3*x^2 + 1) 

sage: FFPD(f) 

(5*x^7 - 5*x^6 + 5/3*x^5 - 5/3*x^4 + 2*x^3 - 2/3*x^2 + 1/3*x - 1/3, 

[(x - 1, 1), (x, 1), (x^2 + 1/3, 1)]) 

 

:: 

 

sage: R.<x,y> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R, SR) 

sage: f = 2*y/(5*(x^3 - 1)*(y + 1)) 

sage: FFPD(f) 

(2/5*y, [(y + 1, 1), (x - 1, 1), (x^2 + x + 1, 1)]) 

 

sage: p = 1/x^2 

sage: q = 3*x**2*y 

sage: qs = q.factor() 

sage: f = FFPD(p/qs.unit(), qs) 

sage: f 

(1/3/x^2, [(y, 1), (x, 2)]) 

 

sage: f = FFPD(cos(x)*x*y^2, [(x, 2), (y, 1)]) 

sage: f 

(x*y^2*cos(x), [(y, 1), (x, 2)]) 

 

sage: G = exp(x + y) 

sage: H = (1 - 2*x - y) * (1 - x - 2*y) 

sage: a = FFPD(G/H) 

sage: a 

(e^(x + y), [(x + 2*y - 1, 1), (2*x + y - 1, 1)]) 

sage: a.denominator_ring 

Multivariate Polynomial Ring in x, y over Rational Field 

sage: b = FFPD(G, H.factor()) 

sage: b 

(e^(x + y), [(x + 2*y - 1, 1), (2*x + y - 1, 1)]) 

sage: b.denominator_ring 

Multivariate Polynomial Ring in x, y over Rational Field 

 

Singular throws a 'not implemented' error when trying to factor in 

a multivariate polynomial ring over an inexact field:: 

 

sage: R.<x,y> = PolynomialRing(CC) 

sage: FFPD = FractionWithFactoredDenominatorRing(R) 

sage: f = (x + 1)/(x*y*(x*y + 1)^2) 

sage: FFPD(f) 

Traceback (most recent call last): 

... 

TypeError: Singular error: 

? not implemented 

? error occurred in or before STDIN line ...: 

`def sage...=factorize(sage...);` 

 

AUTHORS: 

 

- Alexander Raichev (2012-07-26) 

- Daniel Krenn (2014-12-01) 

""" 

 

def __init__(self, parent, numerator, denominator_factored, reduce=True): 

r""" 

Initialize ``self``. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.asymptotics_multivariate_generating_functions import FractionWithFactoredDenominatorRing 

sage: R.<x,y> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R) 

sage: df = [x, 1], [y, 1], [x*y+1, 1] 

sage: f = FFPD(x, df) 

sage: TestSuite(f).run() 

""" 

super(FractionWithFactoredDenominator, self).__init__(parent) 

 

from sage.rings.semirings.non_negative_integer_semiring import NN 

self._numerator = parent._numerator_ring(numerator) 

self._denominator_factored = list( 

(parent._denominator_ring(d), NN(n)) 

for d, n in denominator_factored) 

 

R = self.denominator_ring 

if numerator in R and reduce: 

# Reduce fraction if possible. 

numer = R(self._numerator) 

df = self._denominator_factored 

new_df = [] 

for (q, e) in df: 

ee = e 

quo, rem = numer.quo_rem(q) 

while rem == 0 and ee > 0: 

ee -= 1 

numer = quo 

quo, rem = numer.quo_rem(q) 

if ee > 0: 

new_df.append((q, ee)) 

self._numerator = numer 

self._denominator_factored = new_df 

 

def numerator(self): 

r""" 

Return the numerator of ``self``. 

 

OUTPUT: 

 

The numerator. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.asymptotics_multivariate_generating_functions import FractionWithFactoredDenominatorRing 

sage: R.<x,y> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R, SR) 

sage: H = (1 - x - y - x*y)**2*(1-x) 

sage: Hfac = H.factor() 

sage: G = exp(y)/Hfac.unit() 

sage: F = FFPD(G, Hfac) 

sage: F.numerator() 

-e^y 

""" 

return self._numerator 

 

def denominator(self): 

r""" 

Return the denominator of ``self``. 

 

OUTPUT: 

 

The denominator (i.e., the product of the factored denominator). 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.asymptotics_multivariate_generating_functions import FractionWithFactoredDenominatorRing 

sage: R.<x,y> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R, SR) 

sage: H = (1 - x - y - x*y)**2*(1-x) 

sage: Hfac = H.factor() 

sage: G = exp(y)/Hfac.unit() 

sage: F = FFPD(G, Hfac) 

sage: F.denominator() 

x^3*y^2 + 2*x^3*y + x^2*y^2 + x^3 - 2*x^2*y - x*y^2 - 3*x^2 - 2*x*y 

- y^2 + 3*x + 2*y - 1 

""" 

return prod(q ** e for q, e in self.denominator_factored()) 

 

def denominator_factored(self): 

r""" 

Return the factorization in ``self.denominator_ring`` of the denominator of 

``self`` but without the unit part. 

 

OUTPUT: 

 

The factored denominator as a list of tuple ``(f, m)``, where `f` is 

a factor and `m` its multiplicity. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.asymptotics_multivariate_generating_functions import FractionWithFactoredDenominatorRing 

sage: R.<x,y> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R, SR) 

sage: H = (1 - x - y - x*y)**2*(1-x) 

sage: Hfac = H.factor() 

sage: G = exp(y)/Hfac.unit() 

sage: F = FFPD(G, Hfac) 

sage: F.denominator_factored() 

[(x - 1, 1), (x*y + x + y - 1, 2)] 

""" 

return self._denominator_factored 

 

@property 

def denominator_ring(self): 

r""" 

Return the ring of the denominator. 

 

OUTPUT: 

 

A ring. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.asymptotics_multivariate_generating_functions import FractionWithFactoredDenominatorRing 

sage: R.<x,y> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R, SR) 

sage: H = (1 - x - y - x*y)**2*(1-x) 

sage: Hfac = H.factor() 

sage: G = exp(y)/Hfac.unit() 

sage: F = FFPD(G, Hfac) 

sage: F.denominator_ring 

Multivariate Polynomial Ring in x, y over Rational Field 

sage: F = FFPD(G/H) 

sage: F 

(e^y, [(x - 1, 1), (x*y + x + y - 1, 2)]) 

sage: F.denominator_ring 

Multivariate Polynomial Ring in x, y over Rational Field 

""" 

return self.parent()._denominator_ring 

 

@property 

def numerator_ring(self): 

r""" 

Return the ring of the numerator. 

 

OUTPUT: 

 

A ring. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.asymptotics_multivariate_generating_functions import FractionWithFactoredDenominatorRing 

sage: R.<x,y> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R, SR) 

sage: H = (1 - x - y - x*y)**2*(1-x) 

sage: Hfac = H.factor() 

sage: G = exp(y)/Hfac.unit() 

sage: F = FFPD(G, Hfac) 

sage: F.numerator_ring 

Symbolic Ring 

sage: F = FFPD(G/H) 

sage: F 

(e^y, [(x - 1, 1), (x*y + x + y - 1, 2)]) 

sage: F.numerator_ring 

Symbolic Ring 

""" 

return self.parent()._numerator_ring 

 

def dimension(self): 

r""" 

Return the number of indeterminates of ``self.denominator_ring``. 

 

OUTPUT: 

 

An integer. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.asymptotics_multivariate_generating_functions import FractionWithFactoredDenominatorRing 

sage: R.<x,y> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R, SR) 

sage: H = (1 - x - y - x*y)**2*(1-x) 

sage: Hfac = H.factor() 

sage: G = exp(y)/Hfac.unit() 

sage: F = FFPD(G, Hfac) 

sage: F.dimension() 

2 

""" 

from sage.rings.polynomial.polynomial_ring import is_PolynomialRing 

from sage.rings.polynomial.multi_polynomial_ring_generic import is_MPolynomialRing 

R = self.denominator_ring 

if is_PolynomialRing(R) or is_MPolynomialRing(R): 

return R.ngens() 

raise NotImplementedError('only polynomial rings are supported as base') 

 

def quotient(self): 

r""" 

Convert ``self`` into a quotient. 

 

OUTPUT: 

 

An element. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.asymptotics_multivariate_generating_functions import FractionWithFactoredDenominatorRing 

sage: R.<x,y> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R, SR) 

sage: H = (1 - x - y - x*y)**2*(1-x) 

sage: Hfac = H.factor() 

sage: G = exp(y)/Hfac.unit() 

sage: F = FFPD(G, Hfac) 

sage: F 

(-e^y, [(x - 1, 1), (x*y + x + y - 1, 2)]) 

sage: F.quotient() 

-e^y/(x^3*y^2 + 2*x^3*y + x^2*y^2 + x^3 - 2*x^2*y - x*y^2 - 3*x^2 - 

2*x*y - y^2 + 3*x + 2*y - 1) 

""" 

return self.numerator() / self.denominator() 

 

def _repr_(self): 

r""" 

Return a string representation of ``self``. 

 

OUTPUT: 

 

A string. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.asymptotics_multivariate_generating_functions import FractionWithFactoredDenominatorRing 

sage: R.<x,y> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R) 

sage: f = FFPD(x + y, [(y, 1), (x, 1)]) 

sage: f 

(x + y, [(y, 1), (x, 1)]) 

""" 

return repr((self.numerator(), self.denominator_factored())) 

 

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

 

def _eq_(self, other): 

r""" 

Return whether the FFPD instance ``other`` is equal to 

this FFPD instance. 

 

Two FFPD instances are equal iff they represent the same 

fraction. 

 

INPUT: 

 

- ``other`` -- an instance of :class:`FractionWithFactoredDenominator` 

 

OUTPUT: 

 

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

 

It can be assumed that ``self`` and ``other`` have the same parent. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.asymptotics_multivariate_generating_functions import FractionWithFactoredDenominatorRing 

sage: R.<x,y> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R) 

sage: df = [x, 1], [y, 1], [x*y+1, 1] 

sage: f = FFPD(x, df) 

sage: ff = FFPD(x, df, reduce=False) 

sage: f == ff 

True 

sage: g = FFPD(y, df) 

sage: g == f 

False 

 

:: 

 

sage: R.<x,y> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R, SR) 

sage: G = exp(x + y) 

sage: H = (1 - 2*x - y) * (1 - x - 2*y) 

sage: a = FFPD(G/H) 

sage: b = FFPD(G, H.factor()) 

sage: bool(a == b) 

True 

 

:: 

 

sage: R.<x,y> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R) 

sage: df = [x, 1], [y, 1], [x*y+1, 1] 

sage: f = FFPD(x, df) 

sage: ff = FFPD(x, df, reduce=False) 

sage: f != ff 

False 

sage: g = FFPD(y, df) 

sage: g != f 

True 

 

TESTS:: 

 

sage: R.<x,y> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R) 

sage: f = FFPD(x, []) 

sage: f == x 

True 

 

:: 

 

sage: R.<x,y> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R) 

sage: f = FFPD(x*y, [(x-1, 1), (y-2, 2)]) 

sage: g = FFPD(x, [(x-1, 1), (y-2, 2)]) 

sage: f == f 

True 

sage: f == g 

False 

 

sage: f < g 

Traceback (most recent call last): 

... 

AttributeError: 

'FractionWithFactoredDenominatorRing_with_category.element_class' 

object has no attribute '_lt_' 

""" 

return (self.numerator() * other.denominator() == 

other.numerator() * self.denominator()) 

 

def _total_order_key_(self): 

r""" 

Return a key that can be used for sorting. 

 

FFPD ``A`` is less than FFPD ``B`` iff 

(the denominator factorization of ``A`` is shorter than that of ``B``) 

of (the denominator factorization lengths are equal and 

the denominator of ``A`` is less than that of ``B`` in their ring) or 

(the denominator factorization lengths are equal and the 

denominators are equal and the numerator of ``A`` is less than that 

of ``B`` in their ring). 

 

OUTPUT: 

 

A tuple. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.asymptotics_multivariate_generating_functions import FractionWithFactoredDenominatorRing 

sage: R.<x,y> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R, SR) 

sage: df = [x, 1], [y, 1], [x*y+1, 1] 

sage: f = FFPD(x, df); f 

(1, [(y, 1), (x*y + 1, 1)]) 

sage: ff = FFPD(x, df, reduce=False); ff 

(x, [(y, 1), (x, 1), (x*y + 1, 1)]) 

sage: g = FFPD(y, df) 

sage: h = FFPD(exp(x), df) 

sage: i = FFPD(sin(x + 2), df) 

sage: f._total_order_key_() < ff._total_order_key_() 

True 

sage: f._total_order_key_() < g._total_order_key_() 

True 

sage: g._total_order_key_() < h._total_order_key_() 

True 

sage: bool(h._total_order_key_() < i._total_order_key_()) 

False 

""" 

return (len(self.denominator_factored()), 

self.denominator(), 

self.numerator()) 

 

def univariate_decomposition(self): 

r""" 

Return the usual univariate partial fraction decomposition 

of ``self``. 

 

Assume that the numerator of ``self`` lies in the same univariate 

factorial polynomial ring as the factors of the denominator. 

 

Let `f = p/q` be a rational expression where `p` and `q` lie in a 

univariate factorial polynomial ring `R`. 

Let `q_1^{e_1} \cdots q_n^{e_n}` be the 

unique factorization of `q` in `R` into irreducible factors. 

Then `f` can be written uniquely as: 

 

.. MATH:: 

 

(*) \quad p_0 + \sum_{i=1}^{m} \frac{p_i}{q_i^{e_i}}, 

 

for some `p_j \in R`. 

We call `(*)` the *usual partial fraction decomposition* of `f`. 

 

.. NOTE:: 

 

This partial fraction decomposition can be computed using 

:meth:`~sage.symbolic.expression.Expression.partial_fraction` or 

:meth:`~sage.categories.quotient_fields.QuotientFields.ElementMethods.partial_fraction_decomposition` 

as well. However, here we use the already obtained/cached 

factorization of the denominator. This gives a speed up for 

non-small instances. 

 

OUTPUT: 

 

An instance of :class:`FractionWithFactoredDenominatorSum`. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.asymptotics_multivariate_generating_functions import FractionWithFactoredDenominatorRing 

 

One variable:: 

 

sage: R.<x> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R) 

sage: f = 5*x^3 + 1/x + 1/(x-1) + 1/(3*x^2 + 1) 

sage: f 

(15*x^7 - 15*x^6 + 5*x^5 - 5*x^4 + 6*x^3 - 2*x^2 + x - 1)/(3*x^4 - 

3*x^3 + x^2 - x) 

sage: decomp = FFPD(f).univariate_decomposition() 

sage: decomp 

(5*x^3, []) + 

(1, [(x - 1, 1)]) + 

(1, [(x, 1)]) + 

(1/3, [(x^2 + 1/3, 1)]) 

sage: decomp.sum().quotient() == f 

True 

 

One variable with numerator in symbolic ring:: 

 

sage: R.<x> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R, SR) 

sage: f = 5*x^3 + 1/x + 1/(x-1) + exp(x)/(3*x^2 + 1) 

sage: f 

(5*x^5 - 5*x^4 + 2*x - 1)/(x^2 - x) + e^x/(3*x^2 + 1) 

sage: decomp = FFPD(f).univariate_decomposition() 

sage: decomp 

(0, []) + 

(15/4*x^7 - 15/4*x^6 + 5/4*x^5 - 5/4*x^4 + 3/2*x^3 + 1/4*x^2*e^x - 

3/4*x^2 - 1/4*x*e^x + 1/2*x - 1/4, [(x - 1, 1)]) + 

(-15*x^7 + 15*x^6 - 5*x^5 + 5*x^4 - 6*x^3 - 

x^2*e^x + 3*x^2 + x*e^x - 2*x + 1, [(x, 1)]) + 

(1/4*(15*x^7 - 15*x^6 + 5*x^5 - 5*x^4 + 6*x^3 + x^2*e^x - 

3*x^2 - x*e^x + 2*x - 1)*(3*x - 1), [(x^2 + 1/3, 1)]) 

 

One variable over a finite field:: 

 

sage: R.<x> = PolynomialRing(GF(2)) 

sage: FFPD = FractionWithFactoredDenominatorRing(R) 

sage: f = 5*x^3 + 1/x + 1/(x-1) + 1/(3*x^2 + 1) 

sage: f 

(x^6 + x^4 + 1)/(x^3 + x) 

sage: decomp = FFPD(f).univariate_decomposition() 

sage: decomp 

(x^3, []) + (1, [(x, 1)]) + (x, [(x + 1, 2)]) 

sage: decomp.sum().quotient() == f 

True 

 

One variable over an inexact field:: 

 

sage: R.<x> = PolynomialRing(CC) 

sage: FFPD = FractionWithFactoredDenominatorRing(R) 

sage: f = 5*x^3 + 1/x + 1/(x-1) + 1/(3*x^2 + 1) 

sage: f 

(15.0000000000000*x^7 - 15.0000000000000*x^6 + 5.00000000000000*x^5 

- 5.00000000000000*x^4 + 6.00000000000000*x^3 

- 2.00000000000000*x^2 + x - 1.00000000000000)/(3.00000000000000*x^4 

- 3.00000000000000*x^3 + x^2 - x) 

sage: decomp = FFPD(f).univariate_decomposition() 

sage: decomp 

(5.00000000000000*x^3, []) + 

(1.00000000000000, [(x - 1.00000000000000, 1)]) + 

(-0.288675134594813*I, [(x - 0.577350269189626*I, 1)]) + 

(1.00000000000000, [(x, 1)]) + 

(0.288675134594813*I, [(x + 0.577350269189626*I, 1)]) 

sage: decomp.sum().quotient() == f # Rounding error coming 

False 

 

TESTS:: 

 

sage: R.<x> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R, SR) 

sage: f = exp(x) / (x^2-x) 

sage: f 

e^x/(x^2 - x) 

sage: FFPD(f).univariate_decomposition() 

(0, []) + (e^x, [(x - 1, 1)]) + (-e^x, [(x, 1)]) 

 

AUTHORS: 

 

- Robert Bradshaw (2007-05-31) 

- Alexander Raichev (2012-06-25) 

- Daniel Krenn (2014-12-01) 

""" 

if self.dimension() > 1: 

return FractionWithFactoredDenominatorSum([self]) 

 

R = self.denominator_ring 

p = self.numerator() 

q = self.denominator() 

try: 

whole, p = R(p).quo_rem(q) 

mn = R.one() 

except (TypeError, ValueError): 

whole = R(0) 

mn = p 

p = R.one() 

df = self.denominator_factored() 

decomp = [self.parent()(whole, [])] 

denominator = prod(b**n for b, n in df) 

for a, m in df: 

am = a**m 

q, r = denominator.quo_rem(am) 

assert r==0 

numer = p * q.inverse_mod(am) % am 

# The inverse exists because the product and a**m 

# are relatively prime. 

decomp.append(self.parent()(mn * numer, [(a, m)])) 

return FractionWithFactoredDenominatorSum(decomp) 

 

def nullstellensatz_certificate(self): 

r""" 

Return a Nullstellensatz certificate of ``self`` if it exists. 

 

Let `[(q_1, e_1), \ldots, (q_n, e_n)]` be the denominator 

factorization of ``self``. The Nullstellensatz certificate is 

a list of polynomials `h_1, \ldots, h_m` in ``self.denominator_ring`` 

that satisfies `h_1 q_1 + \cdots + h_m q_n = 1` if it exists. 

 

.. NOTE:: 

 

Only works for multivariate base rings. 

 

OUTPUT: 

 

A list of polynomials or ``None`` if no Nullstellensatz 

certificate exists. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.asymptotics_multivariate_generating_functions import FractionWithFactoredDenominatorRing 

sage: R.<x,y> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R, SR) 

sage: G = sin(x) 

sage: H = x^2 * (x*y + 1) 

sage: f = FFPD(G, H.factor()) 

sage: L = f.nullstellensatz_certificate() 

sage: L 

[y^2, -x*y + 1] 

sage: df = f.denominator_factored() 

sage: sum(L[i]*df[i][0]**df[i][1] for i in range(len(df))) == 1 

True 

 

:: 

 

sage: f = 1/(x*y) 

sage: L = FFPD(f).nullstellensatz_certificate() 

sage: L is None 

True 

""" 

R = self.denominator_ring 

df = self.denominator_factored() 

J = R.ideal([q ** e for q, e in df]) 

if R.one() in J: 

return R.one().lift(J) 

return None 

 

def nullstellensatz_decomposition(self): 

r""" 

Return a Nullstellensatz decomposition of ``self``. 

 

Let `f = p/q` where `q` lies in a `d` -variate polynomial ring 

`K[X]` for some field `K` and `d \geq 1`. 

Let `q_1^{e_1} \cdots q_n^{e_n}` be the 

unique factorization of `q` in `K[X]` into irreducible factors and 

let `V_i` be the algebraic variety `\{x \in L^d \mid q_i(x) = 0\}` 

of `q_i` over the algebraic closure `L` of `K`. 

By [Raic2012]_, `f` can be written as 

 

.. MATH:: 

 

(*) \quad \sum_A \frac{p_A}{\prod_{i \in A} q_i^{e_i}}, 

 

where the `p_A` are products of `p` and elements in `K[X]` and 

the sum is taken over all subsets 

`A \subseteq \{1, \ldots, m\}` such that 

`\bigcap_{i\in A} T_i \neq \emptyset`. 

 

We call `(*)` a *Nullstellensatz decomposition* of `f`. 

Nullstellensatz decompositions are not unique. 

 

The algorithm used comes from [Raic2012]_. 

 

.. NOTE:: 

 

Recursive. Only works for multivariate ``self``. 

 

OUTPUT: 

 

An instance of :class:`FractionWithFactoredDenominatorSum`. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.asymptotics_multivariate_generating_functions import * 

sage: R.<x,y> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R) 

sage: f = 1/(x*(x*y + 1)) 

sage: decomp = FFPD(f).nullstellensatz_decomposition() 

sage: decomp 

(0, []) + (1, [(x, 1)]) + (-y, [(x*y + 1, 1)]) 

sage: decomp.sum().quotient() == f 

True 

sage: [r.nullstellensatz_certificate() is None for r in decomp] 

[True, True, True] 

 

:: 

 

sage: R.<x,y> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R, SR) 

sage: G = sin(y) 

sage: H = x*(x*y + 1) 

sage: f = FFPD(G, H.factor()) 

sage: decomp = f.nullstellensatz_decomposition() 

sage: decomp 

(0, []) + (sin(y), [(x, 1)]) + (-y*sin(y), [(x*y + 1, 1)]) 

sage: bool(decomp.sum().quotient() == G/H) 

True 

sage: [r.nullstellensatz_certificate() is None for r in decomp] 

[True, True, True] 

""" 

L = self.nullstellensatz_certificate() 

if L is None: 

# No decomposing possible. 

return FractionWithFactoredDenominatorSum([self]) 

 

# Otherwise decompose recursively. 

decomp = FractionWithFactoredDenominatorSum() 

p = self.numerator() 

df = self.denominator_factored() 

m = len(df) 

iteration1 = FractionWithFactoredDenominatorSum( 

[self.parent()(p * L[i], [df[j] for j in range(m) if j != i]) 

for i in range(m) if L[i] != 0]) 

 

# Now decompose each FFPD of iteration1. 

for r in iteration1: 

decomp.extend(r.nullstellensatz_decomposition()) 

 

# Simplify and return result. 

return decomp._combine_like_terms_().whole_and_parts() 

 

def algebraic_dependence_certificate(self): 

r""" 

Return the algebraic dependence certificate of ``self``. 

 

The algebraic dependence certificate is the ideal `J` of 

annihilating polynomials for the set of polynomials 

``[q^e for (q, e) in self.denominator_factored()]``, 

which could be the zero ideal. 

The ideal `J` lies in a polynomial ring over the field 

``self.denominator_ring.base_ring()`` that has 

``m = len(self.denominator_factored())`` indeterminates. 

 

OUTPUT: 

 

An ideal. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.asymptotics_multivariate_generating_functions import FractionWithFactoredDenominatorRing 

sage: R.<x,y> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R) 

sage: f = 1/(x^2 * (x*y + 1) * y^3) 

sage: ff = FFPD(f) 

sage: J = ff.algebraic_dependence_certificate(); J 

Ideal (1 - 6*T2 + 15*T2^2 - 20*T2^3 + 15*T2^4 - T0^2*T1^3 - 

6*T2^5 + T2^6) of Multivariate Polynomial Ring in 

T0, T1, T2 over Rational Field 

sage: g = J.gens()[0] 

sage: df = ff.denominator_factored() 

sage: g(*(q**e for q, e in df)) == 0 

True 

 

:: 

 

sage: R.<x,y> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R, SR) 

sage: G = exp(x + y) 

sage: H = x^2 * (x*y + 1) * y^3 

sage: ff = FFPD(G, H.factor()) 

sage: J = ff.algebraic_dependence_certificate(); J 

Ideal (1 - 6*T2 + 15*T2^2 - 20*T2^3 + 15*T2^4 - T0^2*T1^3 - 

6*T2^5 + T2^6) of Multivariate Polynomial Ring in 

T0, T1, T2 over Rational Field 

sage: g = J.gens()[0] 

sage: df = ff.denominator_factored() 

sage: g(*(q**e for q, e in df)) == 0 

True 

 

:: 

 

sage: f = 1/(x^3 * y^2) 

sage: J = FFPD(f).algebraic_dependence_certificate() 

sage: J 

Ideal (0) of Multivariate Polynomial Ring in T0, T1 over Rational Field 

 

:: 

 

sage: f = sin(1)/(x^3 * y^2) 

sage: J = FFPD(f).algebraic_dependence_certificate() 

sage: J 

Ideal (0) of Multivariate Polynomial Ring in T0, T1 over Rational Field 

""" 

R = self.denominator_ring 

df = self.denominator_factored() 

if not df: 

return R.ideal() # The zero ideal. 

m = len(df) 

F = R.base_ring() 

Xs = list(R.gens()) 

d = len(Xs) 

 

# Expand R by 2 * m new variables. 

S = 'S' 

while S in [str(x) for x in Xs]: 

S = S + 'S' 

Ss = [S + str(i) for i in range(m)] 

T = 'T' 

while T in [str(x) for x in Xs]: 

T = T + 'T' 

Ts = [T + str(i) for i in range(m)] 

 

Vs = [str(x) for x in Xs] + Ss + Ts 

RR = PolynomialRing(F, Vs) 

Xs = RR.gens()[:d] 

Ss = RR.gens()[d: d + m] 

Ts = RR.gens()[d + m: d + 2 * m] 

 

# Compute the appropriate elimination ideal. 

J = RR.ideal([Ss[j] - RR(df[j][0]) for j in range(m)] + 

[Ss[j] ** df[j][1] - Ts[j] for j in range(m)]) 

J = J.elimination_ideal(Xs + Ss) 

 

# Coerce J into the polynomial ring in the indeterminates Ts[m:]. 

# I choose the negdeglex order because i find it useful in my work. 

RRR = PolynomialRing(F, [str(t) for t in Ts], order='negdeglex') 

return RRR.ideal(J) 

 

def algebraic_dependence_decomposition(self, whole_and_parts=True): 

r""" 

Return an algebraic dependence decomposition of ``self``. 

 

Let `f = p/q` where `q` lies in a `d`-variate polynomial ring 

`K[X]` for some field `K`. 

Let `q_1^{e_1} \cdots q_n^{e_n}` be the 

unique factorization of `q` in `K[X]` into irreducible factors and 

let `V_i` be the algebraic variety `\{x \in L^d \mid q_i(x) = 0\}` 

of `q_i` over the algebraic closure `L` of `K`. 

By [Raic2012]_, `f` can be written as 

 

.. MATH:: 

 

(*) \quad \sum_A \frac{p_A}{\prod_{i \in A} q_i^{b_i}}, 

 

where the `b_i` are positive integers, each `p_A` is a products 

of `p` and an element in `K[X]`, 

and the sum is taken over all subsets 

`A \subseteq \{1, \ldots, m\}` such that `|A| \leq d` and 

`\{q_i \mid i \in A\}` is algebraically independent. 

 

We call `(*)` an *algebraic dependence decomposition* of `f`. 

Algebraic dependence decompositions are not unique. 

 

The algorithm used comes from [Raic2012]_. 

 

OUTPUT: 

 

An instance of :class:`FractionWithFactoredDenominatorSum`. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.asymptotics_multivariate_generating_functions import FractionWithFactoredDenominatorRing 

sage: R.<x,y> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R) 

sage: f = 1/(x^2 * (x*y + 1) * y^3) 

sage: ff = FFPD(f) 

sage: decomp = ff.algebraic_dependence_decomposition() 

sage: decomp 

(0, []) + (-x, [(x*y + 1, 1)]) + 

(x^2*y^2 - x*y + 1, [(y, 3), (x, 2)]) 

sage: decomp.sum().quotient() == f 

True 

sage: for r in decomp: 

....: J = r.algebraic_dependence_certificate() 

....: J is None or J == J.ring().ideal() # The zero ideal 

True 

True 

True 

 

:: 

 

sage: R.<x,y> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R, SR) 

sage: G = sin(x) 

sage: H = x^2 * (x*y + 1) * y^3 

sage: f = FFPD(G, H.factor()) 

sage: decomp = f.algebraic_dependence_decomposition() 

sage: decomp 

(0, []) + (x^4*y^3*sin(x), [(x*y + 1, 1)]) + 

(-(x^5*y^5 - x^4*y^4 + x^3*y^3 - x^2*y^2 + x*y - 1)*sin(x), 

[(y, 3), (x, 2)]) 

sage: bool(decomp.sum().quotient() == G/H) 

True 

sage: for r in decomp: 

....: J = r.algebraic_dependence_certificate() 

....: J is None or J == J.ring().ideal() 

True 

True 

True 

""" 

J = self.algebraic_dependence_certificate() 

if not J: 

# No decomposing possible. 

return FractionWithFactoredDenominatorSum([self]) 

 

# Otherwise decompose recursively. 

decomp = FractionWithFactoredDenominatorSum() 

p = self.numerator() 

df = self.denominator_factored() 

m = len(df) 

g = J.gens()[0] # An annihilating polynomial for df. 

new_vars = J.ring().gens() 

# Note that each new_vars[j] corresponds to df[j] such that 

# g([q**e for q, e in df]) = 0. 

# Assuming here that g.parent() has negdeglex term order 

# so that g.lt() is indeed the monomial we want below. 

# Use g to rewrite r into a sum of FFPDs, 

# each with < m distinct denominator factors. 

gg = (g.lt() - g) / (g.lc()) 

numers = map(prod, zip(gg.coefficients(), gg.monomials())) 

e = list(g.lt().exponents())[0: m] 

denoms = [(new_vars[j], e[0][j] + 1) for j in range(m)] 

# Write r in terms of new_vars, 

# cancel factors in the denominator, and combine like terms. 

FFPD = FractionWithFactoredDenominatorRing(J.ring()) 

iteration1_temp = FractionWithFactoredDenominatorSum( 

[FFPD(a, denoms) for a in numers])._combine_like_terms_() 

# Substitute in df. 

qpowsub = {new_vars[j]: df[j][0] ** df[j][1] for j in range(m)} 

iteration1 = FractionWithFactoredDenominatorSum() 

for r in iteration1_temp: 

num1 = p * J.ring()(r.numerator()).subs(qpowsub) 

denoms1 = [] 

for q, e in r.denominator_factored(): 

j = new_vars.index(q) 

denoms1.append((df[j][0], df[j][1] * e)) 

iteration1.append(self.parent()(num1, denoms1)) 

# Now decompose each FFPD of iteration1. 

for r in iteration1: 

decomp.extend(r.algebraic_dependence_decomposition()) 

 

# Simplify and return result. 

return decomp._combine_like_terms_().whole_and_parts() 

 

def leinartas_decomposition(self): 

r""" 

Return a Leinartas decomposition of ``self``. 

 

Let `f = p/q` where `q` lies in a `d` -variate polynomial 

ring `K[X]` for some field `K`. 

Let `q_1^{e_1} \cdots q_n^{e_n}` be the 

unique factorization of `q` in `K[X]` into irreducible factors and 

let `V_i` be the algebraic variety 

`\{x\in L^d \mid q_i(x) = 0\}` of `q_i` over the algebraic closure 

`L` of `K`. By [Raic2012]_, `f` can be written as 

 

.. MATH:: 

 

(*) \quad \sum_A \frac{p_A}{\prod_{i \in A} q_i^{b_i}}, 

 

where the `b_i` are positive integers, each `p_A` is a product of 

`p` and an element of `K[X]`, and the sum is taken over all 

subsets `A \subseteq \{1, \ldots, m\}` such that 

 

1. `|A| \le d`, 

2. `\bigcap_{i\in A} T_i \neq \emptyset`, and 

3. `\{q_i \mid i\in A\}` is algebraically independent. 

 

In particular, any rational expression in `d` variables 

can be represented as a sum of rational expressions 

whose denominators each contain at most `d` distinct irreducible 

factors. 

 

We call `(*)` a *Leinartas decomposition* of `f`. 

Leinartas decompositions are not unique. 

 

The algorithm used comes from [Raic2012]_. 

 

OUTPUT: 

 

An instance of :class:`FractionWithFactoredDenominatorSum`. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.asymptotics_multivariate_generating_functions import FractionWithFactoredDenominatorRing 

sage: R.<x> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R) 

sage: f = (x^2 + 1)/((x + 2)*(x - 1)*(x^2 + x + 1)) 

sage: decomp = FFPD(f).leinartas_decomposition() 

sage: decomp 

(0, []) + (2/9, [(x - 1, 1)]) + 

(-5/9, [(x + 2, 1)]) + (1/3*x, [(x^2 + x + 1, 1)]) 

sage: decomp.sum().quotient() == f 

True 

 

:: 

 

sage: R.<x,y> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R) 

sage: f = 1/x + 1/y + 1/(x*y + 1) 

sage: decomp = FFPD(f).leinartas_decomposition() 

sage: decomp 

(0, []) + (1, [(x*y + 1, 1)]) + (x + y, [(y, 1), (x, 1)]) 

sage: decomp.sum().quotient() == f 

True 

sage: def check_decomp(r): 

....: L = r.nullstellensatz_certificate() 

....: J = r.algebraic_dependence_certificate() 

....: return L is None and (J is None or J == J.ring().ideal()) 

sage: all(check_decomp(r) for r in decomp) 

True 

 

:: 

 

sage: R.<x,y> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R, SR) 

sage: f = sin(x)/x + 1/y + 1/(x*y + 1) 

sage: G = f.numerator() 

sage: H = R(f.denominator()) 

sage: ff = FFPD(G, H.factor()) 

sage: decomp = ff.leinartas_decomposition() 

sage: decomp 

(0, []) + 

(-(x*y^2*sin(x) + x^2*y + x*y + y*sin(x) + x)*y, [(y, 1)]) + 

((x*y^2*sin(x) + x^2*y + x*y + y*sin(x) + x)*x*y, [(x*y + 1, 1)]) + 

(x*y^2*sin(x) + x^2*y + x*y + y*sin(x) + x, [(y, 1), (x, 1)]) 

sage: bool(decomp.sum().quotient() == f) 

True 

sage: all(check_decomp(r) for r in decomp) 

True 

 

:: 

 

sage: R.<x,y,z>= PolynomialRing(GF(2, 'a')) 

sage: FFPD = FractionWithFactoredDenominatorRing(R) 

sage: f = 1/(x * y * z * (x*y + z)) 

sage: decomp = FFPD(f).leinartas_decomposition() 

sage: decomp 

(0, []) + (1, [(z, 2), (x*y + z, 1)]) + 

(1, [(z, 2), (y, 1), (x, 1)]) 

sage: decomp.sum().quotient() == f 

True 

""" 

if self.dimension() == 1: 

# Sage's lift() function doesn't work in 

# univariate polynomial rings. 

# So nullstellensatz_decomposition() won't work. 

# Can use algebraic_dependence_decomposition(), 

# which is sufficient. 

# temp = FractionWithFactoredDenominatorSum([self]) 

# Alternatively can use univariate_decomposition(), 

# which is more efficient. 

return self.univariate_decomposition() 

temp = self.nullstellensatz_decomposition() 

decomp = FractionWithFactoredDenominatorSum() 

for r in temp: 

decomp.extend(r.algebraic_dependence_decomposition()) 

 

# Simplify and return result. 

return decomp._combine_like_terms_().whole_and_parts() 

 

def cohomology_decomposition(self): 

r""" 

Return the cohomology decomposition of ``self``. 

 

Let `p / (q_1^{e_1} \cdots q_n^{e_n})` be the fraction represented 

by ``self`` and let `K[x_1, \ldots, x_d]` be the polynomial ring 

in which the `q_i` lie. 

Assume that `n \leq d` and that the gradients of the `q_i` are linearly 

independent at all points in the intersection 

`V_1 \cap \ldots \cap V_n` of the algebraic varieties 

`V_i = \{x \in L^d \mid q_i(x) = 0 \}`, where `L` is the algebraic 

closure of the field `K`. 

Return a :class:`FractionWithFactoredDenominatorSum` 

`f` such that the differential form 

`f dx_1 \wedge \cdots \wedge dx_d` is de Rham cohomologous to the 

differential form 

`p / (q_1^{e_1} \cdots q_n^{e_n}) dx_1 \wedge \cdots \wedge dx_d` 

and such that the denominator of each summand of `f` contains 

no repeated irreducible factors. 

 

The algorithm used here comes from the proof of Theorem 17.4 of 

[AiYu1983]_. 

 

OUTPUT: 

 

An instance of :class:`FractionWithFactoredDenominatorSum`. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.asymptotics_multivariate_generating_functions import FractionWithFactoredDenominatorRing 

sage: R.<x> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R) 

sage: f = 1/(x^2 + x + 1)^3 

sage: decomp = FFPD(f).cohomology_decomposition() 

sage: decomp 

(0, []) + (2/3, [(x^2 + x + 1, 1)]) 

 

sage: R.<x,y> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R) 

sage: FFPD(1, [(x, 1), (y, 2)]).cohomology_decomposition() 

(0, []) 

 

sage: p = 1 

sage: qs = [(x*y - 1, 1), (x**2 + y**2 - 1, 2)] 

sage: f = FFPD(p, qs) 

sage: f.cohomology_decomposition() 

(0, []) + (4/3*x*y + 4/3, [(x^2 + y^2 - 1, 1)]) + 

(1/3, [(x*y - 1, 1), (x^2 + y^2 - 1, 1)]) 

""" 

from sage.calculus.functions import jacobian 

from sage.arith.all import xgcd 

from sage.sets.set import Set 

 

R = self.denominator_ring 

df = self.denominator_factored() 

n = len(df) 

if sum(e for (q, e) in df) <= n: 

# No decomposing possible. 

return FractionWithFactoredDenominatorSum([self]) 

 

# Otherwise decompose recursively. 

decomp = FractionWithFactoredDenominatorSum() 

p = self.numerator() 

qs = [q for (q, e) in df] 

X = sorted(R.gens()) 

var_sets_n = Set(X).subsets(n) 

Par = self.parent() 

 

# Compute Jacobian determinants for qs. 

dets = [] 

for v in var_sets_n: 

# Sort v according to the term order of R. 

x = sorted(v) 

jac = jacobian(qs, x) 

dets.append(R(jac.determinant())) 

 

# Get a Nullstellensatz certificate for qs and dets. 

if self.dimension() == 1: 

# Sage's lift() function doesn't work in 

# univariate polynomial rings. 

# So use xgcd(), which does the same thing in this case. 

# Note that by assumption qs and dets have length 1. 

L = xgcd(qs[0], dets[0])[1:] 

else: 

L = R.one().lift(R.ideal(qs + dets)) 

 

# Do first iteration of decomposition. 

iteration1 = FractionWithFactoredDenominatorSum() 

# Contributions from qs. 

for i in range(n): 

if L[i] == 0: 

continue 

# Cancel one df[i] from denominator. 

new_df = [list(t) for t in df] 

if new_df[i][1] > 1: 

new_df[i][1] -= 1 

else: 

del new_df[i] 

iteration1.append(Par(p * L[i], new_df)) 

 

# Contributions from dets. 

# Compute each contribution's cohomologous form using 

# the least index j such that new_df[j][1] > 1. 

# Know such an index exists by first 'if' statement at 

# the top. 

for j in range(n): 

if df[j][1] > 1: 

J = j 

break 

new_df = [list(t) for t in df] 

new_df[J][1] -= 1 

for k in range(var_sets_n.cardinality()): 

if L[n + k] == 0: 

continue 

# Sort variables according to the term order of R. 

x = sorted(var_sets_n[k]) 

# Compute Jacobian in the Symbolic Ring. 

jac = jacobian([SR(p * L[n + k])] + 

[SR(qs[j]) for j in range(n) if j != J], 

[SR(xx) for xx in x]) 

det = jac.determinant() 

psign = permutation_sign(x, X) 

iteration1.append(Par((-1) ** J * det / (psign * new_df[J][1]), 

new_df)) 

 

# Now decompose each FFPD of iteration1. 

for r in iteration1: 

decomp.extend(r.cohomology_decomposition()) 

 

# Simplify and return result. 

return decomp._combine_like_terms_().whole_and_parts() 

 

def asymptotic_decomposition(self, alpha, asy_var=None): 

r""" 

Return the asymptotic decomposition of ``self``. 

 

The asymptotic decomposition of `F` is a sum that has the 

same asymptotic expansion as `f` in the direction ``alpha`` 

but each summand has a denominator factorization of the form 

`[(q_1, 1), \ldots, (q_n, 1)]`, where `n` is at most the 

:meth:`dimension` of `F`. 

 

INPUT: 

 

- ``alpha`` -- a `d`-tuple of positive integers or symbolic variables 

- ``asy_var`` -- (default: ``None``) a symbolic variable with 

respect to which to compute asymptotics; 

if ``None`` is given, we set ``asy_var = var('r')`` 

 

OUTPUT: 

 

An instance of :class:`FractionWithFactoredDenominatorSum`. 

 

The output results from a Leinartas decomposition followed by a 

cohomology decomposition. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.asymptotics_multivariate_generating_functions import FractionWithFactoredDenominatorRing 

sage: R.<x> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R, SR) 

sage: f = (x^2 + 1)/((x - 1)^3*(x + 2)) 

sage: F = FFPD(f) 

sage: alpha = [var('a')] 

sage: F.asymptotic_decomposition(alpha) 

(0, []) + 

(1/54*(5*a^2 + 2*a^2/x + 11*a^2/x^2)*r^2 

- 1/54*(5*a - 2*a/x - 33*a/x^2)*r + 11/27/x^2, 

[(x - 1, 1)]) + (-5/27, [(x + 2, 1)]) 

 

:: 

 

sage: R.<x,y> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R, SR) 

sage: H = (1 - 2*x -y)*(1 - x -2*y)**2 

sage: Hfac = H.factor() 

sage: G = 1/Hfac.unit() 

sage: F = FFPD(G, Hfac) 

sage: alpha = var('a, b') 

sage: F.asymptotic_decomposition(alpha) 

(0, []) + 

(-1/3*r*(a/x - 2*b/y) - 1/3/x + 2/3/y, 

[(x + 2*y - 1, 1), (2*x + y - 1, 1)]) 

""" 

R = self.denominator_ring 

d = self.dimension() 

n = len(self.denominator_factored()) 

X = [SR(x) for x in R.gens()] 

 

# Reduce number of distinct factors in denominator of self 

# down to at most d. 

decomp1 = FractionWithFactoredDenominatorSum([self]) 

if n > d: 

decomp1 = decomp1[0].leinartas_decomposition() 

 

# Reduce to no repeated factors in denominator of each element 

# of decomp1. 

# Compute the cohomology decomposition for each 

# Cauchy differential form generated by each element of decomp. 

if asy_var is None: 

asy_var = var('r') 

cauchy_stuff = prod([X[j] ** (-alpha[j] * asy_var - 1) 

for j in range(d)]) 

decomp2 = FractionWithFactoredDenominatorSum() 

for f in decomp1: 

ff = self.parent()(f.numerator() * cauchy_stuff, 

f.denominator_factored()) 

decomp2.extend(ff.cohomology_decomposition()) 

decomp2 = decomp2._combine_like_terms_() 

 

# Divide out cauchy_stuff from integrands. 

decomp3 = FractionWithFactoredDenominatorSum() 

for f in decomp2: 

ff = self.parent()((f.numerator() / 

cauchy_stuff).simplify_full().collect(asy_var), 

f.denominator_factored()) 

decomp3.append(ff) 

 

return decomp3 

 

def asymptotics(self, p, alpha, N, asy_var=None, numerical=0, 

verbose=False): 

r""" 

Return the asymptotics in the given direction. 

 

This function returns the first `N` terms (some of which could be 

zero) of the asymptotic expansion of the Maclaurin ray coefficients 

`F_{r \alpha}` of the function `F` represented by ``self`` as 

`r \to \infty`, where `r` is ``asy_var`` and ``alpha`` is a tuple 

of positive integers of length `d` which is ``self.dimension()``. 

Assume that 

 

- `F` is holomorphic in a neighborhood of the origin; 

- the unique factorization of the denominator `H` of `F` in the local 

algebraic ring at `p` equals its unique factorization in the local 

analytic ring at `p`; 

- the unique factorization of `H` in the local algebraic ring at `p` 

has at most ``d`` irreducible factors, none of which are repeated 

(one can reduce to this case via :meth:`asymptotic_decomposition()`); 

- `p` is a convenient strictly minimal smooth or multiple point 

with all nonzero coordinates that is critical and nondegenerate 

for ``alpha``. 

 

The algorithms used here come from [RaWi2008a]_ and [RaWi2012]_. 

 

INPUT: 

 

- ``p`` -- a dictionary with keys that can be coerced to equal 

``self.denominator_ring.gens()`` 

- ``alpha`` -- a tuple of length ``self.dimension()`` of 

positive integers or, if `p` is a smooth point, 

possibly of symbolic variables 

- ``N`` -- a positive integer 

- ``asy_var`` -- (default: ``None``) a symbolic variable for the 

asymptotic expansion; if ``none`` is given, then 

``var('r')`` will be assigned 

- ``numerical`` -- (default: 0) a natural number; 

if ``numerical`` is greater than 0, then return a numerical 

approximation of `F_{r \alpha}` with ``numerical`` digits of 

precision; otherwise return exact values 

- ``verbose`` -- (default: ``False``) print the current state of 

the algorithm 

 

OUTPUT: 

 

The tuple ``(asy, exp_scale, subexp_part)``. 

Here ``asy`` is the sum of the first `N` terms (some of which might 

be 0) of the asymptotic expansion of `F_{r\alpha}` as `r \to \infty`; 

``exp_scale**r`` is the exponential factor of ``asy``; 

``subexp_part`` is the subexponential factor of ``asy``. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.asymptotics_multivariate_generating_functions import FractionWithFactoredDenominatorRing 

 

A smooth point example:: 

 

sage: R.<x,y> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R, SR) 

sage: H = (1 - x - y - x*y)**2 

sage: Hfac = H.factor() 

sage: G = 1/Hfac.unit() 

sage: F = FFPD(G, Hfac); print(F) 

(1, [(x*y + x + y - 1, 2)]) 

sage: alpha = [4, 3] 

sage: decomp = F.asymptotic_decomposition(alpha); decomp 

(0, []) + (-3/2*r*(1/y + 1) - 1/2/y - 1/2, [(x*y + x + y - 1, 1)]) 

sage: F1 = decomp[1] 

sage: p = {y: 1/3, x: 1/2} 

sage: asy = F1.asymptotics(p, alpha, 2, verbose=True) 

Creating auxiliary functions... 

Computing derivatives of auxiliary functions... 

Computing derivatives of more auxiliary functions... 

Computing second order differential operator actions... 

sage: asy 

(1/6000*(3600*sqrt(5)*sqrt(3)*sqrt(2)*sqrt(r)/sqrt(pi) 

+ 463*sqrt(5)*sqrt(3)*sqrt(2)/(sqrt(pi)*sqrt(r)))*432^r, 

432, 

3/5*sqrt(5)*sqrt(3)*sqrt(2)*sqrt(r)/sqrt(pi) 

+ 463/6000*sqrt(5)*sqrt(3)*sqrt(2)/(sqrt(pi)*sqrt(r))) 

sage: F.relative_error(asy[0], alpha, [1, 2, 4, 8, 16], asy[1]) 

[((4, 3), 2.083333333, [2.092576110], [-0.0044365330...]), 

((8, 6), 2.787374614, [2.790732875], [-0.0012048112...]), 

((16, 12), 3.826259447, [3.827462310], [-0.0003143703...]), 

((32, 24), 5.328112821, [5.328540787], [-0.0000803222...]), 

((64, 48), 7.475927885, [7.476079664], [-0.0000203023...])] 

 

A multiple point example:: 

 

sage: R.<x,y,z>= PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R, SR) 

sage: H = (4 - 2*x - y - z)**2*(4 - x - 2*y - z) 

sage: Hfac = H.factor() 

sage: G = 16/Hfac.unit() 

sage: F = FFPD(G, Hfac) 

sage: F 

(-16, [(x + 2*y + z - 4, 1), (2*x + y + z - 4, 2)]) 

sage: alpha = [3, 3, 2] 

sage: decomp = F.asymptotic_decomposition(alpha); decomp 

(0, []) + 

(-16*r*(3/y - 4/z) - 16/y + 32/z, 

[(x + 2*y + z - 4, 1), (2*x + y + z - 4, 1)]) 

sage: F1 = decomp[1] 

sage: p = {x: 1, y: 1, z: 1} 

sage: asy = F1.asymptotics(p, alpha, 2, verbose=True) # long time 

Creating auxiliary functions... 

Computing derivatives of auxiliary functions... 

Computing derivatives of more auxiliary functions... 

Computing second-order differential operator actions... 

sage: asy # long time 

(4/3*sqrt(3)*sqrt(r)/sqrt(pi) + 47/216*sqrt(3)/(sqrt(pi)*sqrt(r)), 

1, 4/3*sqrt(3)*sqrt(r)/sqrt(pi) + 47/216*sqrt(3)/(sqrt(pi)*sqrt(r))) 

sage: F.relative_error(asy[0], alpha, [1, 2, 4, 8], asy[1]) # long time 

[((3, 3, 2), 0.9812164307, [1.515572606], [-0.54458543...]), 

((6, 6, 4), 1.576181132, [1.992989399], [-0.26444185...]), 

((12, 12, 8), 2.485286378, [2.712196351], [-0.091301338...]), 

((24, 24, 16), 3.700576827, [3.760447895], [-0.016178847...])] 

""" 

R = self.denominator_ring 

 

# Coerce keys of p into R. 

p = coerce_point(R, p) 

 

if asy_var is None: 

asy_var = var('r') 

d = self.dimension() 

X = list(R.gens()) 

alpha = list(alpha) 

df = self.denominator_factored() 

n = len(df) # Number of smooth factors 

 

# Find greatest i such that X[i] is a convenient coordinate, 

# that is, such that for all (h, e) in df, we have 

# (X[i]*diff(h, X[i])).subs(p) != 0. 

# Assuming such an i exists. 

i = d - 1 

while 0 in [(X[i] * diff(h, X[i])).subs(p) for (h, e) in df]: 

i -= 1 

coordinate = i 

 

if n == 1: 

# Smooth point. 

return self.asymptotics_smooth(p, alpha, N, asy_var, coordinate, 

numerical, verbose=verbose) 

 

# Multiple point. 

return self.asymptotics_multiple(p, alpha, N, asy_var, coordinate, 

numerical, verbose=verbose) 

 

def asymptotics_smooth(self, p, alpha, N, asy_var, coordinate=None, 

numerical=0, verbose=False): 

r""" 

Return the asymptotics in the given direction of a smooth point. 

 

This is the same as :meth:`asymptotics()`, but only in the 

case of a convenient smooth point. 

 

The formulas used for computing the asymptotic expansions are 

Theorems 3.2 and 3.3 [RaWi2008a]_ with the exponent of `H` 

equal to 1. Theorem 3.2 is a specialization of Theorem 3.4 

of [RaWi2012]_ with `n = 1`. 

 

INPUT: 

 

- ``p`` -- a dictionary with keys that can be coerced to equal 

``self.denominator_ring.gens()`` 

- ``alpha`` -- a tuple of length ``d = self.dimension()`` of 

positive integers or, if `p` is a smooth point, 

possibly of symbolic variables 

- ``N`` -- a positive integer 

- ``asy_var`` -- (optional; default: ``None``) a symbolic variable; 

the variable of the asymptotic expansion, 

if none is given, ``var('r')`` will be assigned 

- ``coordinate`` -- (optional; default: ``None``) an integer in 

`\{0, \ldots, d-1\}` indicating a convenient coordinate to base 

the asymptotic calculations on; if ``None`` is assigned, then 

choose ``coordinate=d-1`` 

- ``numerical`` -- (optional; default: 0) a natural number; 

if numerical is greater than 0, then return a numerical approximation 

of the Maclaurin ray coefficients of ``self`` with ``numerical`` 

digits of precision; otherwise return exact values 

- ``verbose`` -- (default: ``False``) print the current state of 

the algorithm 

 

OUTPUT: 

 

The asymptotic expansion. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.asymptotics_multivariate_generating_functions import FractionWithFactoredDenominatorRing 

sage: R.<x> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R) 

sage: H = 2 - 3*x 

sage: Hfac = H.factor() 

sage: G = 1/Hfac.unit() 

sage: F = FFPD(G, Hfac) 

sage: F 

(-1/3, [(x - 2/3, 1)]) 

sage: alpha = [2] 

sage: p = {x: 2/3} 

sage: asy = F.asymptotics_smooth(p, alpha, 3, asy_var=var('r')) 

sage: asy 

(1/2*(9/4)^r, 9/4, 1/2) 

 

:: 

 

sage: R.<x,y> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R) 

sage: H = 1-x-y-x*y 

sage: Hfac = H.factor() 

sage: G = 1/Hfac.unit() 

sage: F = FFPD(G, Hfac) 

sage: alpha = [3, 2] 

sage: p = {y: 1/2*sqrt(13) - 3/2, x: 1/3*sqrt(13) - 2/3} 

sage: F.asymptotics_smooth(p, alpha, 2, var('r'), numerical=3, verbose=True) 

Creating auxiliary functions... 

Computing derivatives of auxiliary functions... 

Computing derivatives of more auxiliary functions... 

Computing second order differential operator actions... 

(71.2^r*(0.369/sqrt(r) - 0.018.../r^(3/2)), 71.2, 0.369/sqrt(r) - 0.018.../r^(3/2)) 

 

sage: q = 1/2 

sage: qq = q.denominator() 

sage: H = 1 - q*x + q*x*y - x^2*y 

sage: Hfac = H.factor() 

sage: G = (1 - q*x)/Hfac.unit() 

sage: F = FFPD(G, Hfac) 

sage: alpha = list(qq*vector([2, 1 - q])) 

sage: alpha 

[4, 1] 

sage: p = {x: 1, y: 1} 

sage: F.asymptotics_smooth(p, alpha, 5, var('r'), verbose=True) # not tested (140 seconds) 

Creating auxiliary functions... 

Computing derivatives of auxiliary functions... 

Computing derivatives of more auxiliary functions... 

Computing second order differential operator actions... 

(1/12*sqrt(3)*2^(2/3)*gamma(1/3)/(pi*r^(1/3)) 

- 1/96*sqrt(3)*2^(1/3)*gamma(2/3)/(pi*r^(5/3)), 

1, 

1/12*sqrt(3)*2^(2/3)*gamma(1/3)/(pi*r^(1/3)) 

- 1/96*sqrt(3)*2^(1/3)*gamma(2/3)/(pi*r^(5/3))) 

""" 

from sage.calculus.functions import jacobian 

from sage.calculus.var import function 

from sage.functions.other import factorial, sqrt 

from sage.functions.gamma import gamma 

from sage.functions.log import exp, log 

from sage.matrix.constructor import matrix 

from sage.modules.free_module_element import vector 

from sage.symbolic.constants import pi 

from sage.symbolic.relation import solve 

from sage.rings.all import CC 

from sage.rings.rational_field import QQ 

 

R = self.denominator_ring 

d = self.dimension() 

I = sqrt(-ZZ.one()) 

# Coerce everything into the Symbolic Ring. 

X = [SR(x) for x in R.gens()] 

G = SR(self.numerator()) 

H = SR(self.denominator()) 

p = {SR(x): p[x] for x in R.gens()} 

alpha = [SR(a) for a in alpha] 

 

# Put given convenient coordinate at end of variable list. 

if coordinate is not None: 

x = X.pop(coordinate) 

X.append(x) 

a = alpha.pop(coordinate) 

alpha.append(a) 

 

# Deal with the simple univariate case first. 

# Same as the multiple point case with n == d. 

# but with a negative sign. 

# I'll just past the code from the multiple point case. 

if d == 1: 

det = jacobian(H, X).subs(p).determinant().abs() 

exp_scale = prod([(p[X[i]] ** (-alpha[i])).subs(p) 

for i in range(d)]) 

subexp_part = -G.subs(p) / (det * prod(p.values())) 

if numerical: 

exp_scale = exp_scale.n(digits=numerical) 

subexp_part = subexp_part.n(digits=numerical) 

return (exp_scale ** asy_var * subexp_part, exp_scale, subexp_part) 

 

# If p is a tuple of rationals, then compute with it directly. 

# Otherwise, compute symbolically and plug in p at the end. 

if vector(p.values()) in QQ ** d: 

P = p 

else: 

sP = [var('p' + str(j)) for j in range(d)] 

P = {X[j]: sP[j] for j in range(d)} 

p = {sP[j]: p[X[j]] for j in range(d)} 

 

# Setup. 

if verbose: 

print("Creating auxiliary functions...") 

# Implicit functions. 

h = function('h')(*tuple(X[:d - 1])) 

U = function('U')(*tuple(X)) 

# All other functions are defined in terms of h, U, and 

# explicit functions. 

Gcheck = -G / U * (h / X[d - 1]) 

A = Gcheck.subs({X[d - 1]: ZZ.one() / h}) / h 

t = 't' 

L = [str(elt) for elt in X] 

while t in L: 

t = t + 't' 

T = [var(t + str(i)) for i in range(d - 1)] 

e = {X[i]: P[X[i]] * exp(I * T[i]) for i in range(d - 1)} 

ht = h.subs(e) 

At = A.subs(e) 

Phit = (-log(P[X[d - 1]] * ht) + 

I * sum([alpha[i] / alpha[d - 1] * T[i] 

for i in range(d - 1)])) 

Tstar = {t: ZZ.zero() for t in T} 

# Store h and U and all their derivatives evaluated at P. 

atP = P.copy() 

atP.update({h.subs(P): ZZ.one() / P[X[d - 1]]}) 

 

# Compute the derivatives of h up to order 2 * N, evaluate at P, 

# and store in atP. 

# Keep a copy of unevaluated h derivatives for use in the case 

# d = 2 and v > 2 below. 

hderivs1 = {} # First derivatives of h. 

for i in range(d - 1): 

s = solve(diff(H.subs({X[d - 1]: ZZ.one() / h}), X[i]), 

diff(h, X[i]))[0].rhs().simplify() 

hderivs1.update({diff(h, X[i]): s}) 

atP.update({diff(h, X[i]).subs(P): s.subs(P).subs(atP)}) 

hderivs = diff_all(h, X[0: d - 1], 2 * N, sub=hderivs1, rekey=h) 

for k in hderivs: 

atP.update({k.subs(P): hderivs[k].subs(atP)}) 

 

# Compute the derivatives of U up to order 2 * N and evaluate at P. 

# To do this, differentiate H = U*Hcheck over and over, evaluate at P, 

# and solve for the derivatives of U at P. 

# Need the derivatives of H with short keys to pass on 

# to diff_prod later. 

Hderivs = diff_all(H, X, 2 * N, ending=[X[d - 1]], sub_final=P) 

if verbose: 

print("Computing derivatives of auxiliary functions...") 

# For convenience in checking if all the nontrivial derivatives of U 

# at p are zero a few line below, store the value of U(p) in atP 

# instead of in Uderivs. 

Uderivs = {} 

atP.update({U.subs(P): diff(H, X[d - 1]).subs(P)}) 

end = [X[d - 1]] 

Hcheck = X[d - 1] - ZZ.one() / h 

k = H.polynomial(CC).degree() - 1 

if k == 0: 

# Then we can conclude that all higher derivatives of U are zero. 

for l in range(1, 2 * N + 1): 

for s in combinations_with_replacement(X, l): 

Uderivs[diff(U, list(s)).subs(P)] = ZZ.zero() 

elif k > 0 and k < 2 * N: 

all_zero = True 

Uderivs = diff_prod(Hderivs, U, Hcheck, X, 

range(1, k + 1), end, Uderivs, atP) 

# Check for a nonzero U derivative. 

if any(u for u in Uderivs.values()): 

all_zero = False 

if all_zero: 

# Then, using a proposition at the end of [RaWi2012], we can 

# conclude that all higher derivatives of U are zero. 

for l in range(k + 1, 2 * N + 1): 

for s in combinations_with_replacement(X, l): 

Uderivs.update({diff(U, list(s)).subs(P): ZZ.zero()}) 

else: 

# Have to compute the rest of the derivatives. 

Uderivs = diff_prod(Hderivs, U, Hcheck, X, 

range(k + 1, 2 * N + 1), end, Uderivs, atP) 

else: 

Uderivs = diff_prod(Hderivs, U, Hcheck, X, 

range(1, 2 * N + 1), end, Uderivs, atP) 

atP.update(Uderivs) 

 

# In general, this algorithm is not designed to handle the case of a 

# singular Phit''(Tstar). 

# However, when d = 2 the algorithm can cope. 

if d == 2: 

# Compute v, the order of vanishing at Tstar of Phit. 

# It is at least 2. 

v = Integer(2) 

Phitderiv = diff(Phit, T[0], 2) 

splat = Phitderiv.subs(Tstar).subs(atP).subs(p).simplify() 

while splat == 0: 

v += 1 

if v > 2 * N: 

# Then need to compute more derivatives of h for atP. 

hderivs.update({diff(h, X[0], v): 

diff(hderivs[diff(h, X[0], v - 1)], 

X[0]).subs(hderivs1)}) 

atP.update({diff(h, X[0], v).subs(P): 

hderivs[diff(h, X[0], v)].subs(atP)}) 

Phitderiv = diff(Phitderiv, T[0]) 

splat = Phitderiv.subs(Tstar).subs(atP).subs(p).simplify() 

 

if d == 2 and v > 2: 

t = T[0] # Simplify variable names. 

a = splat / factorial(v) 

Phitu = Phit - a * t ** v 

 

# Compute all partial derivatives of At and Phitu 

# up to orders 2*(N - 1) and 2*(N - 1) + v, respectively, 

# in case v is even. 

# Otherwise, compute up to orders N - 1 and N - 1 + v, 

# respectively. 

# To speed up later computations, 

# create symbolic functions AA and BB 

# to stand in for the expressions At and Phitu, respectively. 

if verbose: 

print("Computing derivatives of more auxiliary functions...") 

AA = function('AA')(t) 

BB = function('BB')(t) 

if v.mod(2) == 0: 

At_derivs = diff_all(At, T, 2 * N - 2, sub=hderivs1, 

sub_final=[Tstar, atP], rekey=AA) 

Phitu_derivs = diff_all(Phitu, T, 2 * N - 2 +v, 

sub=hderivs1, sub_final=[Tstar, atP], 

zero_order=v + 1, rekey=BB) 

else: 

At_derivs = diff_all(At, T, N - 1, sub=hderivs1, 

sub_final=[Tstar, atP], rekey=AA) 

Phitu_derivs = diff_all(Phitu, T, N - 1 + v, 

sub=hderivs1, sub_final=[Tstar, atP], 

zero_order=v + 1 , rekey=BB) 

AABB_derivs = At_derivs 

AABB_derivs.update(Phitu_derivs) 

AABB_derivs[AA] = At.subs(Tstar).subs(atP) 

AABB_derivs[BB] = Phitu.subs(Tstar).subs(atP) 

if verbose: 

print("Computing second order differential operator actions...") 

DD = diff_op_simple(AA, BB, AABB_derivs, t, v, a, N) 

 

# Plug above into asymptotic formula. 

L = [] 

if v.mod(2) == 0: 

for k in range(N): 

L.append(sum([(-1) ** l * gamma((2 * k + v * l + 1) / v) / 

(factorial(l) * factorial(2 * k + v * l)) * 

DD[(k, l)] for l in range(0, 2 * k + 1)])) 

chunk = (a ** (-1 / v) / (pi * v) * 

sum([alpha[d - 1] ** (-(2 * k + 1) / v) * 

L[k] * asy_var ** (-(2 * k + 1) / v) 

for k in range(N)])) 

else: 

zeta = exp(I * pi / (2 * v)) 

for k in range(N): 

L.append(sum([(-1) ** l * gamma((k + v * l + 1) / v) / 

(factorial(l) * factorial(k + v * l)) * 

(zeta ** (k + v * l + 1) + 

(-1) ** (k + v * l) * 

zeta ** (-(k + v * l + 1))) * 

DD[(k, l)] for l in range(0, k + 1)])) 

chunk = (abs(a) ** (-1 / v) / (2 * pi * v) * 

sum([alpha[d - 1] ** (-(k + 1) / v) * 

L[k] * asy_var ** (-(k + 1) / v) 

for k in range(N)])) 

 

# Asymptotics for d >= 2 case. 

# A singular Phit''(Tstar) will cause a crash in this case. 

else: 

Phit1 = jacobian(Phit, T).subs(hderivs1) 

a = jacobian(Phit1, T).subs(hderivs1).subs(Tstar).subs(atP) 

a_inv = a.inverse() 

Phitu = (Phit - (1 / QQ(2)) * matrix([T]) * 

a * matrix([T]).transpose()) 

Phitu = Phitu[0][0] 

# Compute all partial derivatives of At and Phitu up to 

# orders 2 * N-2 and 2 * N, respectively. 

# Take advantage of the fact that At and Phitu 

# are sufficiently differentiable functions so that mixed partials 

# are equal. Thus only need to compute representative partials. 

# Choose nondecreasing sequences as representative differentiation- 

# order sequences. 

# To speed up later computations, 

# create symbolic functions AA and BB 

# to stand in for the expressions At and Phitu, respectively. 

if verbose: 

print("Computing derivatives of more auxiliary functions...") 

AA = function('AA')(*tuple(T)) 

At_derivs = diff_all(At, T, 2 * N - 2, sub=hderivs1, 

sub_final=[Tstar, atP], rekey=AA) 

BB = function('BB')(*tuple(T)) 

Phitu_derivs = diff_all(Phitu, T, 2 * N, sub=hderivs1, 

sub_final=[Tstar, atP], rekey=BB, zero_order=3) 

AABB_derivs = At_derivs 

AABB_derivs.update(Phitu_derivs) 

AABB_derivs[AA] = At.subs(Tstar).subs(atP) 

AABB_derivs[BB] = Phitu.subs(Tstar).subs(atP) 

if verbose: 

print("Computing second order differential operator actions...") 

DD = diff_op(AA, BB, AABB_derivs, T, a_inv, 1 , N) 

 

# Plug above into asymptotic formula. 

L = [] 

for k in range(N): 

L.append(sum([DD[(0, k, l)] / ((-1) ** k * 2 ** (l + k) * 

factorial(l) * factorial(l + k)) 

for l in range(0, 2 * k + 1)])) 

chunk = sum([(2 * pi) ** ((1 - d) / Integer(2)) * 

a.determinant() ** (-ZZ.one() / Integer(2)) * 

alpha[d - 1] ** ((ZZ.one() - d) / Integer(2) - k) * 

L[k] * 

asy_var ** ((ZZ.one() - d) / Integer(2) - k) 

for k in range(N)]) 

 

chunk = chunk.subs(p).simplify() 

coeffs = chunk.coefficients(asy_var) 

coeffs.reverse() 

coeffs = coeffs[:N] 

if numerical: 

subexp_part = sum([co[0].subs(p).n(digits=numerical) * 

asy_var ** co[1] for co in coeffs]) 

exp_scale = prod([(P[X[i]] ** (-alpha[i])).subs(p) 

for i in range(d)]).n(digits=numerical) 

else: 

subexp_part = sum([co[0].subs(p) * asy_var ** co[1] 

for co in coeffs]) 

exp_scale = prod([(P[X[i]] ** (-alpha[i])).subs(p) 

for i in range(d)]) 

return (exp_scale ** asy_var * subexp_part, exp_scale, subexp_part) 

 

def asymptotics_multiple(self, p, alpha, N, asy_var, coordinate=None, 

numerical=0, verbose=False): 

r""" 

Return the asymptotics in the given direction of a multiple 

point nondegenerate for ``alpha``. 

 

This is the same as :meth:`asymptotics`, but only in the case 

of a convenient multiple point nondegenerate for ``alpha``. 

Assume also that ``self.dimension >= 2`` and that the 

``p.values()`` are not symbolic variables. 

 

The formulas used for computing the asymptotic expansion are 

Theorem 3.4 and Theorem 3.7 of [RaWi2012]_. 

 

INPUT: 

 

- ``p`` -- a dictionary with keys that can be coerced to equal 

``self.denominator_ring.gens()`` 

- ``alpha`` -- a tuple of length ``d = self.dimension()`` of 

positive integers or, if `p` is a smooth point, 

possibly of symbolic variables 

- ``N`` -- a positive integer 

- ``asy_var`` -- (optional; default: ``None``) a symbolic variable; 

the variable of the asymptotic expansion, 

if none is given, ``var('r')`` will be assigned 

- ``coordinate`` -- (optional; default: ``None``) an integer in 

`\{0, \ldots, d-1\}` indicating a convenient coordinate to base 

the asymptotic calculations on; if ``None`` is assigned, then 

choose ``coordinate=d-1`` 

- ``numerical`` -- (optional; default: 0) a natural number; 

if numerical is greater than 0, then return a numerical approximation 

of the Maclaurin ray coefficients of ``self`` with ``numerical`` 

digits of precision; otherwise return exact values 

- ``verbose`` -- (default: ``False``) print the current state of 

the algorithm 

 

OUTPUT: 

 

The asymptotic expansion. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.asymptotics_multivariate_generating_functions import FractionWithFactoredDenominatorRing 

sage: R.<x,y,z>= PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R) 

sage: H = (4 - 2*x - y - z)*(4 - x -2*y - z) 

sage: Hfac = H.factor() 

sage: G = 16/Hfac.unit() 

sage: F = FFPD(G, Hfac) 

sage: F 

(16, [(x + 2*y + z - 4, 1), (2*x + y + z - 4, 1)]) 

sage: p = {x: 1, y: 1, z: 1} 

sage: alpha = [3, 3, 2] 

sage: F.asymptotics_multiple(p, alpha, 2, var('r'), verbose=True) # long time 

Creating auxiliary functions... 

Computing derivatives of auxiliary functions... 

Computing derivatives of more auxiliary functions... 

Computing second-order differential operator actions... 

(4/3*sqrt(3)/(sqrt(pi)*sqrt(r)) - 25/216*sqrt(3)/(sqrt(pi)*r^(3/2)), 

1, 

4/3*sqrt(3)/(sqrt(pi)*sqrt(r)) - 25/216*sqrt(3)/(sqrt(pi)*r^(3/2))) 

 

sage: H = (1 - x*(1 + y))*(1 - z*x**2*(1 + 2*y)) 

sage: Hfac = H.factor() 

sage: G = 1/Hfac.unit() 

sage: F = FFPD(G, Hfac) 

sage: F 

(1, [(x*y + x - 1, 1), (2*x^2*y*z + x^2*z - 1, 1)]) 

sage: p = {x: 1/2, z: 4/3, y: 1} 

sage: alpha = [8, 3, 3] 

sage: F.asymptotics_multiple(p, alpha, 2, var('r'), coordinate=1, verbose=True) # long time 

Creating auxiliary functions... 

Computing derivatives of auxiliary functions... 

Computing derivatives of more auxiliary functions... 

Computing second-order differential operator actions... 

(1/172872*108^r*(24696*sqrt(7)*sqrt(3)/(sqrt(pi)*sqrt(r)) 

- 1231*sqrt(7)*sqrt(3)/(sqrt(pi)*r^(3/2))), 

108, 

1/7*sqrt(7)*sqrt(3)/(sqrt(pi)*sqrt(r)) 

- 1231/172872*sqrt(7)*sqrt(3)/(sqrt(pi)*r^(3/2))) 

 

:: 

 

sage: R.<x,y> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R, SR) 

sage: H = (1 - 2*x - y) * (1 - x - 2*y) 

sage: Hfac = H.factor() 

sage: G = exp(x + y)/Hfac.unit() 

sage: F = FFPD(G, Hfac) 

sage: F 

(e^(x + y), [(x + 2*y - 1, 1), (2*x + y - 1, 1)]) 

sage: p = {x: 1/3, y: 1/3} 

sage: alpha = (var('a'), var('b')) 

sage: F.asymptotics_multiple(p, alpha, 2, var('r')) # long time 

(3*((1/3)^(-a)*(1/3)^(-b))^r*e^(2/3), (1/3)^(-a)*(1/3)^(-b), 3*e^(2/3)) 

""" 

from itertools import product 

from sage.calculus.functions import jacobian 

from sage.calculus.var import function 

from sage.combinat.combinat import stirling_number1 

from sage.functions.log import exp, log 

from sage.functions.other import factorial, sqrt 

from sage.matrix.constructor import matrix 

from sage.misc.mrange import xmrange 

from sage.modules.free_module_element import vector 

from sage.rings.all import CC 

from sage.arith.misc import binomial 

from sage.rings.rational_field import QQ 

from sage.symbolic.constants import pi 

from sage.symbolic.relation import solve 

 

R = self.denominator_ring 

 

# Coerce keys of p into R. 

p = coerce_point(R, p) 

 

d = self.dimension() 

I = sqrt(-ZZ.one()) 

# Coerce everything into the Symbolic Ring. 

X = [SR(x) for x in R.gens()] 

G = SR(self.numerator()) 

H = [SR(h) for (h, e) in self.denominator_factored()] 

Hprod = prod(H) 

n = len(H) 

P = {SR(x): p[x] for x in R.gens()} 

Sstar = self._crit_cone_combo(p, alpha, coordinate) 

 

# Put the given convenient variable at end of variable list. 

if coordinate is not None: 

x = X.pop(coordinate) 

X.append(x) 

a = alpha.pop(coordinate) 

alpha.append(a) 

 

# Case n = d. 

if n == d: 

det = jacobian(H, X).subs(P).determinant().abs() 

exp_scale = prod([(P[X[i]] ** (-alpha[i])).subs(P) 

for i in range(d)]) 

subexp_part = G.subs(P) / (det * prod(P.values())) 

if numerical: 

exp_scale = exp_scale.n(digits=numerical) 

subexp_part = subexp_part.n(digits=numerical) 

return (exp_scale ** asy_var * subexp_part, exp_scale, subexp_part) 

 

# Case n < d. 

# If P is a tuple of rationals, then compute with it directly. 

# Otherwise, compute symbolically and plug in P at the end. 

if vector(P.values()) not in QQ ** d: 

sP = [var('p' + str(j)) for j in range(d)] 

P = {X[j]: sP[j] for j in range(d)} 

p = {sP[j]: p[X[j]] for j in range(d)} 

 

# Setup. 

if verbose: 

print("Creating auxiliary functions...") 

# Create T and S variables. 

t = 't' 

L = [str(elt) for elt in X] 

while t in L: 

t = t + 't' 

T = [var(t + str(i)) for i in range(d - 1)] 

s = 's' 

while s in L: 

s = s + 't' 

S = [var(s + str(i)) for i in range(n - 1)] 

Sstar = {S[j]: Sstar[j] for j in range(n - 1)} 

thetastar = {t: ZZ.zero() for t in T} 

thetastar.update(Sstar) 

# Create implicit functions. 

h = [function('h' + str(j))(*tuple(X[:d - 1])) for j in range(n)] 

U = function('U')(*tuple(X)) 

# All other functions are defined in terms of h, U, and 

# explicit functions. 

Hcheck = prod([X[d - 1] - ZZ.one() / h[j] for j in range(n)]) 

Gcheck = -G / U * prod([-h[j] / X[d - 1] for j in range(n)]) 

A = [(-1) ** (n - 1) * X[d - 1] ** (-n + j) * 

diff(Gcheck.subs({X[d - 1]: ZZ.one() / X[d - 1]}), X[d - 1], j) 

for j in range(n)] 

e = {X[i]: P[X[i]] * exp(I * T[i]) for i in range(d - 1)} 

ht = [hh.subs(e) for hh in h] 

hsumt = (sum([S[j] * ht[j] for j in range(n - 1)]) + 

(ZZ.one() - sum(S)) * ht[n - 1]) 

At = [AA.subs(e).subs({X[d - 1]: hsumt}) for AA in A] 

Phit = (-log(P[X[d - 1]] * hsumt) + 

I * sum([alpha[i] / alpha[d - 1] * T[i] 

for i in range(d - 1)])) 

# atP Stores h and U and all their derivatives evaluated at C. 

atP = P.copy() 

atP.update({hh.subs(P): ZZ.one() / P[X[d - 1]] for hh in h}) 

 

# Compute the derivatives of h up to order 2 * N and evaluate at P. 

hderivs1 = {} # First derivatives of h. 

for (i, j) in xmrange([d - 1, n], tuple): 

s = solve(diff(H[j].subs({X[d - 1]: ZZ.one() / h[j]}), X[i]), 

diff(h[j], X[i]))[0].rhs().simplify() 

hderivs1.update({diff(h[j], X[i]): s}) 

atP.update({diff(h[j], X[i]).subs(P): s.subs(P).subs(atP)}) 

hderivs = diff_all(h, X[0:d - 1], 2 * N, sub=hderivs1, rekey=h) 

for k in hderivs: 

atP.update({k.subs(P): hderivs[k].subs(atP)}) 

 

# Compute the derivatives of U up to order 2 * N - 2 + min{n, N} - 1 and 

# evaluate at P. 

# To do this, differentiate H = U*Hcheck over and over, evaluate at P, 

# and solve for the derivatives of U at P. 

# Need the derivatives of H with short keys to pass on to 

# diff_prod later. 

if verbose: 

print("Computing derivatives of auxiliary functions...") 

m = min(n, N) 

end = [X[d-1] for j in range(n)] 

Hprodderivs = diff_all(Hprod, X, 2 * N - 2 + n, ending=end, sub_final=P) 

atP.update({U.subs(P): diff(Hprod, X[d - 1], n).subs(P)/factorial(n)}) 

Uderivs = {} 

k = Hprod.polynomial(CC).degree() - n 

if k == 0: 

# Then we can conclude that all higher derivatives of U are zero. 

for l in range(1, 2 * N - 2 + m): 

for s in combinations_with_replacement(X, l): 

Uderivs[diff(U, list(s)).subs(P)] = ZZ.zero() 

elif k > 0 and k < 2 * N - 2 + m - 1: 

all_zero = True 

Uderivs = diff_prod(Hprodderivs, U, Hcheck, X, 

range(1, k + 1), end, Uderivs, atP) 

# Check for a nonzero U derivative. 

if any(u for u in Uderivs.values()): 

all_zero = False 

if all_zero: 

# Then all higher derivatives of U are zero. 

for l in range(k + 1, 2 * N - 2 + m): 

for s in combinations_with_replacement(X, l): 

Uderivs.update({diff(U, list(s)).subs(P): ZZ.zero()}) 

else: 

# Have to compute the rest of the derivatives. 

Uderivs = diff_prod(Hprodderivs, U, Hcheck, X, 

range(k + 1, 2 * N - 2 + m), end, 

Uderivs, atP) 

else: 

Uderivs = diff_prod(Hprodderivs, U, Hcheck, X, 

range(1, 2 * N - 2 + m), end, Uderivs, atP) 

atP.update(Uderivs) 

Phit1 = jacobian(Phit, T + S).subs(hderivs1) 

a = jacobian(Phit1, T + S).subs(hderivs1).subs(thetastar).subs(atP) 

a_inv = a.inverse() 

Phitu = (Phit - (1 / Integer(2)) * matrix([T + S]) * a * 

matrix([T + S]).transpose()) 

Phitu = Phitu[0][0] 

 

# Compute all partial derivatives of At and Phitu up to orders 2 * N - 2 

# and 2 * N, respectively. Take advantage of the fact that At and Phitu 

# are sufficiently differentiable functions so that mixed partials 

# are equal. Thus only need to compute representative partials. 

# Choose nondecreasing sequences as representative differentiation- 

# order sequences. 

# To speed up later computations, create symbolic functions AA and BB 

# to stand in for the expressions At and Phitu respectively. 

if verbose: 

print("Computing derivatives of more auxiliary functions...") 

AA = [function('A' + str(j))(*tuple(T + S)) for j in range(n)] 

At_derivs = diff_all(At, T + S, 2 * N - 2, sub=hderivs1, 

sub_final=[thetastar, atP], rekey=AA) 

BB = function('BB')(*tuple(T + S)) 

Phitu_derivs = diff_all(Phitu, T + S, 2 * N, sub=hderivs1, 

sub_final=[thetastar, atP], rekey=BB, zero_order=3) 

AABB_derivs = At_derivs 

AABB_derivs.update(Phitu_derivs) 

for j in range(n): 

AABB_derivs[AA[j]] = At[j].subs(thetastar).subs(atP) 

AABB_derivs[BB] = Phitu.subs(thetastar).subs(atP) 

 

if verbose: 

print("Computing second-order differential operator actions...") 

DD = diff_op(AA, BB, AABB_derivs, T + S, a_inv, n, N) 

L = {} 

for (j, k) in product(range(min(n, N)), range(max(0, N - 1 - n), N)): 

if j + k <= N - 1: 

L[(j, k)] = sum([DD[(j, k, l)] / ((-1) ** k * 2 ** (k + l) * 

factorial(l) * 

factorial(k + l)) 

for l in range(2 * k + 1)]) 

det = (a.determinant() ** (-1 / Integer(2)) * 

(2 * pi) ** ((n - d) / Integer(2))) 

chunk = det * sum([(alpha[d - 1] * asy_var) ** ((n - d) / 

Integer(2) - q) * 

sum([L[(j, k)] * binomial(n - 1, j) * 

stirling_number1(n - j, n + k - q) * 

(-1) ** (q - j - k) 

for (j, k) in product(range(min(n - 1, q) + 1), 

range(max(0, q - n), 

q + 1)) 

if j + k <= q]) 

for q in range(N)]) 

chunk = chunk.subs(P).simplify() 

coeffs = chunk.coefficients(asy_var) 

coeffs.reverse() 

coeffs = coeffs[:N] 

if numerical: 

subexp_part = sum([co[0].subs(p).n(digits=numerical) * 

asy_var ** co[1] 

for co in coeffs]) 

exp_scale = prod([(P[X[i]] ** (-alpha[i])).subs(p) 

for i in range(d)]).n(digits=numerical) 

else: 

subexp_part = sum([co[0].subs(p) * asy_var ** co[1] 

for co in coeffs]) 

exp_scale = prod([(P[X[i]] ** (-alpha[i])).subs(p) 

for i in range(d)]) 

return (exp_scale ** asy_var * subexp_part, exp_scale, subexp_part) 

 

def _crit_cone_combo(self, p, alpha, coordinate=None): 

r""" 

Return an auxiliary point associated to the multiple 

point ``p`` of the factors ``self``. 

 

INPUT: 

 

- ``p`` -- a dictionary with keys that can be coerced to equal 

``self.denominator_ring.gens()`` 

- ``alpha`` -- a list of rationals 

 

OUTPUT: 

 

A solution of the matrix equation `y \Gamma = \alpha^{\prime}` for `y`, 

where `\Gamma` is the matrix given by 

``[direction(v) for v in self.log_grads(p)]`` and 

`\alpha^{\prime}` is ``direction(alpha)``. 

 

.. SEEALSO:: 

 

:func:`direction` 

 

.. NOTE:: 

 

For internal use by 

:meth:`FractionWithFactoredDenominator.asymptotics_multiple()`. 

 

.. NOTE:: 

 

Use this function only when `\Gamma` is well-defined and 

there is a unique solution to the matrix equation 

`y \Gamma = \alpha'`. Fails otherwise. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.asymptotics_multivariate_generating_functions import FractionWithFactoredDenominatorRing 

sage: R.<x,y> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R, SR) 

sage: p = exp(x) 

sage: df = [(1 - 2*x - y, 1), (1 - x - 2*y, 1)] 

sage: f = FFPD(p, df) 

sage: p = {x: 1/3, y: 1/3} 

sage: alpha = (var('a'), var('b')) 

sage: f._crit_cone_combo(p, alpha) 

[1/3*(2*a - b)/b, -2/3*(a - 2*b)/b] 

""" 

from sage.matrix.constructor import matrix 

from sage.symbolic.relation import solve 

 

# Assuming here that each log_grads(f) has nonzero final component. 

# Then 'direction' will not throw a division by zero error. 

R = self.denominator_ring 

 

# Coerce keys of p into R. 

p = coerce_point(R, p) 

 

d = self.dimension() 

n = len(self.denominator_factored()) 

Gamma = matrix([direction(v, coordinate) for v in self.log_grads(p)]) 

beta = direction(alpha, coordinate) 

# solve_left() fails when working in SR :-(. 

# So use solve() instead. 

# Gamma.solve_left(vector(beta)) 

V = [var('sss' + str(i)) for i in range(n)] 

M = matrix(V) * Gamma 

eqns = [M[0][j] == beta[j] for j in range(d)] 

s = solve(eqns, V, solution_dict=True)[0] # Assume a unique solution. 

return [s[v] for v in V] 

 

def grads(self, p): 

r""" 

Return a list of the gradients of the polynomials 

``[q for (q, e) in self.denominator_factored()]`` evaluated at ``p``. 

 

INPUT: 

 

- ``p`` -- (optional; default: ``None``) a dictionary whose keys are 

the generators of ``self.denominator_ring`` 

 

OUTPUT: 

 

A list. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.asymptotics_multivariate_generating_functions import FractionWithFactoredDenominatorRing 

sage: R.<x,y> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R, SR) 

sage: p = exp(x) 

sage: df = [(x^3 + 3*y^2, 5), (x*y, 2), (y, 1)] 

sage: f = FFPD(p, df) 

sage: f 

(e^x, [(y, 1), (x*y, 2), (x^3 + 3*y^2, 5)]) 

sage: R.gens() 

(x, y) 

sage: p = None 

sage: f.grads(p) 

[(0, 1), (y, x), (3*x^2, 6*y)] 

 

sage: p = {x: sqrt(2), y: var('a')} 

sage: f.grads(p) 

[(0, 1), (a, sqrt(2)), (6, 6*a)] 

""" 

R = self.denominator_ring 

 

# Coerce keys of p into R. 

p = coerce_point(R, p) 

 

X = R.gens() 

d = self.dimension() 

H = [h for (h, e) in self.denominator_factored()] 

n = len(H) 

return [tuple([diff(H[i], X[j]).subs(p) for j in range(d)]) 

for i in range(n)] 

 

def log_grads(self, p): 

r""" 

Return a list of the logarithmic gradients of the polynomials 

``[q for (q, e) in self.denominator_factored()]`` evaluated at ``p``. 

 

The logarithmic gradient of a function `f` at point `p` is the 

vector `(x_1 \partial_1 f(x), \ldots, x_d \partial_d f(x) )` 

evaluated at `p`. 

 

INPUT: 

 

- ``p`` -- (optional; default: ``None``) a dictionary whose keys 

are the generators of ``self.denominator_ring`` 

 

OUTPUT: 

 

A list. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.asymptotics_multivariate_generating_functions import FractionWithFactoredDenominatorRing 

sage: R.<x,y> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R, SR) 

sage: p = exp(x) 

sage: df = [(x^3 + 3*y^2, 5), (x*y, 2), (y, 1)] 

sage: f = FFPD(p, df) 

sage: f 

(e^x, [(y, 1), (x*y, 2), (x^3 + 3*y^2, 5)]) 

sage: R.gens() 

(x, y) 

sage: p = None 

sage: f.log_grads(p) 

[(0, y), (x*y, x*y), (3*x^3, 6*y^2)] 

 

sage: p = {x: sqrt(2), y: var('a')} 

sage: f.log_grads(p) 

[(0, a), (sqrt(2)*a, sqrt(2)*a), (6*sqrt(2), 6*a^2)] 

""" 

R = self.denominator_ring 

 

# Coerce keys of p into R. 

p = coerce_point(R, p) 

 

X = R.gens() 

d = self.dimension() 

H = [h for (h, e) in self.denominator_factored()] 

n = len(H) 

return [tuple([(X[j] * diff(H[i], X[j])).subs(p) for j in range(d)]) 

for i in range(n)] 

 

def critical_cone(self, p, coordinate=None): 

r""" 

Return the critical cone of the convenient multiple point ``p``. 

 

INPUT: 

 

- ``p`` -- a dictionary with keys that can be coerced to equal 

``self.denominator_ring.gens()`` and values in a field 

- ``coordinate`` -- (optional; default: ``None``) a natural number 

 

OUTPUT: 

 

A list of vectors. 

 

This list of vectors generate the critical cone of ``p`` and 

the cone itself, which is ``None`` if the values of ``p`` don't lie in 

`\QQ`. Divide logarithmic gradients by their component ``coordinate`` 

entries. If ``coordinate = None``, then search from `d-1` down to 0 

for the first index ``j`` such that for all ``i`` we have 

``self.log_grads()[i][j] != 0`` and set ``coordinate = j``. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.asymptotics_multivariate_generating_functions import FractionWithFactoredDenominatorRing 

sage: R.<x,y,z> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R) 

sage: G = 1 

sage: H = (1 - x*(1 + y)) * (1 - z*x**2*(1 + 2*y)) 

sage: Hfac = H.factor() 

sage: G = 1/Hfac.unit() 

sage: F = FFPD(G, Hfac) 

sage: p = {x: 1/2, y: 1, z: 4/3} 

sage: F.critical_cone(p) 

([(2, 1, 0), (3, 1, 3/2)], 2-d cone in 3-d lattice N) 

""" 

from sage.geometry.cone import Cone 

 

R = self.denominator_ring 

 

# Coerce keys of p into R. 

p = coerce_point(R, p) 

 

d = self.dimension() 

lg = self.log_grads(p) 

n = len(lg) 

if coordinate not in range(d): 

# Search from d-1 down to 0 for a coordinate j such that 

# for all i we have lg[i][j] != 0. 

# One is guaranteed to exist in the case of a convenient multiple 

# point. 

for j in reversed(range(d)): 

if 0 not in [lg[i][j] for i in range(n)]: 

coordinate = j 

break 

Gamma = [direction(v, coordinate) for v in lg] 

try: 

cone = Cone(Gamma) 

except TypeError: 

cone = None 

return (Gamma, cone) 

 

def is_convenient_multiple_point(self, p): 

r""" 

Tests if ``p`` is a convenient multiple point of ``self``. 

 

In case ``p`` is a convenient multiple point, ``verdict = True`` and 

``comment`` is a string stating which variables it's convenient to use. 

In case ``p`` is not, ``verdict = False`` and ``comment`` is a string 

explaining why ``p`` fails to be a convenient multiple point. 

 

See [RaWi2012]_ for more details. 

 

INPUT: 

 

- ``p`` -- a dictionary with keys that can be coerced to equal 

``self.denominator_ring.gens()`` 

 

OUTPUT: 

 

A pair ``(verdict, comment)``. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.asymptotics_multivariate_generating_functions import FractionWithFactoredDenominatorRing 

sage: R.<x,y,z> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R) 

sage: H = (1 - x*(1 + y)) * (1 - z*x**2*(1 + 2*y)) 

sage: df = H.factor() 

sage: G = 1 / df.unit() 

sage: F = FFPD(G, df) 

sage: p1 = {x: 1/2, y: 1, z: 4/3} 

sage: p2 = {x: 1, y: 2, z: 1/2} 

sage: F.is_convenient_multiple_point(p1) 

(True, 'convenient in variables [x, y]') 

sage: F.is_convenient_multiple_point(p2) 

(False, 'not a singular point') 

""" 

from sage.combinat.subset import Subsets 

from sage.matrix.constructor import matrix 

 

R = self.denominator_ring 

 

# Coerce keys of p into R. 

p = coerce_point(R, p) 

 

H = [h for (h, e) in self.denominator_factored()] 

n = len(H) 

d = self.dimension() 

 

# Test 1: Are the factors in H zero at p? 

if [h.subs(p) for h in H] != [0 for h in H]: 

# Failed test 1. Move on to next point. 

return (False, 'not a singular point') 

 

# Test 2: Are the factors in H smooth at p? 

grads = self.grads(p) 

for v in grads: 

if v == [0 for i in range(d)]: 

return (False, 'not smooth point of factors') 

 

# Test 3: Do the factors in H intersect transversely at p? 

if n <= d: 

M = matrix(grads) 

if M.rank() != n: 

return (False, 'not a transverse intersection') 

else: 

# Check all sub-multisets of grads of size d. 

for S in Subsets(grads, d, submultiset=True): 

M = matrix(S) 

if M.rank() != d: 

return (False, 'not a transverse intersection') 

 

# Test 4: Is p convenient? 

M = matrix(self.log_grads(p)) 

convenient_coordinates = [] 

for j in range(d): 

if 0 not in M.columns()[j]: 

convenient_coordinates.append(j) 

if not convenient_coordinates: 

return (False, 'multiple point but not convenient') 

 

# Tests all passed 

X = R.gens() 

convenientX = [X[i] for i in convenient_coordinates] 

return (True, 'convenient in variables {}'.format(convenientX)) 

 

def singular_ideal(self): 

r""" 

Return the singular ideal of ``self``. 

 

Let `R` be the ring of ``self`` and `H` its denominator. 

Let `H_{red}` be the reduction (square-free part) of `H`. 

Return the ideal in `R` generated by `H_{red}` and 

its partial derivatives. 

If the coefficient field of `R` is algebraically closed, 

then the output is the ideal of the singular locus (which 

is a variety) of the variety of `H`. 

 

OUTPUT: 

 

An ideal. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.asymptotics_multivariate_generating_functions import FractionWithFactoredDenominatorRing 

sage: R.<x,y,z> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R) 

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

sage: df = H.factor() 

sage: G = 1 / df.unit() 

sage: F = FFPD(G, df) 

sage: F.singular_ideal() 

Ideal (x*y + x - 1, y^2 - 2*y*z + 2*y - z + 1, x*z + y - 2*z + 1) of 

Multivariate Polynomial Ring in x, y, z over Rational Field 

""" 

R = self.denominator_ring 

 

Hred = prod([h for (h, e) in self.denominator_factored()]) 

J = R.ideal([Hred] + Hred.gradient()) 

return R.ideal(J.groebner_basis()) 

 

def smooth_critical_ideal(self, alpha): 

r""" 

Return the smooth critical ideal of ``self``. 

 

Let `R` be the ring of ``self`` and `H` its denominator. 

Return the ideal in `R` of smooth critical points of the variety 

of `H` for the direction ``alpha``. 

If the variety `V` of `H` has no smooth points, then return the ideal 

in `R` of `V`. 

 

See [RaWi2012]_ for more details. 

 

INPUT: 

 

- ``alpha`` -- a tuple of positive integers and/or symbolic entries 

of length ``self.denominator_ring.ngens()`` 

 

OUTPUT: 

 

An ideal. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.asymptotics_multivariate_generating_functions import FractionWithFactoredDenominatorRing 

sage: R.<x,y> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R) 

sage: H = (1 - x - y - x*y)^2 

sage: Hfac = H.factor() 

sage: G = 1/Hfac.unit() 

sage: F = FFPD(G, Hfac) 

sage: alpha = var('a1, a2') 

sage: F.smooth_critical_ideal(alpha) 

Ideal (y^2 + 2*a1/a2*y - 1, x + ((-a2)/a1)*y + (-a1 + a2)/a1) of 

Multivariate Polynomial Ring in x, y over Fraction Field of 

Multivariate Polynomial Ring in a1, a2 over Rational Field 

 

sage: H = (1-x-y-x*y)^2 

sage: Hfac = H.factor() 

sage: G = 1/Hfac.unit() 

sage: F = FFPD(G, Hfac) 

sage: alpha = [7/3, var('a')] 

sage: F.smooth_critical_ideal(alpha) 

Ideal (y^2 + 14/(3*a)*y - 1, x + (-3/7*a)*y + 3/7*a - 1) of 

Multivariate Polynomial Ring in x, y over Fraction Field of 

Univariate Polynomial Ring in a over Rational Field 

""" 

from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing 

 

R = self.denominator_ring 

Hred = prod([h for (h, e) in self.denominator_factored()]) 

K = R.base_ring() 

d = self.dimension() 

 

# Expand K by the variables of alpha if there are any. 

indets = [] 

for a in alpha: 

if a not in K and a in SR: 

indets.append(a) 

indets = sorted(set(indets), key=str) # Delete duplicates in indets. 

if indets: 

L = PolynomialRing(K, indets).fraction_field() 

S = R.change_ring(L) 

# Coerce alpha into L. 

alpha = [L(a) for a in alpha] 

else: 

S = R 

 

# Find smooth, critical points for alpha. 

X = S.gens() 

Hred = S(Hred) 

J = S.ideal([Hred] + 

[alpha[d - 1] * X[i] * diff(Hred, X[i]) - 

alpha[i] * X[d - 1] * diff(Hred, X[d - 1]) 

for i in range(d - 1)]) 

return S.ideal(J.groebner_basis()) 

 

def maclaurin_coefficients(self, multi_indices, numerical=0): 

r""" 

Return the Maclaurin coefficients of ``self`` with given 

``multi_indices``. 

 

INPUT: 

 

- ``multi_indices`` -- a list of tuples of positive integers, where 

each tuple has length ``self.dimension()`` 

- ``numerical`` -- (optional; default: 0) a natural number; if 

positive, return numerical approximations of coefficients with 

``numerical`` digits of accuracy 

 

OUTPUT: 

 

A dictionary whose value of the key ``nu`` are the Maclaurin 

coefficient of index ``nu`` of ``self``. 

 

.. NOTE:: 

 

Uses iterated univariate Maclaurin expansions. Slow. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.asymptotics_multivariate_generating_functions import FractionWithFactoredDenominatorRing 

sage: R.<x> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R) 

sage: H = 2 - 3*x 

sage: Hfac = H.factor() 

sage: G = 1 / Hfac.unit() 

sage: F = FFPD(G, Hfac) 

sage: F 

(-1/3, [(x - 2/3, 1)]) 

sage: F.maclaurin_coefficients([(2*k,) for k in range(6)]) 

{(0,): 1/2, 

(2,): 9/8, 

(4,): 81/32, 

(6,): 729/128, 

(8,): 6561/512, 

(10,): 59049/2048} 

 

:: 

 

sage: R.<x,y,z> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R) 

sage: H = (4 - 2*x - y - z) * (4 - x - 2*y - z) 

sage: Hfac = H.factor() 

sage: G = 16 / Hfac.unit() 

sage: F = FFPD(G, Hfac) 

sage: alpha = vector([3, 3, 2]) 

sage: interval = [1, 2, 4] 

sage: S = [r*alpha for r in interval] 

sage: F.maclaurin_coefficients(S, numerical=10) 

{(3, 3, 2): 0.7849731445, 

(6, 6, 4): 0.7005249476, 

(12, 12, 8): 0.5847732654} 

""" 

R = self.denominator_ring 

d = self.dimension() 

coeffs = {} 

 

# Deal with the simple univariate case first. 

if d == 1: 

f = SR(self.quotient()) 

x = SR(R.gens()[0]) 

m = max(multi_indices)[0] 

f = f.taylor(x, 0, m) 

F = R(f) 

tmp = F.coefficients() 

for nu in multi_indices: 

val = tmp[nu[0]] 

if numerical: 

val = val.n(digits=numerical) 

coeffs[tuple(nu)] = val 

return coeffs 

 

# Create biggest multi-index needed. 

alpha = [] 

for i in range(d): 

alpha.append(max(nu[i] for nu in multi_indices)) 

 

# Compute Maclaurin expansion of self up to index alpha. 

# Use iterated univariate expansions. 

# Slow! 

f = SR(self.quotient()) 

X = [SR(g) for g in R.gens()] 

for i in range(d): 

f = f.taylor(X[i], 0, alpha[i]) 

F = R(f) 

 

# Collect coefficients. 

X = R.gens() 

for nu in multi_indices: 

monomial = prod(X[i] ** nu[i] for i in range(d)) 

val = F.monomial_coefficient(monomial) 

if numerical: 

val = val.n(digits=numerical) 

coeffs[tuple(nu)] = val 

return coeffs 

 

def relative_error(self, approx, alpha, interval, exp_scale=Integer(1), 

digits=10): 

r""" 

Return the relative error between the values of the Maclaurin 

coefficients of ``self`` with multi-indices ``r alpha`` for ``r`` in 

``interval`` and the values of the functions (of the variable ``r``) 

in ``approx``. 

 

INPUT: 

 

- ``approx`` -- an individual or list of symbolic expressions in 

one variable 

- ``alpha`` - a list of positive integers of length 

``self.denominator_ring.ngens()`` 

- ``interval`` -- a list of positive integers 

- ``exp_scale`` -- (optional; default: 1) a number 

 

OUTPUT: 

 

A list of tuples with properties described below. 

 

This outputs a list whose entries are a tuple 

``(r*alpha, a_r, b_r, err_r)`` for ``r`` in ``interval``. 

Here ``r*alpha`` is a tuple; ``a_r`` is the ``r*alpha`` (multi-index) 

coefficient of the Maclaurin series for ``self`` divided by 

``exp_scale**r``; 

``b_r`` is a list of the values of the functions in ``approx`` 

evaluated at ``r`` and divided by ``exp_scale**m``; 

``err_r`` is the list of relative errors 

``(a_r - f)/a_r`` for ``f`` in ``b_r``. 

All outputs are decimal approximations. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.asymptotics_multivariate_generating_functions import FractionWithFactoredDenominatorRing 

sage: R.<x,y> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R) 

sage: H = 1 - x - y - x*y 

sage: Hfac = H.factor() 

sage: G = 1 / Hfac.unit() 

sage: F = FFPD(G, Hfac) 

sage: alpha = [1, 1] 

sage: r = var('r') 

sage: a1 = (0.573/sqrt(r))*5.83^r 

sage: a2 = (0.573/sqrt(r) - 0.0674/r^(3/2))*5.83^r 

sage: es = 5.83 

sage: F.relative_error([a1, a2], alpha, [1, 2, 4, 8], es) # long time 

[((1, 1), 0.5145797599, 

[0.5730000000, 0.5056000000], [-0.1135300000, 0.01745066667]), 

((2, 2), 0.3824778089, 

[0.4051721856, 0.3813426871], [-0.05933514614, 0.002967810973]), 

((4, 4), 0.2778630595, 

[0.2865000000, 0.2780750000], [-0.03108344267, -0.0007627515584]), 

((8, 8), 0.1991088276, 

[0.2025860928, 0.1996074055], [-0.01746414394, -0.002504047242])] 

""" 

from sage.modules.free_module_element import vector 

 

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

approx = [approx] 

if approx[0].variables(): 

av = approx[0].variables()[0] 

else: 

av = ZZ.one() 

 

# Get Maclaurin coefficients of self. 

alpha = vector(alpha) 

multi_indices = [r * alpha for r in interval] 

mac = self.maclaurin_coefficients(multi_indices, numerical=digits) 

#mac = self.old_maclaurin_coefficients(alpha, max(interval)) 

mac_approx = {} 

stats = [] 

for r in interval: 

exp_s_r = exp_scale ** r 

beta = tuple(r * alpha) 

mac[beta] = (mac[beta] / exp_s_r).n(digits=digits) 

mac_approx[beta] = [(f.subs({av: r}) / exp_s_r).n(digits=digits) 

for f in approx] 

stats_row = [beta, mac[beta], mac_approx[beta]] 

if mac[beta] == 0: 

stats_row.extend([None for a in mac_approx[beta]]) 

else: 

stats_row.append([(mac[beta] - a) / mac[beta] 

for a in mac_approx[beta]]) 

stats.append(tuple(stats_row)) 

return stats 

 

def _add_(left, right): 

r""" 

Returns the sum of ``left`` with ``right``. 

 

INPUT: 

 

- ``left`` -- the left summand (i.e. ``self``) 

 

- ``right`` -- the right summand 

 

OUTPUT: 

 

The sum as a new element. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.asymptotics_multivariate_generating_functions import FractionWithFactoredDenominatorRing 

sage: R.<x,y> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R) 

sage: df = (x, 1), (y, 1), (x*y + 1, 1) 

sage: f = FFPD(2, df) 

sage: g = FFPD(2*x*y, df) 

sage: f + g 

(2, [(y, 1), (x, 1)]) 

""" 

return FractionWithFactoredDenominatorSum([left, right]).sum() 

 

def _mul_(left, right): 

r""" 

Returns the product of ``left`` with ``right``. 

 

INPUT: 

 

- ``left`` -- the left factor (i.e. ``self``) 

 

- ``right`` -- the right factor 

 

OUTPUT: 

 

The product as a new element. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.asymptotics_multivariate_generating_functions import FractionWithFactoredDenominatorRing 

sage: R.<x,y> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R) 

sage: f = FFPD(2, [(x, 1), (x*y + 1, 1), (x*y^2 + 1, 1)]) 

sage: g = FFPD(2*x*y, [(y, 1), (x*y + 1, 1), (x^2*y + 1, 1)]) 

sage: f * g 

(4, [(x*y + 1, 1), (x*y + 1, 1), (x*y^2 + 1, 1), (x^2*y + 1, 1)]) 

""" 

numer = left.numerator() * right.numerator() 

df = left.denominator_factored() + right.denominator_factored() 

return left.parent()(numer, df) 

 

 

class FractionWithFactoredDenominatorRing(UniqueRepresentation, Ring): 

r""" 

This is the ring of fractions with factored denominator. 

 

INPUT: 

 

- ``denominator_ring`` -- the base ring (a polynomial ring) 

 

- ``numerator_ring`` -- (optional) the numerator ring; the default is 

the ``denominator_ring`` 

 

- ``category`` -- (default: :class:`Rings`) the category 

 

.. SEEALSO:: 

 

:class:`FractionWithFactoredDenominator`, 

:mod:`~sage.rings.asymptotic.asymptotics_multivariate_generating_functions` 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.asymptotics_multivariate_generating_functions import FractionWithFactoredDenominatorRing 

sage: R.<x,y> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R) 

sage: df = [x, 1], [y, 1], [x*y+1, 1] 

sage: f = FFPD(x, df) # indirect doctest 

sage: f 

(1, [(y, 1), (x*y + 1, 1)]) 

 

AUTHORS: 

 

- Daniel Krenn (2014-12-01) 

""" 

 

@staticmethod 

def __classcall_private__(cls, denominator_ring, numerator_ring=None, category=None): 

""" 

Normalize input to ensure a unique representation. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.asymptotics_multivariate_generating_functions import FractionWithFactoredDenominatorRing 

sage: R.<x,y> = PolynomialRing(QQ) 

sage: FFPD1 = FractionWithFactoredDenominatorRing(R) 

sage: FFPD2 = FractionWithFactoredDenominatorRing(R, R, Rings()) 

sage: FFPD1 is FFPD2 

True 

""" 

if numerator_ring is None: 

numerator_ring = denominator_ring 

if not numerator_ring.has_coerce_map_from(denominator_ring): 

raise ValueError('numerator ring {} has no coercion map from the ' 

'denominator ring {}'.format( 

numerator_ring, denominator_ring)) 

category = Rings().or_subcategory(category) 

return super(FractionWithFactoredDenominatorRing, cls).__classcall__(cls, 

denominator_ring, numerator_ring, category) 

 

def __init__(self, denominator_ring, numerator_ring=None, category=None): 

r""" 

Initialize ``self``. 

 

TESTS:: 

 

sage: from sage.rings.asymptotic.asymptotics_multivariate_generating_functions import FractionWithFactoredDenominatorRing 

sage: P.<X, Y> = ZZ[] 

sage: FractionWithFactoredDenominatorRing(P) 

Ring of fractions with factored denominator 

over Multivariate Polynomial Ring in X, Y over Integer Ring 

""" 

self._numerator_ring = numerator_ring 

self._denominator_ring = denominator_ring 

Ring.__init__(self, denominator_ring, category=category) 

 

def _repr_(self): 

r""" 

Returns a representation. 

 

OUTPUT: 

 

A string. 

 

TESTS:: 

 

sage: from sage.rings.asymptotic.asymptotics_multivariate_generating_functions import FractionWithFactoredDenominatorRing 

sage: P.<X, Y> = ZZ[] 

sage: FractionWithFactoredDenominatorRing(P) # indirect doctest 

Ring of fractions with factored denominator 

over Multivariate Polynomial Ring in X, Y over Integer Ring 

""" 

return ("Ring of fractions with factored denominator " 

"over {!r}".format(self.base())) 

 

def base_ring(self): 

r""" 

Returns the base ring. 

 

OUTPUT: 

 

A ring. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.asymptotics_multivariate_generating_functions import FractionWithFactoredDenominatorRing 

sage: P.<X, Y> = ZZ[] 

sage: F = FractionWithFactoredDenominatorRing(P); F 

Ring of fractions with factored denominator 

over Multivariate Polynomial Ring in X, Y over Integer Ring 

sage: F.base_ring() 

Integer Ring 

sage: F.base() 

Multivariate Polynomial Ring in X, Y over Integer Ring 

""" 

return self.base().base_ring() 

 

from sage.misc.decorators import rename_keyword 

@rename_keyword(deprecation=10519, reduce_='reduce') 

def _element_constructor_(self, *args, **kwargs): 

r""" 

Returns an element of this ring. 

 

See :class:`FractionWithFactoredDenominator` for details. 

 

TESTS:: 

 

sage: from sage.rings.asymptotic.asymptotics_multivariate_generating_functions import FractionWithFactoredDenominatorRing 

sage: R.<x,y> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R) 

sage: df = [x, 1], [y, 1], [x*y+1, 1] 

sage: f = FFPD(x, df) # indirect doctest 

sage: f 

(1, [(y, 1), (x*y + 1, 1)]) 

""" 

R = self.base() 

Q = R.fraction_field() 

 

# process deprecated keyword arguments 

hasn = 'numerator' in kwargs 

hasdf = 'denominator_factored' in kwargs 

if hasn: 

from sage.misc.superseded import deprecation 

deprecation(10519, "Keyword argument 'numerator' " 

"is deprecated. " 

"Ignoring non-keyword arguments (if any). " 

"Specify numerator and factored denominator " 

"as first and second argument, i.e., use " 

"something like FFPD(n, df).") 

if hasdf: 

from sage.misc.superseded import deprecation 

deprecation(10519, "Keyword argument 'denominator_factored' " 

"is deprecated. " 

"Ignoring non-keyword arguments (if any). " 

"Specify numerator and factored denominator " 

"as first and second argument, i.e., use " 

"something like FFPD(n, df).") 

if hasn or hasdf: 

args = [kwargs.pop('numerator') if hasn else R(0), 

kwargs.pop('denominator_factored') if hasdf else []] 

 

hasq = 'quotient' in kwargs 

if hasq: 

from sage.misc.superseded import deprecation 

deprecation(10519, "Keyword argument 'quotient' " 

"is deprecated. " 

"Ignoring non-keyword arguments (if any). " 

"Specify numerator and factored denominator " 

"as first and second argument, i.e., use " 

"something like FFPD(q).") 

args = [kwargs.pop('quotient')] 

 

if (hasn or hasdf) and hasq: 

raise ValueError('parameters ambiguous') 

 

# process keyword arguments 

reduce = kwargs.pop('reduce', None) 

 

if kwargs: 

raise ValueError('Unknown keyword arguments ' 

'%s given' % (kwargs,)) 

 

# process arguments 

if len(args) > 2: 

raise ValueError('too many arguments given') 

 

elif not args: 

raise ValueError('No argument given. ' 

'We are in serious troubles...') 

 

# At this point we have one or two input arguments. 

 

x = args[0] 

try: 

P = x.parent() 

except AttributeError: 

P = None 

 

denominator_factored = None # init 

reduce_default = True 

 

if len(args) == 2: 

numerator, denominator_factored = args 

if numerator is None: 

numerator = R(0) 

if denominator_factored is None: 

denominator_factored = [] 

 

from sage.rings.semirings.non_negative_integer_semiring import NN 

try: 

denominator_factored = sorted( 

(R(d[0]), NN(d[1])) for d in denominator_factored) 

except TypeError: 

raise TypeError('factored denominator is not well-formed ' 

'or of wrong type') 

 

# From now on we only have one input argument; 

# it's called x and has parent P. 

 

elif isinstance(P, FractionWithFactoredDenominatorRing): 

numerator = x._numerator 

denominator_factored = self._denominator_factored 

reduce_default = False 

 

elif P == SR: 

numerator = x.numerator() 

denominator = x.denominator() 

reduce_default = False 

 

elif x in R: 

numerator = R(x) 

denominator_factored = [] 

 

elif x in Q: 

quotient = Q(x) 

numerator = quotient.numerator() 

denominator = quotient.denominator() 

reduce_default = False 

 

elif hasattr(x, 'numerator') and hasattr(x, 'denominator'): 

numerator = x.numerator() 

denominator = x.denominator() 

reduce_default = False 

 

else: 

raise TypeError('element {} is not contained in {}'.format(x, self)) 

 

if reduce is None: 

reduce = reduce_default 

 

if denominator_factored is None: 

if denominator not in R: 

raise TypeError('extracted denominator {} is not in {}'.format(denominator, self)) 

p = numerator 

q = R(denominator) 

 

from sage.rings.polynomial.polynomial_ring import is_PolynomialRing 

from sage.rings.polynomial.multi_polynomial_ring_generic import is_MPolynomialRing 

if is_PolynomialRing(R) or is_MPolynomialRing(R): 

if not R(q).is_unit(): 

# Factor denominator 

try: 

df = q.factor() 

except NotImplementedError: 

# Singular's factor() needs 'proof=False'. 

df = q.factor(proof=False) 

numerator = p / df.unit() 

df = sorted(tuple(t) for t in df) # sort for consistency 

denominator_factored = df 

else: 

# At this point, denominator could not be factored. 

numerator = p / q 

denominator_factored = [] 

 

return self.element_class(self, 

numerator=numerator, 

denominator_factored=denominator_factored, 

reduce=reduce) 

 

def _coerce_map_from_(self, P): 

r""" 

Checks if there is a coercion from the given parent. 

 

INPUT: 

 

- ``P`` -- a parent 

 

OUTPUT: 

 

``True`` if there is a coercion, otherwise ``False`` or ``None``. 

 

TESTS:: 

 

sage: from sage.rings.asymptotic.asymptotics_multivariate_generating_functions import FractionWithFactoredDenominatorRing 

sage: Q = QQ['x,y'] 

sage: FFPD_QQ = FractionWithFactoredDenominatorRing(Q) 

sage: FFPD_QQ.has_coerce_map_from(Q) 

True 

sage: FFPD_QQ.has_coerce_map_from(QQ) 

True 

sage: FFPD_QQ.has_coerce_map_from(ZZ) 

True 

sage: FFPD_QQ.has_coerce_map_from(Q.fraction_field()) 

True 

sage: Z = ZZ['x,y'] 

sage: FFPD_ZZ = FractionWithFactoredDenominatorRing(Z) 

sage: FFPD_ZZ.has_coerce_map_from(FFPD_QQ) 

False 

sage: FFPD_QQ.has_coerce_map_from(FFPD_ZZ) 

True 

sage: FFPD_ZZ.has_coerce_map_from(QQ) 

False 

sage: FFPD_ZZ.has_coerce_map_from(Z.fraction_field()) 

True 

sage: FFPD_ZZ.has_coerce_map_from(Q.fraction_field()) 

False 

sage: FFPD_QQ.has_coerce_map_from(Z.fraction_field()) 

True 

""" 

if isinstance(P, FractionWithFactoredDenominatorRing): 

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

return True 

 

from sage.rings.fraction_field import is_FractionField 

if is_FractionField(P): 

B = P.base() 

from sage.rings.polynomial.polynomial_ring import is_PolynomialRing 

from sage.rings.polynomial.multi_polynomial_ring_generic import is_MPolynomialRing 

if is_PolynomialRing(B) or is_MPolynomialRing(B): 

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

return True 

 

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

return True 

 

def _an_element_(self): 

r""" 

Returns an element. 

 

OUTPUT: 

 

An element. 

 

TESTS:: 

 

sage: from sage.rings.asymptotic.asymptotics_multivariate_generating_functions import FractionWithFactoredDenominatorRing 

sage: R.<x,y> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R) 

sage: FFPD.an_element() # indirect doctest 

(42, [(x, 3)]) 

""" 

from sage.rings.semirings.non_negative_integer_semiring import NN 

return self(NN.an_element(), [(self.base().an_element(), NN(3))]) 

 

 

Element = FractionWithFactoredDenominator 

 

 

class FractionWithFactoredDenominatorSum(list): 

r""" 

A list representing the sum of :class:`FractionWithFactoredDenominator` 

objects with distinct denominator factorizations. 

 

AUTHORS: 

 

- Alexander Raichev (2012-06-25) 

 

- Daniel Krenn (2014-12-01) 

""" 

 

def __repr__(self): 

r""" 

Return a string representation of ``self``. 

 

OUTPUT: 

 

A string. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.asymptotics_multivariate_generating_functions import FractionWithFactoredDenominatorRing, FractionWithFactoredDenominatorSum 

sage: R.<x,y> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R) 

sage: f = FFPD(x + y, [(y, 1), (x, 1)]) 

sage: g = FFPD(x**2 + y, [(y, 1), (x, 2)]) 

sage: FractionWithFactoredDenominatorSum([f, g]) 

(x + y, [(y, 1), (x, 1)]) + (x^2 + y, [(y, 1), (x, 2)]) 

""" 

return ' + '.join(repr(r) for r in self) 

 

def __eq__(self, other): 

r""" 

Return ``True`` if ``self`` is equal to ``other``. 

 

OUTPUT: 

 

A boolean. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.asymptotics_multivariate_generating_functions import FractionWithFactoredDenominatorRing, FractionWithFactoredDenominatorSum 

sage: R.<x,y> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R) 

sage: f = FFPD(x + y, [(y, 1), (x, 1)]) 

sage: g = FFPD(x*(x + y), [(y, 1), (x, 2)]) 

sage: s = FractionWithFactoredDenominatorSum([f]); s 

(x + y, [(y, 1), (x, 1)]) 

sage: t = FractionWithFactoredDenominatorSum([g]); t 

(x + y, [(y, 1), (x, 1)]) 

sage: s == t 

True 

""" 

from operator import methodcaller 

return (sorted(self, key=methodcaller('_total_order_key_')) == 

sorted(other, key=methodcaller('_total_order_key_'))) 

 

def __ne__(self, other): 

r""" 

Return ``True`` if ``self`` is not equal to ``other``. 

 

OUTPUT: 

 

A boolean. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.asymptotics_multivariate_generating_functions import FractionWithFactoredDenominatorRing, FractionWithFactoredDenominatorSum 

sage: R.<x,y> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R) 

sage: f = FFPD(x + y, [(y, 1), (x, 1)]) 

sage: g = FFPD(x + y, [(y, 1), (x, 2)]) 

sage: s = FractionWithFactoredDenominatorSum([f]); s 

(x + y, [(y, 1), (x, 1)]) 

sage: t = FractionWithFactoredDenominatorSum([g]); t 

(x + y, [(y, 1), (x, 2)]) 

sage: s != t 

True 

""" 

return not self.__eq__(other) 

 

@property 

def denominator_ring(self): 

r""" 

Return the polynomial ring of the denominators of ``self``. 

 

OUTPUT: 

 

A ring or ``None`` if the list is empty. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.asymptotics_multivariate_generating_functions import FractionWithFactoredDenominatorRing, FractionWithFactoredDenominatorSum 

sage: R.<x,y> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R) 

sage: f = FFPD(x + y, [(y, 1), (x, 1)]) 

sage: s = FractionWithFactoredDenominatorSum([f]) 

sage: s.denominator_ring 

Multivariate Polynomial Ring in x, y over Rational Field 

sage: g = FFPD(x + y, []) 

sage: t = FractionWithFactoredDenominatorSum([g]) 

sage: t.denominator_ring 

Multivariate Polynomial Ring in x, y over Rational Field 

""" 

for r in self: 

return r.denominator_ring 

return None 

 

def whole_and_parts(self): 

r""" 

Rewrite ``self`` as a sum of a (possibly zero) polynomial 

followed by reduced rational expressions. 

 

OUTPUT: 

 

An instance of :class:`FractionWithFactoredDenominatorSum`. 

 

Only useful for multivariate decompositions. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.asymptotics_multivariate_generating_functions import FractionWithFactoredDenominatorRing, FractionWithFactoredDenominatorSum 

sage: R.<x,y> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R, SR) 

sage: f = x**2 + 3*y + 1/x + 1/y 

sage: f = FFPD(f); f 

(x^3*y + 3*x*y^2 + x + y, [(y, 1), (x, 1)]) 

sage: FractionWithFactoredDenominatorSum([f]).whole_and_parts() 

(x^2 + 3*y, []) + (x + y, [(y, 1), (x, 1)]) 

 

sage: f = cos(x)**2 + 3*y + 1/x + 1/y; f 

cos(x)^2 + 3*y + 1/x + 1/y 

sage: G = f.numerator() 

sage: H = R(f.denominator()) 

sage: f = FFPD(G, H.factor()); f 

(x*y*cos(x)^2 + 3*x*y^2 + x + y, [(y, 1), (x, 1)]) 

sage: FractionWithFactoredDenominatorSum([f]).whole_and_parts() 

(0, []) + (x*y*cos(x)^2 + 3*x*y^2 + x + y, [(y, 1), (x, 1)]) 

""" 

whole = 0 

parts = [] 

R = self.denominator_ring 

for r in self: 

# Since r has already passed through FFPD.__init__()'s reducing 

# procedure, r is already in lowest terms. 

# Check if can write r as a mixed fraction: whole + fraction. 

p = r.numerator() 

q = r.denominator() 

if q == 1: 

# r is already whole 

whole += p 

else: 

try: 

# Coerce p into R and divide p by q 

p = R(p) 

a, b = p.quo_rem(q) 

except TypeError: 

# p is not in R and so can't divide p by q 

a = 0 

b = p 

whole += a 

parts.append(r.parent()(b, r.denominator_factored(), reduce=False)) 

return FractionWithFactoredDenominatorSum( 

[r.parent()(whole, ())] + parts) # r.parent() is not the nicest here 

 

def _combine_like_terms_(self): 

r""" 

Combine terms in ``self`` with the same denominator. 

Only useful for multivariate decompositions. 

 

OUTPUT: 

 

An instance of :class:`FractionWithFactoredDenominatorSum`. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.asymptotics_multivariate_generating_functions import FractionWithFactoredDenominatorRing, FractionWithFactoredDenominatorSum 

sage: R.<x,y> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R, SR) 

sage: f = FFPD(1/(x * y * (x*y + 1))) 

sage: g = FFPD(x/(x * y * (x*y + 1))) 

sage: s = FractionWithFactoredDenominatorSum([f, g, f]) 

sage: t = s._combine_like_terms_() 

sage: s 

(1, [(y, 1), (x, 1), (x*y + 1, 1)]) + 

(1, [(y, 1), (x*y + 1, 1)]) + 

(1, [(y, 1), (x, 1), (x*y + 1, 1)]) 

sage: t 

(1, [(y, 1), (x*y + 1, 1)]) + (2, [(y, 1), (x, 1), (x*y + 1, 1)]) 

 

sage: H = x * y * (x*y + 1) 

sage: f = FFPD(1, H.factor()) 

sage: g = FFPD(exp(x + y), H.factor()) 

sage: s = FractionWithFactoredDenominatorSum([f, g]) 

sage: s 

(1, [(y, 1), (x, 1), (x*y + 1, 1)]) + 

(e^(x + y), [(y, 1), (x, 1), (x*y + 1, 1)]) 

sage: t = s._combine_like_terms_() 

sage: t 

(e^(x + y) + 1, [(y, 1), (x, 1), (x*y + 1, 1)]) 

""" 

if not self: 

return self 

 

from operator import methodcaller 

# Combine like terms. 

FFPDs = sorted(self, key=methodcaller('_total_order_key_')) 

new_FFPDs = [] 

temp = FFPDs[0] 

for f in FFPDs[1:]: 

if temp.denominator_factored() == f.denominator_factored(): 

# Add f to temp. 

num = temp.numerator() + f.numerator() 

temp = f.parent()(num, temp.denominator_factored()) 

else: 

# Append temp to new_FFPDs and update temp. 

new_FFPDs.append(temp) 

temp = f 

new_FFPDs.append(temp) 

return FractionWithFactoredDenominatorSum(new_FFPDs) 

 

def sum(self): 

r""" 

Return the sum of the elements in ``self``. 

 

OUTPUT: 

 

An instance of :class:`FractionWithFactoredDenominator`. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.asymptotics_multivariate_generating_functions import FractionWithFactoredDenominatorRing, FractionWithFactoredDenominatorSum 

sage: R.<x,y> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R, SR) 

sage: df = (x, 1), (y, 1), (x*y + 1, 1) 

sage: f = FFPD(2, df) 

sage: g = FFPD(2*x*y, df) 

sage: FractionWithFactoredDenominatorSum([f, g]) 

(2, [(y, 1), (x, 1), (x*y + 1, 1)]) + (2, [(x*y + 1, 1)]) 

sage: FractionWithFactoredDenominatorSum([f, g]).sum() 

(2, [(y, 1), (x, 1)]) 

 

sage: f = FFPD(cos(x), [(x, 2)]) 

sage: g = FFPD(cos(y), [(x, 1), (y, 2)]) 

sage: FractionWithFactoredDenominatorSum([f, g]) 

(cos(x), [(x, 2)]) + (cos(y), [(y, 2), (x, 1)]) 

sage: FractionWithFactoredDenominatorSum([f, g]).sum() 

(y^2*cos(x) + x*cos(y), [(y, 2), (x, 2)]) 

""" 

if not self: 

return self 

 

# Compute the sum's numerator and denominator. 

R = self.denominator_ring 

summy = sum((f.quotient() for f in self)) 

numer = summy.numerator() 

denom = R(summy.denominator()) 

 

# Compute the sum's denominator factorization. 

# Could use the factor() command, but it's probably faster to use 

# the irreducible factors of the denominators of self. 

df = [] # The denominator factorization for the sum. 

if denom == 1: 

# Done 

return FractionWithFactoredDenominatorRing(numer.parent())(numer, df, reduce=False) 

 

factors = [] 

for f in self: 

factors.extend([q for (q, e) in f.denominator_factored()]) 

 

# Eliminate repeats from factors and sort. 

factors = sorted(list(set(factors))) 

 

# The irreducible factors of denom lie in factors. 

# Use this fact to build df. 

for q in factors: 

e = 0 

quo, rem = denom.quo_rem(q) 

while rem == 0: 

e += 1 

denom = quo 

quo, rem = denom.quo_rem(q) 

if e > 0: 

df.append((q, e)) 

return FractionWithFactoredDenominatorRing(numer.parent())(numer, df, reduce=False) 

 

 

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

## Helper functions 

 

 

def diff_prod(f_derivs, u, g, X, interval, end, uderivs, atc): 

r""" 

Take various derivatives of the equation `f = ug`, 

evaluate them at a point `c`, and solve for the derivatives of `u`. 

 

INPUT: 

 

- ``f_derivs`` -- a dictionary whose keys are all tuples of the form 

``s + end``, where ``s`` is a sequence of variables from ``X`` whose 

length lies in ``interval``, and whose values are the derivatives 

of a function `f` evaluated at `c` 

- ``u`` -- a callable symbolic function 

- ``g`` -- an expression or callable symbolic function 

- ``X`` -- a list of symbolic variables 

- ``interval`` -- a list of positive integers 

Call the first and last values `n` and `nn`, respectively 

- ``end`` -- a possibly empty list of repetitions of the 

variable ``z``, where ``z`` is the last element of ``X`` 

- ``uderivs`` -- a dictionary whose keys are the symbolic 

derivatives of order 0 to order `n-1` of ``u`` evaluated at `c` 

and whose values are the corresponding derivatives evaluated at `c` 

- ``atc`` -- a dictionary whose keys are the keys of `c` and all 

the symbolic derivatives of order 0 to order `nn` of ``g`` 

evaluated `c` and whose values are the corresponding 

derivatives evaluated at `c` 

 

OUTPUT: 

 

A dictionary whose keys are the derivatives of ``u`` up to order 

`nn` and whose values are those derivatives evaluated at `c`. 

 

This function works by differentiating the equation `f = ug` 

with respect to the variable sequence ``s + end``, 

for all tuples ``s`` of ``X`` of lengths in ``interval``, 

evaluating at the point `c` , 

and solving for the remaining derivatives of ``u``. 

This function assumes that ``u`` never appears in the 

differentiations of `f = ug` after evaluating at `c`. 

 

.. NOTE:: 

 

For internal use by 

:meth:`FractionWithFactoredDenominator.asymptotics_multiple()`. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.asymptotics_multivariate_generating_functions import diff_prod 

sage: u = function('u')(x) 

sage: g = function('g')(x) 

sage: fd = {(x,):1,(x, x):1} 

sage: ud = {u(x=2): 1} 

sage: atc = {x: 2, g(x=2): 3, diff(g, x)(x=2): 5} 

sage: atc[diff(g, x, x)(x=2)] = 7 

sage: dd = diff_prod(fd, u, g, [x], [1, 2], [], ud, atc) 

sage: dd[diff(u, x, 2)(x=2)] 

22/9 

""" 

from sage.symbolic.relation import solve 

 

for l in interval: 

D = {} 

rhs = [] 

lhs = [] 

for t in combinations_with_replacement(X, l): 

t = list(t) 

s = t + end 

lhs.append(f_derivs[tuple(s)]) 

rhs.append(diff(u * g, s).subs(atc).subs(uderivs)) 

# Since Sage's solve command can't take derivatives as variable 

# names, make new variables based on t to stand in for 

# diff(u, t) and store them in D. 

D[diff(u, t).subs(atc)] = var('zing' + 

''.join(str(x) for x in t)) 

eqns = [lhs[i] == rhs[i].subs(uderivs).subs(D) 

for i in range(len(lhs))] 

variables = D.values() 

sol = solve(eqns, *variables, solution_dict=True) 

uderivs.update(subs_all(D, sol[ZZ.zero()])) 

return uderivs 

 

 

def permutation_sign(s, u): 

r""" 

This function returns the sign of the permutation on 

``1, ..., len(u)`` that is induced by the sublist ``s`` of ``u``. 

 

.. NOTE:: 

 

For internal use by 

:meth:`FractionWithFactoredDenominator.cohomology_decomposition()`. 

 

INPUT: 

 

- ``s`` -- a sublist of ``u`` 

- ``u`` -- a list 

 

OUTPUT: 

 

The sign of the permutation obtained by taking indices 

within ``u`` of the list ``s + sc``, where ``sc`` is ``u`` 

with the elements of ``s`` removed. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.asymptotics_multivariate_generating_functions import permutation_sign 

sage: u = ['a', 'b', 'c', 'd', 'e'] 

sage: s = ['b', 'd'] 

sage: permutation_sign(s, u) 

-1 

sage: s = ['d', 'b'] 

sage: permutation_sign(s, u) 

1 

""" 

from sage.combinat.permutation import Permutation 

 

# Convert lists to lists of numbers in {1,..., len(u)} 

A = [i + 1 for i in range(len(u))] 

B = [u.index(x) + 1 for x in s] 

 

C = sorted(set(A).difference(set(B))) 

P = Permutation(B + C) 

return P.signature() 

 

 

def subs_all(f, sub, simplify=False): 

r""" 

Return the items of `f` substituted by the dictionaries 

of ``sub`` in order of their appearance in ``sub``. 

 

INPUT: 

 

- ``f`` -- an individual or list of symbolic expressions 

or dictionaries 

- ``sub`` -- an individual or list of dictionaries 

- ``simplify`` -- (default: ``False``) boolean; set to ``True`` to 

simplify the result 

 

OUTPUT: 

 

The items of ``f`` substituted by the dictionaries of ``sub`` in order 

of their appearance in ``sub``. The ``subs()`` command is used. If 

simplify is ``True``, then ``simplify()`` is used after substitution. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.asymptotics_multivariate_generating_functions import subs_all 

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

(x, y, z) 

sage: a = {x:1} 

sage: b = {y:2} 

sage: c = {z:3} 

sage: subs_all(x + y + z, a) 

y + z + 1 

sage: subs_all(x + y + z, [c, a]) 

y + 4 

sage: subs_all([x + y + z, y^2], b) 

[x + z + 2, 4] 

sage: subs_all([x + y + z, y^2], [b, c]) 

[x + 5, 4] 

 

:: 

 

sage: var('x, y') 

(x, y) 

sage: a = {'foo': x**2 + y**2, 'bar': x - y} 

sage: b = {x: 1 , y: 2} 

sage: subs_all(a, b) 

{'bar': -1, 'foo': 5} 

""" 

singleton = False 

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

f = [f] 

singleton = True 

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

sub = [sub] 

g = [] 

for ff in f: 

for D in sub: 

if isinstance(ff, dict): 

ff = {k: ff[k].subs(D) for k in ff} 

else: 

ff = ff.subs(D) 

g.append(ff) 

 

if singleton and simplify: 

if isinstance(g[0], dict): 

return g[0] 

return g[0].simplify() 

 

if singleton and not simplify: 

return g[0] 

 

if not singleton and simplify: 

G = [] 

for gg in g: 

if isinstance(gg, dict): 

G.append(gg) 

else: 

G.append(gg.simplify()) 

return G 

 

return g 

 

 

def diff_all(f, V, n, ending=[], sub=None, sub_final=None, 

zero_order=0, rekey=None): 

r""" 

Return a dictionary of representative mixed partial 

derivatives of `f` from order 1 up to order `n` with respect to the 

variables in `V`. 

 

The default is to key the dictionary by all nondecreasing sequences 

in `V` of length 1 up to length `n`. 

 

INPUT: 

 

- ``f`` -- an individual or list of `\mathcal{C}^{n+1}` functions 

- ``V`` -- a list of variables occurring in `f` 

- ``n`` -- a natural number 

- ``ending`` -- a list of variables in `V` 

- ``sub`` -- an individual or list of dictionaries 

- ``sub_final`` -- an individual or list of dictionaries 

- ``rekey`` -- a callable symbolic function in `V` or list thereof 

- ``zero_order`` -- a natural number 

 

OUTPUT: 

 

The dictionary ``{s_1:deriv_1, ..., sr:deriv_r}``. 

 

Here ``s_1, ..., s_r`` is a listing of 

all nondecreasing sequences of length 1 up to length `n` over the 

alphabet `V`, where `w > v` in `X` if and only if ``str(w) > str(v)``, 

and ``deriv_j`` is the derivative of `f` with respect to the derivative 

sequence ``s_j`` and simplified with respect to the substitutions in 

``sub`` and evaluated at ``sub_final``. 

Moreover, all derivatives with respect to sequences of length less than 

``zero_order`` (derivatives of order less than ``zero_order`` ) 

will be made zero. 

 

If ``rekey`` is nonempty, then ``s_1, ..., s_r`` will be replaced 

by the symbolic derivatives of the functions in ``rekey``. 

 

If ``ending`` is nonempty, then every derivative sequence ``s_j`` 

will be suffixed by ``ending``. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.asymptotics_multivariate_generating_functions import diff_all 

sage: f = function('f')(x) 

sage: dd = diff_all(f, [x], 3) 

sage: dd[(x, x, x)] 

diff(f(x), x, x, x) 

 

sage: d1 = {diff(f, x): 4*x^3} 

sage: dd = diff_all(f, [x], 3, sub=d1) 

sage: dd[(x, x, x)] 

24*x 

 

sage: dd = diff_all(f, [x], 3, sub=d1, rekey=f) 

sage: dd[diff(f, x, 3)] 

24*x 

 

sage: a = {x:1} 

sage: dd = diff_all(f, [x], 3, sub=d1, rekey=f, sub_final=a) 

sage: dd[diff(f, x, 3)] 

24 

 

:: 

 

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

sage: f = function('f')(*X) 

sage: dd = diff_all(f, X, 2, ending=[y, y, y]) 

sage: dd[(z, y, y, y)] 

diff(f(x, y, z), y, y, y, z) 

 

:: 

 

sage: g = function('g')(*X) 

sage: dd = diff_all([f, g], X, 2) 

sage: dd[(0, y, z)] 

diff(f(x, y, z), y, z) 

 

sage: dd[(1, z, z)] 

diff(g(x, y, z), z, z) 

 

sage: f = exp(x*y*z) 

sage: ff = function('ff')(*X) 

sage: dd = diff_all(f, X, 2, rekey=ff) 

sage: dd[diff(ff, x, z)] 

x*y^2*z*e^(x*y*z) + y*e^(x*y*z) 

""" 

singleton = False 

if not isinstance(f, list): 

f = [f] 

singleton = True 

 

# Build the dictionary of derivatives iteratively from a list 

# of nondecreasing derivative-order sequences. 

derivs = {} 

r = len(f) 

if ending: 

seeds = [ending] 

start = ZZ.one() 

else: 

seeds = [[v] for v in V] 

start = Integer(2) 

if singleton: 

for s in seeds: 

derivs[tuple(s)] = subs_all(diff(f[0], s), sub) 

for l in range(start, n + 1): 

for t in combinations_with_replacement(V, l): 

s = t + tuple(ending) 

derivs[s] = subs_all(diff(derivs[s[1:]], s[0]), sub) 

else: 

# Make the dictionary keys of the form (j, sequence of variables), 

# where j in range(r). 

for s in seeds: 

value = subs_all([diff(f[j], s) for j in range(r)], sub) 

derivs.update({tuple([j] + s): value[j] for j in range(r)}) 

for l in range(start, n + 1): 

for t in combinations_with_replacement(V, l): 

s = t + tuple(ending) 

value = subs_all([diff(derivs[(j,) + s[1:]], s[0]) for j in range(r)], sub) 

derivs.update({(j,) + s: value[j] for j in range(r)}) 

if zero_order: 

# Zero out all the derivatives of order < zero_order 

if singleton: 

for k in derivs: 

if len(k) < zero_order: 

derivs[k] = ZZ.zero() 

else: 

# Ignore the first of element of k, which is an index. 

for k in derivs: 

if len(k) - 1 < zero_order: 

derivs[k] = ZZ.zero() 

if sub_final: 

# Substitute sub_final into the values of derivs. 

for k in derivs: 

derivs[k] = subs_all(derivs[k], sub_final) 

if rekey: 

# Rekey the derivs dictionary by the value of rekey. 

F = rekey 

if singleton: 

# F must be a singleton. 

derivs = {diff(F, list(k)): derivs[k] for k in derivs} 

else: 

# F must be a list. 

derivs = {diff(F[k[0]], list(k)[1:]): derivs[k] for k in derivs} 

return derivs 

 

 

def diff_op(A, B, AB_derivs, V, M, r, N): 

r""" 

Return the derivatives `DD^{(l+k)}(A[j] B^l)` evaluated at a point 

`p` for various natural numbers `j, k, l` which depend on `r` and `N`. 

 

Here `DD` is a specific second-order linear differential operator 

that depends on `M` , `A` is a list of symbolic functions, 

`B` is symbolic function, and ``AB_derivs`` contains all the derivatives 

of `A` and `B` evaluated at `p` that are necessary for the computation. 

 

INPUT: 

 

- ``A`` -- a single or length ``r`` list of symbolic functions in the 

variables ``V`` 

- ``B`` -- a symbolic function in the variables ``V``. 

- ``AB_derivs`` -- a dictionary whose keys are the (symbolic) 

derivatives of ``A[0], ..., A[r-1]`` up to order ``2 * N-2`` and 

the (symbolic) derivatives of ``B`` up to order ``2 * N``; 

the values of the dictionary are complex numbers that are 

the keys evaluated at a common point `p` 

- ``V`` -- the variables of the ``A[j]`` and ``B`` 

- ``M`` -- a symmetric `l \times l` matrix, where `l` is the 

length of ``V`` 

- ``r, N`` -- natural numbers 

 

OUTPUT: 

 

A dictionary. 

 

The output is 

a dictionary whose keys are natural number tuples of the form 

`(j, k, l)`, where `l \leq 2k`, `j \leq r-1`, and `j+k \leq N-1`, 

and whose values are `DD^(l+k)(A[j] B^l)` evaluated at a point 

`p`, where `DD` is the linear second-order differential operator 

`-\sum_{i=0}^{l-1} \sum_{j=0}^{l-1} M[i][j] 

\partial^2 /(\partial V[j] \partial V[i])`. 

 

.. NOTE:: 

 

For internal use by 

:meth:`FractionWithFactoredDenominator.asymptotics_smooth()` and 

:meth:`FractionWithFactoredDenominator.asymptotics_multiple()`. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.asymptotics_multivariate_generating_functions import diff_op 

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

sage: A = function('A')(*tuple(T)) 

sage: B = function('B')(*tuple(T)) 

sage: AB_derivs = {} 

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

sage: DD = diff_op(A, B, AB_derivs, T, M, 1, 2) 

sage: sorted(DD) 

[(0, 0, 0), (0, 1, 0), (0, 1, 1), (0, 1, 2)] 

sage: len(DD[(0, 1, 2)]) 

246 

""" 

from itertools import product 

from sage.misc.mrange import xmrange 

 

if not isinstance(A, list): 

A = [A] 

 

# First, compute the necessary product derivatives of A and B. 

product_derivs = {} 

for j, k in xmrange([r, N], tuple): 

if j + k < N: 

for l in range(2 * k + 1): 

for s in combinations_with_replacement(V, 2 * (k + l)): 

DF = diff(A[j] * B ** l, list(s)).subs(AB_derivs) 

product_derivs[(j, k, l) + s] = DF 

 

# Second, compute DD^(k+l)(A[j]*B^l)(p) and store values in dictionary. 

DD = {} 

rows = M.nrows() 

for j, k in xmrange([r, N], tuple): 

if j + k < N: 

for l in range(2 * k + 1): 

# Take advantage of the symmetry of M by ignoring 

# the upper-diagonal entries of M and multiplying by 

# appropriate powers of 2. 

if k + l == 0: 

DD[(j, k, l)] = product_derivs[(j, k, l)] 

continue 

S = [(a, b) for a, b in xmrange([rows, rows], tuple) if b <= a] 

P = product(S, repeat=k + l) 

diffo = ZZ.zero() 

for t in P: 

idx = (j, k, l) + diff_seq(V, t) 

if product_derivs[idx] != ZZ.zero(): 

MM = ZZ.one() 

for (a, b) in t: 

MM *= M[a][b] 

if a != b: 

MM *= Integer(2) 

diffo += MM * product_derivs[idx] 

DD[(j, k, l)] = (-ZZ.one()) ** (k + l) * diffo 

return DD 

 

 

def diff_seq(V, s): 

r""" 

Given a list ``s`` of tuples of natural numbers, return the 

list of elements of ``V`` with indices the elements of the elements 

of ``s``. 

 

INPUT: 

 

- ``V`` -- a list 

- ``s`` -- a list of tuples of natural numbers in the interval 

``range(len(V))`` 

 

OUTPUT: 

 

The tuple ``tuple([V[tt] for tt in sorted(t)])``, where ``t`` is the 

list of elements of the elements of ``s``. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.asymptotics_multivariate_generating_functions import diff_seq 

sage: V = list(var('x, t, z')) 

sage: diff_seq(V,([0, 1],[0, 2, 1],[0, 0])) 

(x, x, x, x, t, t, z) 

 

.. NOTE:: 

 

This function is for internal use by :func:`diff_op()`. 

""" 

t = [] 

for ss in s: 

t.extend(ss) 

return tuple([V[tt] for tt in sorted(t)]) 

 

 

def diff_op_simple(A, B, AB_derivs, x, v, a, N): 

r""" 

Return `DD^(e k + v l)(A B^l)` evaluated at a point `p` for 

various natural numbers `e, k, l` that depend on `v` and `N`. 

 

Here `DD` is a specific linear differential operator that depends 

on `a` and `v` , `A` and `B` are symbolic functions, and `AB_derivs` 

contains all the derivatives of `A` and `B` evaluated at `p` that are 

necessary for the computation. 

 

.. NOTE:: 

 

For internal use by the function 

:meth:`FractionWithFactoredDenominator.asymptotics_smooth()`. 

 

INPUT: 

 

- ``A, B`` -- Symbolic functions in the variable ``x`` 

- ``AB_derivs`` - a dictionary whose keys are the (symbolic) 

derivatives of ``A`` up to order ``2 * N`` if ``v`` is even or 

``N`` if ``v`` is odd and the (symbolic) derivatives of ``B`` 

up to order ``2 * N + v`` if ``v`` is even or ``N + v`` 

if ``v`` is odd; the values of the dictionary are complex numbers 

that are the keys evaluated at a common point `p` 

- ``x`` -- a symbolic variable 

- ``a`` -- a complex number 

- ``v, N`` -- natural numbers 

 

OUTPUT: 

 

A dictionary. 

 

The output is 

a dictionary whose keys are natural number pairs of the form `(k, l)`, 

where `k < N` and `l \leq 2k` and whose values are 

`DD^(e k + v l)(A B^l)` evaluated at a point `p`. 

Here `e=2` if `v` is even, `e=1` if `v` is odd, and `DD` is the 

linear differential operator 

`(a^{-1/v} d/dt)` if `v` is even and 

`(|a|^{-1/v} i \text{sgn}(a) d/dt)` if `v` is odd. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.asymptotics_multivariate_generating_functions import diff_op_simple 

sage: A = function('A')(x) 

sage: B = function('B')(x) 

sage: AB_derivs = {} 

sage: sorted(diff_op_simple(A, B, AB_derivs, x, 3, 2, 2).items()) 

[((0, 0), A(x)), 

((1, 0), 1/2*I*2^(2/3)*diff(A(x), x)), 

((1, 1), 

1/4*2^(2/3)*(B(x)*diff(A(x), x, x, x, x) + 4*diff(A(x), x, x, x)*diff(B(x), x) + 6*diff(A(x), x, x)*diff(B(x), x, x) + 4*diff(A(x), x)*diff(B(x), x, x, x) + A(x)*diff(B(x), x, x, x, x)))] 

""" 

from sage.functions.other import sqrt 

 

I = sqrt(-ZZ.one()) 

DD = {} 

if v.mod(Integer(2)) == ZZ.zero(): 

for k in range(N): 

for l in range(2 * k + 1): 

DD[(k, l)] = ((a ** (-ZZ.one() / v)) ** (2 * k + v * l) * 

diff(A * B ** l, x, 

2 * k + v * l).subs(AB_derivs)) 

else: 

for k in range(N): 

for l in range(k + 1): 

DD[(k, l)] = ((abs(a) ** (-ZZ.one() / v) * I * 

a / abs(a)) ** (k + v * l) * 

diff(A * B ** l, x, 

k + v * l).subs(AB_derivs)) 

return DD 

 

 

def direction(v, coordinate=None): 

r""" 

Return ``[vv/v[coordinate] for vv in v]`` where 

``coordinate`` is the last index of ``v`` if not specified otherwise. 

 

INPUT: 

 

- ``v`` -- a vector 

- ``coordinate`` -- (optional; default: ``None``) an index for ``v`` 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.asymptotics_multivariate_generating_functions import direction 

sage: direction([2, 3, 5]) 

(2/5, 3/5, 1) 

sage: direction([2, 3, 5], 0) 

(1, 3/2, 5/2) 

""" 

if coordinate is None: 

coordinate = len(v) - 1 

return tuple([vv / v[coordinate] for vv in v]) 

 

 

def coerce_point(R, p): 

r""" 

Coerce the keys of the dictionary ``p`` into the ring ``R``. 

 

.. WARNING:: 

 

This method assumes that it is possible. 

 

EXAMPLES:: 

 

sage: from sage.rings.asymptotic.asymptotics_multivariate_generating_functions import FractionWithFactoredDenominatorRing, coerce_point 

sage: R.<x,y> = PolynomialRing(QQ) 

sage: FFPD = FractionWithFactoredDenominatorRing(R) 

sage: f = FFPD() 

sage: p = {SR(x): 1, SR(y): 7/8} 

sage: for k in sorted(p, key=str): 

....: print("{} {} {}".format(k, k.parent(), p[k])) 

x Symbolic Ring 1 

y Symbolic Ring 7/8 

sage: q = coerce_point(R, p) 

sage: for k in sorted(q, key=str): 

....: print("{} {} {}".format(k, k.parent(), q[k])) 

x Multivariate Polynomial Ring in x, y over Rational Field 1 

y Multivariate Polynomial Ring in x, y over Rational Field 7/8 

""" 

if p and list(p)[0].parent() != R: 

try: 

return {x: p[SR(x)] for x in R.gens()} 

except TypeError: 

pass 

return p