Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

286

287

288

289

290

291

292

293

294

295

296

297

298

299

300

301

302

303

304

305

306

307

308

309

310

311

312

313

314

315

316

317

318

319

320

321

322

323

324

325

326

327

328

329

330

331

332

333

334

335

336

337

338

339

340

341

342

343

344

345

346

347

348

349

350

351

352

353

354

355

356

357

358

359

360

361

362

363

364

365

366

367

368

369

370

371

372

373

374

375

376

377

378

379

380

381

382

383

384

385

386

387

388

389

390

391

392

393

394

395

396

397

398

399

400

401

402

403

404

405

406

407

408

409

410

411

412

413

414

415

416

417

418

419

420

421

422

423

424

425

426

427

428

429

430

431

432

433

434

435

436

437

438

439

440

441

442

443

444

445

446

447

448

449

450

451

452

453

454

455

456

457

458

459

460

461

462

463

464

465

466

467

468

469

470

471

472

473

474

475

476

477

478

479

480

481

482

483

484

485

486

487

488

489

490

491

492

493

494

495

496

497

498

499

500

501

502

503

504

505

506

507

508

509

510

511

512

513

514

515

516

517

518

519

520

521

522

523

524

525

526

527

528

529

530

531

532

533

534

535

536

537

538

539

540

541

542

543

544

545

546

547

548

549

550

551

552

553

554

555

556

557

558

559

560

561

562

563

564

565

566

567

568

569

570

571

572

573

574

575

576

577

578

579

580

581

582

583

584

585

586

587

588

589

590

591

592

593

594

595

596

597

598

599

600

601

602

603

604

605

606

607

608

609

610

611

612

613

614

615

616

617

618

619

620

621

622

623

624

625

626

627

628

629

630

631

632

633

634

635

636

637

638

639

640

641

642

643

644

645

646

647

648

649

650

651

652

653

654

655

656

657

658

659

660

661

662

663

664

665

666

667

668

669

670

671

672

673

674

675

676

677

678

679

680

681

682

683

684

685

686

687

688

689

690

691

692

693

694

695

696

697

698

699

700

701

702

703

704

705

706

707

708

709

710

711

712

713

714

715

716

717

718

719

720

721

722

723

724

725

726

727

728

729

730

731

732

733

734

735

736

737

738

739

740

741

742

743

744

745

746

747

748

749

750

751

752

753

754

755

756

757

758

759

760

761

762

763

764

765

766

767

768

769

770

771

772

773

774

775

776

777

778

779

780

781

782

783

784

785

786

787

788

789

790

791

792

793

794

795

796

797

798

799

800

801

802

803

804

805

806

807

808

809

810

811

812

813

814

815

816

817

818

819

820

821

822

823

824

825

826

827

828

829

830

831

832

833

834

835

836

837

838

839

840

841

842

843

844

845

846

847

848

849

850

851

852

853

854

855

856

857

858

859

860

861

862

863

864

865

866

867

868

869

870

871

872

873

874

875

876

877

878

879

880

881

882

883

884

885

886

887

888

889

890

891

892

893

894

895

896

897

898

899

900

901

902

903

904

905

906

907

908

909

910

911

912

913

914

915

916

917

918

919

920

921

922

923

924

925

926

927

928

929

930

931

932

933

934

935

936

937

938

939

940

941

942

943

944

945

946

947

948

949

950

951

952

953

954

955

956

957

958

959

960

961

962

963

964

965

966

967

968

969

970

971

972

973

974

975

976

977

978

979

980

981

982

983

984

985

986

987

988

989

990

991

992

993

994

995

996

997

998

999

1000

1001

1002

1003

1004

1005

1006

1007

1008

1009

1010

1011

1012

1013

1014

1015

1016

1017

1018

1019

1020

1021

1022

1023

1024

1025

1026

1027

1028

1029

1030

1031

1032

1033

1034

1035

1036

1037

1038

1039

1040

1041

1042

1043

1044

1045

1046

1047

1048

1049

1050

1051

1052

1053

1054

1055

1056

1057

1058

1059

1060

1061

1062

1063

1064

1065

1066

1067

1068

1069

1070

1071

1072

1073

1074

1075

1076

1077

1078

1079

1080

1081

1082

1083

1084

1085

1086

1087

1088

1089

1090

1091

1092

1093

1094

1095

1096

1097

1098

1099

1100

1101

1102

1103

1104

1105

1106

1107

1108

1109

1110

1111

1112

1113

1114

1115

1116

1117

1118

1119

1120

1121

1122

1123

1124

1125

1126

1127

1128

1129

1130

1131

1132

1133

1134

1135

1136

1137

1138

1139

1140

1141

1142

1143

1144

1145

1146

1147

1148

1149

1150

1151

1152

1153

1154

1155

1156

1157

1158

1159

1160

1161

1162

1163

1164

1165

1166

1167

1168

1169

1170

1171

1172

1173

1174

1175

1176

1177

1178

1179

1180

1181

1182

1183

1184

1185

1186

1187

1188

1189

1190

1191

1192

1193

1194

1195

1196

1197

1198

1199

1200

1201

1202

1203

1204

1205

1206

1207

1208

1209

1210

1211

1212

1213

1214

1215

1216

1217

1218

1219

1220

1221

1222

1223

1224

1225

1226

1227

1228

1229

1230

1231

1232

1233

1234

1235

1236

1237

1238

1239

1240

1241

1242

1243

1244

1245

1246

1247

1248

1249

1250

1251

1252

1253

1254

1255

1256

1257

1258

1259

1260

1261

1262

1263

1264

1265

1266

1267

1268

1269

1270

1271

1272

1273

1274

1275

1276

1277

1278

1279

1280

1281

1282

1283

1284

1285

1286

1287

1288

1289

1290

1291

1292

1293

1294

1295

1296

1297

1298

1299

1300

1301

1302

1303

1304

1305

1306

1307

1308

1309

1310

1311

1312

1313

1314

1315

1316

1317

1318

1319

1320

1321

1322

1323

1324

1325

1326

1327

1328

1329

1330

1331

1332

1333

1334

1335

1336

1337

1338

1339

1340

1341

1342

1343

1344

1345

1346

1347

1348

1349

1350

1351

1352

1353

1354

1355

1356

1357

1358

1359

1360

1361

1362

1363

1364

1365

1366

1367

1368

1369

1370

1371

1372

1373

1374

1375

1376

1377

1378

1379

1380

1381

1382

1383

1384

1385

1386

1387

1388

1389

1390

1391

1392

1393

1394

1395

1396

1397

1398

1399

1400

1401

1402

1403

1404

1405

1406

1407

1408

1409

1410

1411

1412

1413

1414

1415

1416

1417

1418

1419

1420

1421

1422

1423

1424

1425

1426

1427

1428

1429

1430

1431

1432

1433

1434

1435

1436

1437

1438

1439

1440

1441

1442

1443

1444

1445

1446

1447

1448

1449

1450

1451

1452

1453

1454

1455

1456

1457

1458

1459

1460

1461

1462

1463

1464

1465

1466

1467

1468

1469

1470

1471

1472

1473

1474

1475

1476

1477

1478

1479

1480

1481

1482

1483

1484

1485

1486

1487

1488

1489

1490

1491

1492

1493

1494

1495

1496

1497

1498

1499

1500

1501

1502

1503

1504

1505

1506

1507

1508

1509

1510

1511

1512

1513

1514

1515

1516

1517

1518

1519

1520

1521

1522

1523

1524

1525

1526

1527

1528

1529

1530

1531

1532

1533

1534

1535

1536

1537

1538

1539

1540

1541

1542

1543

1544

1545

1546

1547

1548

1549

1550

1551

1552

1553

1554

1555

1556

1557

1558

1559

1560

1561

1562

1563

1564

1565

1566

1567

1568

1569

1570

1571

1572

1573

1574

1575

1576

1577

1578

1579

1580

1581

1582

1583

1584

1585

1586

1587

1588

1589

1590

1591

1592

1593

1594

1595

1596

1597

1598

1599

1600

1601

1602

1603

1604

1605

1606

1607

1608

1609

1610

1611

1612

1613

1614

1615

1616

1617

1618

1619

1620

1621

1622

1623

1624

1625

1626

1627

1628

1629

1630

1631

1632

1633

1634

1635

1636

1637

1638

1639

1640

1641

1642

1643

1644

1645

1646

1647

1648

1649

1650

1651

1652

1653

1654

1655

1656

1657

1658

1659

1660

1661

1662

1663

1664

1665

1666

1667

1668

1669

1670

1671

1672

1673

1674

1675

1676

1677

1678

1679

1680

1681

1682

1683

1684

1685

1686

1687

1688

1689

1690

1691

1692

1693

1694

1695

1696

1697

1698

1699

1700

1701

1702

1703

1704

1705

1706

1707

1708

1709

1710

1711

1712

1713

1714

1715

1716

1717

1718

1719

1720

1721

1722

1723

1724

1725

1726

1727

1728

1729

1730

1731

1732

1733

1734

1735

1736

1737

1738

1739

1740

1741

1742

1743

1744

1745

1746

1747

1748

1749

1750

1751

1752

1753

1754

1755

1756

1757

1758

1759

1760

1761

1762

1763

1764

1765

1766

1767

1768

1769

1770

1771

1772

1773

1774

1775

1776

1777

1778

1779

1780

1781

1782

1783

1784

1785

1786

1787

1788

1789

1790

1791

1792

1793

1794

1795

1796

1797

1798

1799

1800

1801

1802

1803

1804

1805

1806

1807

1808

1809

1810

1811

1812

1813

1814

1815

1816

1817

1818

1819

1820

1821

1822

1823

1824

1825

1826

1827

1828

1829

1830

1831

1832

1833

1834

1835

1836

1837

1838

1839

1840

1841

1842

1843

1844

1845

1846

1847

1848

1849

1850

1851

1852

1853

1854

1855

1856

1857

1858

1859

1860

1861

1862

1863

1864

1865

1866

1867

1868

1869

1870

1871

1872

1873

1874

1875

1876

1877

1878

1879

1880

1881

1882

1883

1884

1885

1886

1887

1888

1889

1890

1891

1892

1893

1894

1895

1896

1897

1898

1899

1900

1901

1902

1903

1904

1905

1906

1907

1908

1909

1910

1911

1912

1913

1914

1915

1916

1917

1918

1919

1920

1921

1922

1923

1924

1925

1926

1927

1928

1929

1930

1931

1932

1933

1934

1935

1936

1937

1938

1939

1940

1941

1942

1943

1944

1945

1946

1947

1948

1949

1950

1951

1952

1953

1954

1955

1956

1957

1958

1959

1960

1961

1962

1963

1964

1965

1966

1967

1968

1969

1970

1971

1972

1973

1974

1975

1976

1977

1978

1979

1980

1981

1982

1983

1984

1985

1986

1987

1988

1989

1990

1991

1992

1993

1994

1995

1996

1997

1998

1999

2000

2001

2002

2003

2004

2005

2006

2007

2008

2009

2010

2011

2012

2013

2014

2015

2016

2017

2018

2019

2020

2021

2022

2023

2024

2025

2026

2027

2028

2029

2030

2031

2032

2033

2034

2035

2036

2037

2038

2039

2040

2041

2042

2043

2044

2045

2046

2047

2048

2049

2050

2051

2052

2053

2054

2055

2056

2057

2058

2059

2060

2061

2062

2063

2064

2065

2066

2067

2068

2069

2070

2071

2072

2073

2074

2075

2076

2077

2078

2079

2080

2081

2082

2083

2084

2085

2086

2087

2088

2089

2090

2091

2092

2093

2094

2095

2096

2097

2098

2099

2100

2101

2102

2103

2104

2105

2106

2107

2108

2109

2110

2111

2112

2113

2114

2115

2116

2117

2118

2119

2120

2121

2122

2123

2124

2125

2126

2127

2128

2129

2130

2131

2132

2133

2134

2135

2136

2137

2138

2139

2140

2141

2142

2143

2144

2145

2146

2147

2148

2149

2150

2151

2152

2153

2154

2155

2156

2157

2158

2159

2160

2161

2162

2163

2164

2165

2166

2167

2168

2169

2170

2171

2172

2173

2174

2175

2176

2177

2178

2179

2180

2181

2182

2183

2184

2185

2186

2187

2188

2189

2190

2191

2192

2193

2194

2195

2196

2197

2198

2199

2200

2201

2202

2203

2204

2205

2206

2207

2208

2209

2210

2211

2212

2213

2214

2215

2216

2217

2218

2219

2220

2221

2222

2223

2224

2225

2226

2227

2228

2229

2230

2231

2232

2233

2234

2235

2236

2237

2238

2239

2240

2241

2242

2243

2244

2245

2246

2247

2248

2249

2250

2251

2252

2253

2254

2255

2256

2257

2258

2259

2260

2261

2262

2263

2264

2265

2266

2267

2268

2269

2270

2271

2272

2273

2274

2275

2276

2277

2278

2279

2280

2281

2282

2283

2284

2285

2286

2287

2288

2289

2290

2291

2292

2293

2294

2295

2296

2297

2298

2299

2300

2301

2302

2303

2304

2305

2306

2307

2308

2309

2310

2311

2312

2313

2314

2315

2316

2317

2318

2319

2320

2321

2322

2323

2324

2325

2326

2327

2328

2329

2330

2331

2332

2333

2334

2335

2336

2337

2338

2339

2340

2341

2342

2343

2344

2345

2346

2347

2348

2349

2350

2351

2352

2353

2354

2355

2356

2357

2358

2359

2360

2361

2362

2363

2364

2365

2366

2367

2368

2369

2370

2371

2372

2373

2374

2375

2376

2377

2378

2379

2380

2381

2382

2383

2384

2385

2386

2387

2388

2389

2390

2391

2392

2393

2394

2395

2396

2397

2398

2399

2400

2401

2402

2403

2404

2405

2406

2407

2408

2409

2410

2411

2412

2413

2414

2415

2416

2417

2418

2419

2420

2421

2422

2423

2424

2425

2426

2427

2428

2429

2430

2431

2432

2433

2434

2435

2436

2437

2438

2439

2440

2441

2442

2443

2444

2445

2446

2447

2448

2449

2450

2451

2452

2453

2454

2455

2456

2457

2458

2459

2460

2461

2462

2463

2464

2465

2466

2467

2468

2469

2470

2471

2472

2473

2474

2475

2476

2477

2478

2479

2480

2481

2482

2483

2484

2485

2486

2487

2488

2489

2490

2491

2492

2493

2494

2495

2496

2497

2498

2499

2500

2501

2502

2503

2504

2505

2506

2507

2508

2509

2510

2511

2512

2513

2514

2515

2516

2517

2518

2519

2520

2521

2522

2523

2524

2525

2526

2527

2528

2529

2530

2531

2532

2533

2534

2535

2536

2537

2538

2539

2540

2541

2542

2543

2544

2545

2546

2547

2548

2549

2550

2551

2552

2553

2554

2555

2556

2557

2558

2559

2560

2561

2562

2563

2564

2565

2566

2567

2568

2569

2570

2571

2572

2573

2574

2575

2576

2577

2578

2579

2580

2581

2582

2583

2584

2585

2586

2587

2588

2589

2590

2591

2592

2593

2594

2595

2596

2597

2598

2599

2600

2601

2602

2603

2604

2605

2606

2607

2608

2609

2610

2611

2612

2613

2614

2615

2616

2617

2618

2619

2620

2621

2622

2623

2624

2625

2626

2627

2628

2629

2630

2631

2632

2633

2634

2635

2636

2637

2638

2639

2640

2641

2642

2643

2644

2645

2646

2647

2648

2649

2650

2651

2652

2653

2654

2655

2656

2657

2658

2659

2660

2661

2662

2663

2664

2665

2666

2667

2668

2669

2670

2671

2672

2673

2674

2675

2676

2677

2678

2679

2680

2681

2682

2683

2684

2685

2686

2687

2688

2689

2690

2691

2692

2693

2694

2695

2696

2697

2698

2699

2700

2701

2702

2703

2704

2705

2706

2707

2708

2709

2710

2711

2712

2713

2714

2715

2716

2717

2718

2719

2720

2721

2722

2723

2724

2725

2726

2727

2728

2729

2730

2731

2732

2733

2734

2735

2736

2737

2738

2739

2740

2741

2742

2743

2744

2745

2746

2747

2748

2749

2750

2751

2752

2753

2754

2755

2756

2757

2758

2759

2760

2761

2762

2763

2764

2765

2766

2767

2768

2769

2770

2771

2772

2773

2774

2775

2776

2777

2778

2779

2780

2781

2782

2783

2784

2785

2786

2787

2788

2789

2790

2791

2792

2793

2794

2795

2796

2797

2798

2799

2800

2801

2802

2803

2804

2805

2806

2807

2808

2809

2810

2811

2812

2813

2814

2815

2816

2817

2818

2819

2820

2821

2822

2823

2824

2825

2826

2827

2828

2829

2830

2831

2832

2833

2834

2835

2836

2837

2838

2839

2840

2841

2842

2843

2844

2845

2846

2847

2848

2849

2850

2851

2852

2853

2854

2855

2856

2857

2858

2859

2860

2861

2862

2863

2864

2865

2866

2867

2868

2869

2870

2871

2872

2873

2874

2875

2876

2877

2878

2879

2880

2881

2882

2883

2884

2885

2886

2887

2888

2889

2890

2891

2892

2893

2894

2895

2896

2897

2898

2899

2900

2901

2902

2903

2904

2905

2906

2907

2908

2909

2910

2911

2912

2913

2914

2915

2916

2917

2918

2919

2920

2921

2922

2923

2924

2925

2926

2927

2928

2929

2930

2931

2932

2933

2934

2935

2936

2937

2938

2939

2940

2941

2942

2943

2944

2945

2946

2947

2948

2949

2950

2951

2952

2953

2954

2955

2956

2957

2958

2959

2960

2961

2962

2963

2964

2965

2966

2967

2968

2969

2970

2971

2972

2973

2974

2975

2976

2977

2978

2979

2980

2981

2982

2983

2984

2985

2986

2987

2988

2989

2990

2991

2992

2993

2994

2995

2996

2997

2998

2999

3000

3001

3002

3003

3004

3005

3006

3007

3008

3009

3010

3011

3012

3013

3014

3015

3016

3017

3018

3019

3020

3021

3022

3023

3024

3025

3026

3027

3028

3029

3030

3031

3032

3033

3034

3035

3036

3037

3038

3039

3040

3041

3042

3043

3044

3045

3046

3047

3048

3049

3050

3051

3052

3053

3054

3055

3056

3057

3058

3059

3060

3061

3062

3063

3064

3065

3066

3067

3068

3069

3070

3071

3072

3073

3074

3075

3076

3077

3078

3079

3080

3081

3082

3083

3084

3085

3086

3087

3088

3089

3090

3091

3092

3093

3094

3095

3096

3097

3098

3099

3100

3101

3102

3103

3104

3105

3106

3107

3108

3109

3110

3111

3112

3113

3114

3115

3116

3117

3118

3119

3120

3121

3122

3123

3124

3125

3126

3127

3128

3129

3130

3131

3132

3133

3134

3135

3136

3137

3138

3139

3140

3141

3142

3143

3144

3145

3146

3147

3148

3149

3150

3151

3152

3153

3154

3155

3156

3157

3158

3159

3160

3161

3162

3163

3164

3165

3166

3167

3168

3169

3170

3171

3172

3173

3174

3175

3176

3177

3178

3179

3180

3181

3182

3183

3184

3185

3186

3187

3188

3189

3190

3191

3192

3193

3194

3195

3196

3197

3198

3199

3200

3201

3202

3203

3204

3205

3206

3207

3208

3209

3210

3211

3212

3213

3214

3215

3216

3217

3218

3219

3220

3221

3222

3223

3224

3225

3226

3227

3228

3229

3230

3231

3232

3233

3234

3235

3236

3237

3238

3239

3240

3241

3242

3243

3244

3245

3246

3247

3248

3249

3250

3251

3252

3253

3254

3255

3256

3257

3258

3259

3260

3261

3262

3263

3264

3265

3266

3267

3268

3269

3270

3271

3272

3273

3274

3275

3276

3277

3278

3279

3280

3281

3282

3283

3284

3285

3286

3287

3288

3289

3290

3291

3292

3293

3294

3295

3296

3297

3298

3299

3300

3301

3302

3303

3304

3305

3306

3307

3308

3309

3310

3311

3312

3313

3314

3315

3316

3317

3318

3319

3320

3321

3322

3323

3324

3325

3326

3327

3328

3329

3330

3331

3332

3333

3334

3335

3336

3337

3338

3339

3340

3341

3342

3343

3344

3345

3346

3347

3348

3349

3350

3351

3352

3353

3354

3355

3356

3357

3358

3359

3360

3361

3362

3363

3364

3365

3366

3367

3368

3369

3370

3371

3372

3373

3374

3375

3376

3377

3378

3379

3380

3381

3382

3383

3384

3385

3386

3387

3388

3389

3390

3391

3392

3393

3394

3395

3396

3397

3398

3399

3400

3401

3402

3403

3404

3405

3406

3407

3408

3409

3410

3411

3412

3413

3414

3415

3416

3417

3418

3419

3420

3421

3422

3423

3424

3425

3426

3427

3428

3429

3430

3431

3432

3433

3434

3435

3436

3437

3438

3439

3440

3441

3442

3443

3444

3445

3446

3447

3448

3449

3450

3451

3452

3453

3454

3455

3456

3457

3458

3459

3460

3461

3462

3463

3464

3465

3466

3467

3468

3469

3470

3471

3472

3473

3474

3475

3476

3477

3478

3479

3480

3481

3482

3483

3484

3485

3486

3487

3488

3489

3490

3491

3492

3493

3494

3495

3496

3497

3498

3499

3500

3501

3502

3503

3504

3505

3506

3507

3508

3509

3510

3511

3512

3513

3514

3515

3516

3517

3518

3519

3520

3521

3522

3523

3524

3525

3526

3527

3528

3529

3530

3531

3532

3533

3534

3535

3536

3537

3538

3539

3540

3541

3542

3543

3544

3545

3546

3547

3548

3549

3550

3551

3552

3553

3554

3555

3556

3557

3558

3559

3560

3561

3562

3563

3564

3565

3566

3567

3568

3569

3570

3571

3572

3573

3574

3575

3576

3577

3578

3579

3580

3581

3582

3583

3584

3585

3586

3587

3588

3589

3590

3591

3592

3593

3594

3595

3596

3597

3598

3599

3600

3601

3602

3603

3604

3605

3606

3607

3608

3609

3610

3611

3612

3613

3614

3615

3616

3617

3618

3619

3620

3621

3622

3623

3624

3625

3626

3627

3628

3629

3630

3631

3632

3633

3634

3635

3636

3637

3638

3639

3640

3641

3642

3643

3644

3645

3646

3647

3648

3649

3650

3651

3652

3653

3654

3655

3656

3657

3658

3659

3660

3661

3662

3663

3664

3665

3666

3667

3668

3669

3670

3671

3672

3673

3674

3675

3676

3677

3678

3679

3680

3681

3682

3683

3684

3685

3686

3687

3688

3689

3690

3691

3692

3693

3694

3695

3696

3697

3698

3699

3700

3701

3702

3703

3704

3705

3706

3707

3708

3709

3710

3711

3712

3713

3714

3715

3716

3717

3718

3719

3720

3721

3722

3723

3724

3725

3726

3727

3728

3729

3730

3731

3732

3733

3734

3735

3736

3737

3738

3739

3740

3741

3742

3743

3744

3745

3746

3747

3748

3749

3750

3751

3752

3753

3754

3755

3756

3757

3758

3759

3760

3761

3762

3763

3764

3765

3766

3767

3768

3769

3770

3771

3772

3773

3774

3775

3776

3777

3778

3779

3780

3781

3782

3783

3784

3785

3786

3787

3788

3789

3790

3791

3792

3793

3794

3795

3796

3797

3798

3799

3800

3801

3802

3803

3804

3805

3806

3807

3808

3809

3810

3811

3812

3813

3814

3815

3816

3817

3818

3819

3820

3821

3822

3823

3824

3825

3826

3827

3828

3829

3830

3831

3832

3833

3834

3835

3836

3837

3838

3839

3840

3841

3842

3843

3844

3845

3846

3847

3848

3849

3850

3851

3852

3853

3854

3855

3856

3857

3858

3859

3860

3861

3862

3863

3864

3865

3866

3867

3868

3869

3870

3871

3872

3873

3874

3875

3876

3877

3878

3879

3880

3881

3882

3883

3884

3885

3886

3887

3888

3889

3890

3891

3892

3893

3894

3895

3896

3897

3898

3899

3900

3901

3902

3903

3904

3905

3906

3907

3908

3909

3910

3911

3912

3913

3914

3915

3916

3917

3918

3919

3920

3921

3922

3923

3924

3925

3926

3927

3928

3929

3930

3931

3932

3933

3934

3935

3936

3937

3938

3939

3940

3941

3942

3943

3944

3945

3946

3947

3948

3949

3950

3951

3952

3953

3954

3955

3956

3957

3958

3959

3960

3961

3962

3963

3964

3965

3966

3967

3968

3969

3970

3971

3972

3973

3974

3975

3976

3977

3978

3979

3980

3981

3982

3983

3984

3985

3986

3987

3988

3989

3990

3991

3992

3993

3994

3995

3996

3997

3998

3999

4000

4001

4002

4003

4004

4005

4006

4007

4008

4009

4010

4011

4012

4013

4014

4015

4016

4017

4018

4019

4020

4021

4022

4023

4024

4025

4026

4027

4028

4029

4030

4031

4032

4033

4034

4035

4036

4037

4038

4039

4040

4041

4042

4043

4044

4045

4046

4047

4048

4049

4050

4051

4052

4053

4054

4055

4056

4057

4058

4059

4060

4061

4062

4063

4064

4065

4066

4067

4068

4069

4070

4071

4072

4073

4074

4075

4076

4077

4078

4079

4080

4081

4082

4083

4084

4085

4086

4087

4088

4089

4090

4091

4092

4093

4094

4095

4096

4097

4098

4099

4100

4101

4102

4103

4104

4105

4106

4107

4108

4109

4110

4111

4112

4113

4114

4115

4116

4117

4118

4119

4120

4121

4122

4123

4124

4125

4126

4127

4128

4129

4130

4131

4132

4133

4134

4135

4136

4137

4138

4139

4140

4141

4142

4143

4144

4145

4146

4147

4148

4149

4150

4151

4152

4153

4154

4155

4156

4157

4158

4159

4160

4161

4162

4163

4164

4165

4166

4167

4168

4169

4170

4171

4172

4173

4174

4175

4176

4177

4178

4179

4180

4181

4182

4183

4184

4185

4186

4187

4188

4189

4190

4191

4192

4193

4194

4195

4196

4197

4198

4199

4200

4201

4202

4203

4204

4205

4206

4207

4208

4209

4210

4211

4212

4213

4214

4215

4216

4217

4218

4219

4220

4221

4222

4223

4224

4225

4226

4227

4228

4229

4230

4231

4232

4233

4234

4235

4236

4237

4238

4239

4240

4241

4242

4243

4244

4245

4246

4247

4248

4249

4250

4251

4252

4253

4254

4255

4256

4257

4258

4259

4260

4261

4262

4263

4264

4265

4266

4267

4268

4269

4270

4271

4272

4273

4274

4275

4276

4277

4278

4279

4280

4281

4282

4283

4284

4285

4286

4287

4288

4289

4290

4291

4292

4293

4294

4295

4296

4297

4298

4299

4300

4301

4302

4303

4304

4305

4306

4307

4308

4309

4310

4311

4312

4313

4314

4315

4316

4317

4318

4319

4320

4321

4322

4323

4324

4325

4326

4327

4328

4329

4330

4331

4332

4333

4334

4335

4336

4337

4338

4339

4340

4341

4342

4343

4344

4345

4346

4347

4348

4349

4350

4351

4352

4353

4354

4355

4356

4357

4358

4359

4360

4361

4362

4363

4364

4365

4366

4367

4368

4369

4370

4371

4372

4373

4374

4375

4376

4377

4378

4379

4380

4381

4382

4383

4384

4385

4386

4387

4388

4389

4390

4391

4392

4393

4394

4395

4396

4397

4398

4399

4400

4401

4402

4403

4404

4405

4406

4407

4408

4409

4410

4411

4412

4413

4414

4415

4416

4417

4418

4419

4420

4421

4422

4423

4424

4425

4426

4427

4428

4429

4430

4431

4432

4433

4434

4435

4436

4437

# -*- coding: utf-8 

r""" 

Arbitrary precision complex balls using Arb 

  

This is a binding to the `Arb library <http://fredrikj.net/arb/>`_; it 

may be useful to refer to its documentation for more details. 

  

Parts of the documentation for this module are copied or adapted from 

Arb's own documentation, licenced under the GNU General Public License 

version 2, or later. 

  

.. SEEALSO:: 

  

- :mod:`Real balls using Arb <sage.rings.real_arb>` 

- :mod:`Complex interval field (using MPFI) <sage.rings.complex_interval_field>` 

- :mod:`Complex intervals (using MPFI) <sage.rings.complex_interval>` 

  

Data Structure 

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

  

A :class:`ComplexBall` represents a complex number with error bounds. It wraps 

an Arb object of type ``acb_t``, which consists of a pair of real number balls 

representing the real and imaginary part with separate error bounds. (See the 

documentation of :mod:`sage.rings.real_arb` for more information.) 

  

A :class:`ComplexBall` thus represents a rectangle `[m_1-r_1, m_1+r_1] + 

[m_2-r_2, m_2+r_2] i` in the complex plane. This is used in Arb instead of a 

disk or square representation (consisting of a complex floating-point midpoint 

with a single radius), since it allows implementing many operations more 

conveniently by splitting into ball operations on the real and imaginary parts. 

It also allows tracking when complex numbers have an exact (for example exactly 

zero) real part and an inexact imaginary part, or vice versa. 

  

The parents of complex balls are instances of :class:`ComplexBallField`. 

The name ``CBF`` is bound to the complex ball field with the default precision 

of 53 bits:: 

  

sage: CBF is ComplexBallField() is ComplexBallField(53) 

True 

  

Comparison 

========== 

  

.. WARNING:: 

  

In accordance with the semantics of Arb, identical :class:`ComplexBall` 

objects are understood to give permission for algebraic simplification. 

This assumption is made to improve performance. For example, setting ``z = 

x*x`` sets `z` to a ball enclosing the set `\{t^2 : t \in x\}` and not the 

(generally larger) set `\{tu : t \in x, u \in x\}`. 

  

Two elements are equal if and only if they are exact and equal (in spite of the 

above warning, inexact balls are not considered equal to themselves):: 

  

sage: a = CBF(1, 2) 

sage: b = CBF(1, 2) 

sage: a is b 

False 

sage: a == a 

True 

sage: a == b 

True 

  

:: 

  

sage: a = CBF(1/3, 1/5) 

sage: b = CBF(1/3, 1/5) 

sage: a.is_exact() 

False 

sage: b.is_exact() 

False 

sage: a is b 

False 

sage: a == a 

False 

sage: a == b 

False 

  

A ball is non-zero in the sense of usual comparison if and only if it does not 

contain zero:: 

  

sage: a = CBF(RIF(-0.5, 0.5)) 

sage: a != 0 

False 

sage: b = CBF(1/3, 1/5) 

sage: b != 0 

True 

  

However, ``bool(b)`` returns ``False`` for a ball ``b`` only if ``b`` is exactly 

zero:: 

  

sage: bool(a) 

True 

sage: bool(b) 

True 

sage: bool(CBF.zero()) 

False 

  

Coercion 

======== 

  

Automatic coercions work as expected:: 

  

sage: bpol = 1/3*CBF(i) + AA(sqrt(2)) + (polygen(RealBallField(20), 'x') + QQbar(i)) 

sage: bpol 

x + [1.41421 +/- 5.09e-6] + [1.33333 +/- 3.97e-6]*I 

sage: bpol.parent() 

Univariate Polynomial Ring in x over Complex ball field with 20 bits of precision 

sage: bpol/3 

([0.333333 +/- 4.93e-7])*x + [0.47140 +/- 5.39e-6] + [0.44444 +/- 4.98e-6]*I 

  

TESTS:: 

  

sage: polygen(CBF, 'x')^3 

x^3 

  

:: 

  

sage: SR.coerce(CBF(0.42 + 3.33*I)) 

[0.4200000000000000 +/- 1.56e-17] + [3.330000000000000 +/- 7.11e-17]*I 

  

Check that :trac:`19839` is fixed:: 

  

sage: log(SR(CBF(0.42))).pyobject().parent() 

Complex ball field with 53 bits of precision 

  

:trac:`24621`:: 

  

sage: CBF(NumberField(polygen(QQ, 'y')^3 + 20, 'a', embedding=CC(1.35,2.35)).gen()) 

[1.357208808297453 +/- 4.96e-16] + [2.350754612451197 +/- 7.67e-16]*I 

  

Classes and Methods 

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

""" 

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

# Copyright (C) 2014 Clemens Heuberger <clemens.heuberger@aau.at> 

# 2017 Vincent Delecroix <20100.delecroix@gmail.com> 

# 

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

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

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

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

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

from __future__ import absolute_import 

  

import operator, sys 

from cysignals.signals cimport sig_on, sig_str, sig_off, sig_error 

  

import sage.categories.fields 

import sage.rings.number_field.number_field as number_field 

  

cimport sage.rings.integer 

cimport sage.rings.rational 

  

from cpython.float cimport PyFloat_AS_DOUBLE 

from cpython.int cimport PyInt_AS_LONG 

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

from cpython.complex cimport PyComplex_FromDoubles 

  

from sage.ext.stdsage cimport PY_NEW 

  

from sage.libs.mpfr cimport MPFR_RNDU, MPFR_RNDD, mpfr_get_d_2exp 

from sage.libs.arb.types cimport ARF_RND_NEAR 

from sage.libs.arb.arb cimport * 

from sage.libs.arb.acb cimport * 

from sage.libs.arb.acb_calc cimport * 

from sage.libs.arb.acb_hypgeom cimport * 

from sage.libs.arb.acb_elliptic cimport * 

from sage.libs.arb.acb_modular cimport * 

from sage.libs.arb.arf cimport arf_init, arf_get_d, arf_get_mpfr, arf_set_mpfr, arf_clear, arf_set_mag, arf_set, arf_is_nan 

from sage.libs.arb.mag cimport (mag_init, mag_clear, mag_add, mag_set_d, 

MAG_BITS, mag_is_inf, mag_is_finite, mag_zero, mag_set_ui_2exp_si, 

mag_mul_2exp_si) 

from sage.libs.flint.fmpz cimport fmpz_t, fmpz_init, fmpz_get_mpz, fmpz_set_mpz, fmpz_clear, fmpz_abs 

from sage.libs.flint.fmpq cimport fmpq_t, fmpq_init, fmpq_set_mpq, fmpq_clear 

from sage.libs.gmp.mpz cimport mpz_fits_ulong_p, mpz_fits_slong_p, mpz_get_ui, mpz_get_si, mpz_sgn 

from sage.libs.gsl.complex cimport gsl_complex_rect 

  

from sage.rings.real_double cimport RealDoubleElement 

from sage.rings.complex_double cimport ComplexDoubleElement 

from sage.rings.complex_field import ComplexField 

from sage.rings.complex_interval_field import ComplexIntervalField 

from sage.rings.integer_ring import ZZ 

from sage.rings.real_arb cimport mpfi_to_arb, arb_to_mpfi 

from sage.rings.real_arb import RealBallField 

from sage.rings.real_mpfr cimport RealField_class, RealField, RealNumber 

from sage.rings.ring import Field 

from sage.structure.element cimport Element, ModuleElement 

from sage.structure.parent cimport Parent 

from sage.structure.unique_representation import UniqueRepresentation 

  

cdef void ComplexIntervalFieldElement_to_acb( 

acb_t target, 

ComplexIntervalFieldElement source): 

""" 

Convert a :class:`ComplexIntervalFieldElement` to an ``acb``. 

  

INPUT: 

  

- ``target`` -- an ``acb_t`` 

  

- ``source`` -- a :class:`ComplexIntervalFieldElement` 

  

OUTPUT: 

  

None. 

""" 

cdef long precision 

precision = source.parent().precision() 

mpfi_to_arb(acb_realref(target), source.__re, precision) 

mpfi_to_arb(acb_imagref(target), source.__im, precision) 

  

cdef int acb_to_ComplexIntervalFieldElement( 

ComplexIntervalFieldElement target, 

const acb_t source) except -1: 

""" 

Convert an ``acb`` to a :class:`ComplexIntervalFieldElement`. 

  

INPUT: 

  

- ``target`` -- a :class:`ComplexIntervalFieldElement` 

  

- ``source`` -- an ``acb_t`` 

  

OUTPUT: 

  

A :class:`ComplexIntervalFieldElement`. 

""" 

cdef long precision = target._prec 

  

arb_to_mpfi(target.__re, acb_realref(source), precision) 

arb_to_mpfi(target.__im, acb_imagref(source), precision) 

return 0 

  

  

cdef class IntegrationContext: 

r""" 

Used to wrap the integrand and hold some context information during 

numerical integration. 

""" 

cdef object f 

cdef object parent 

cdef object exn_type 

cdef object exn_obj 

cdef object exn_tb 

  

cdef int acb_calc_func_callback(acb_ptr out, const acb_t inp, void * param, 

long order, long prec): 

r""" 

Callback used for numerical integration 

  

TESTS:: 

  

sage: CBF.integral(lambda x, flag: 24, 0, 2) 

48.00000000000000 

  

sage: CBF.integral(lambda x, flag: "a", 0, 1) 

Traceback (most recent call last): 

... 

TypeError: no canonical coercion ... to Complex ball field with 53 bits 

of precision 

  

sage: def foo(*args): 

....: raise RuntimeError 

sage: CBF.integral(foo, 0, 2) 

Traceback (most recent call last): 

... 

RuntimeError 

  

sage: points = [] 

sage: def foo(x, flag): 

....: points.append(x) 

....: return x 

sage: CBF.integral(foo, 0, 1) 

[0.50000000000000...] 

sage: points 

[[+/- 1.01], ..., [0.788...], [0.211...]] 

""" 

cdef IntegrationContext ctx 

cdef ComplexBall x 

sig_off() 

try: 

ctx = <IntegrationContext>param 

if ctx.exn_type is not None or order >= 2: 

acb_indeterminate(out) 

return 0 

x = ComplexBall.__new__(ComplexBall) 

assert prec == ctx.parent._prec 

x._parent = ctx.parent 

acb_set(x.value, inp) 

try: 

y = ctx.f(x, (order == 1)) 

if not isinstance(y, ComplexBall): 

y = ctx.parent.coerce(y) 

acb_set(out, (<ComplexBall> y).value) 

except: 

ctx.exn_type, ctx.exn_obj, ctx.exn_tb = sys.exc_info() 

acb_indeterminate(out) 

return 0 

finally: 

sig_on() 

  

class ComplexBallField(UniqueRepresentation, Field): 

r""" 

An approximation of the field of complex numbers using pairs of mid-rad 

intervals. 

  

INPUT: 

  

- ``precision`` -- an integer `\ge 2`. 

  

EXAMPLES:: 

  

sage: CBF(1) 

1.000000000000000 

  

TESTS:: 

  

sage: ComplexBallField(0) 

Traceback (most recent call last): 

... 

ValueError: precision must be at least 2 

sage: ComplexBallField(1) 

Traceback (most recent call last): 

... 

ValueError: precision must be at least 2 

""" 

Element = ComplexBall 

  

@staticmethod 

def __classcall__(cls, long precision=53): 

r""" 

Normalize the arguments for caching. 

  

TESTS:: 

  

sage: ComplexBallField(53) is ComplexBallField() 

True 

""" 

return super(ComplexBallField, cls).__classcall__(cls, precision) 

  

def __init__(self, long precision=53): 

r""" 

Initialize the complex ball field. 

  

INPUT: 

  

- ``precision`` -- an integer `\ge 2`. 

  

EXAMPLES:: 

  

sage: CBF(1) 

1.000000000000000 

  

TESTS:: 

  

sage: CBF.base() 

Real ball field with 53 bits of precision 

sage: CBF.base_ring() 

Real ball field with 53 bits of precision 

  

There are direct coercions from ZZ and QQ (for which arb provides 

construction functions):: 

  

sage: CBF.coerce_map_from(ZZ) 

Coercion map: 

From: Integer Ring 

To: Complex ball field with 53 bits of precision 

sage: CBF.coerce_map_from(QQ) 

Coercion map: 

From: Rational Field 

To: Complex ball field with 53 bits of precision 

  

Various other coercions are available through real ball fields or CLF:: 

  

sage: CBF.has_coerce_map_from(RLF) 

True 

sage: CBF.has_coerce_map_from(AA) 

True 

sage: CBF.has_coerce_map_from(QuadraticField(-1)) 

True 

sage: CBF.has_coerce_map_from(QQbar) 

True 

sage: CBF.has_coerce_map_from(CLF) 

True 

""" 

if precision < 2: 

raise ValueError("precision must be at least 2") 

self._prec = precision 

real_field = RealBallField(self._prec) 

Field.__init__(self, 

base_ring=real_field, 

category=sage.categories.fields.Fields().Infinite()) 

from sage.rings.rational_field import QQ 

self._populate_coercion_lists_([ZZ, QQ], convert_method_name='_acb_') 

  

def _real_field(self): 

""" 

TESTS:: 

  

sage: CBF._real_field() is RBF 

True 

""" 

return self._base 

  

def _repr_(self): 

r""" 

String representation of ``self``. 

  

EXAMPLES:: 

  

sage: ComplexBallField() 

Complex ball field with 53 bits of precision 

sage: ComplexBallField(106) 

Complex ball field with 106 bits of precision 

""" 

return "Complex ball field with {} bits of precision".format(self._prec) 

  

def construction(self): 

""" 

Return the construction of a complex ball field as the algebraic 

closure of the real ball field with the same precision. 

  

EXAMPLES:: 

  

sage: functor, base = CBF.construction() 

sage: functor, base 

(AlgebraicClosureFunctor, Real ball field with 53 bits of precision) 

sage: functor(base) is CBF 

True 

""" 

from sage.categories.pushout import AlgebraicClosureFunctor 

return (AlgebraicClosureFunctor(), self._base) 

  

def complex_field(self): 

""" 

Return the complex ball field with the same precision, i.e. ``self`` 

  

EXAMPLES:: 

  

sage: CBF.complex_field() is CBF 

True 

""" 

return ComplexBallField(self._prec) 

  

def ngens(self): 

r""" 

Return 1 as the only generator is the imaginary unit. 

  

EXAMPLES:: 

  

sage: CBF.ngens() 

1 

""" 

return 1 

  

def gen(self, i): 

r""" 

For i = 0, return the imaginary unit in this complex ball field. 

  

EXAMPLES:: 

  

sage: CBF.0 

1.000000000000000*I 

sage: CBF.gen(1) 

Traceback (most recent call last): 

... 

ValueError: only one generator 

""" 

if i == 0: 

return self(0, 1) 

else: 

raise ValueError("only one generator") 

  

def gens(self): 

r""" 

Return the tuple of generators of this complex ball field, i.e. 

``(i,)``. 

  

EXAMPLES:: 

  

sage: CBF.gens() 

(1.000000000000000*I,) 

sage: CBF.gens_dict() 

{'1.000000000000000*I': 1.000000000000000*I} 

""" 

return (self(0, 1),) 

  

def _coerce_map_from_(self, other): 

r""" 

Parents that canonically coerce into complex ball fields include: 

  

- anything that coerces into the corresponding real ball field; 

  

- real and complex ball fields with a larger precision; 

  

- various exact or lazy parents representing subsets of the complex 

numbers, such as ``QQbar``, ``CLF``, and number fields equipped 

with complex embeddings. 

  

TESTS:: 

  

sage: CBF.coerce_map_from(CBF) 

Identity endomorphism of Complex ball field with 53 bits of precision 

sage: CBF.coerce_map_from(ComplexBallField(100)) 

Coercion map: 

From: Complex ball field with 100 bits of precision 

To: Complex ball field with 53 bits of precision 

sage: CBF.has_coerce_map_from(ComplexBallField(42)) 

False 

sage: CBF.has_coerce_map_from(RealBallField(54)) 

True 

sage: CBF.has_coerce_map_from(RealBallField(52)) 

False 

sage: CBF.has_coerce_map_from(QuadraticField(-2)) 

True 

sage: CBF.has_coerce_map_from(QuadraticField(2, embedding=None)) 

False 

  

Check that there are no coercions from interval or floating-point parents:: 

  

sage: CBF.has_coerce_map_from(RIF) 

False 

sage: CBF.has_coerce_map_from(CIF) 

False 

sage: CBF.has_coerce_map_from(RR) 

False 

sage: CBF.has_coerce_map_from(CC) 

False 

  

Check that the map goes through the ``_acb_`` method:: 

  

sage: CBF.coerce_map_from(QuadraticField(-2, embedding=AA(-2).sqrt())) 

Conversion via _acb_ method map: 

... 

sage: CBF.convert_map_from(QuadraticField(-2)) 

Conversion via _acb_ method map: 

... 

""" 

if isinstance(other, RealBallField): 

return other._prec >= self._prec 

elif isinstance(other, ComplexBallField): 

return other._prec >= self._prec 

elif isinstance(other, number_field.NumberField_quadratic): 

emb = other.coerce_embedding() 

return emb is not None and self.has_coerce_map_from(emb.codomain()) 

  

from sage.rings.all import QQ, AA, QQbar, RLF, CLF 

if other in [AA, QQbar, RLF, CLF]: 

return True 

  

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

r""" 

Convert (x, y) to an element of this complex ball field, perhaps 

non-canonically. 

  

INPUT: 

  

- ``x``, ``y`` (optional) -- either a complex number, interval or ball, 

or two real ones (see examples below for more information on accepted 

number types). 

  

EXAMPLES:: 

  

sage: CBF() 

0 

sage: CBF(1) # indirect doctest 

1.000000000000000 

sage: CBF(1, 1) 

1.000000000000000 + 1.000000000000000*I 

sage: CBF(pi, sqrt(2)) 

[3.141592653589793 +/- 5.61e-16] + [1.414213562373095 +/- 4.10e-16]*I 

sage: CBF(I) 

1.000000000000000*I 

sage: CBF(pi+I/3) 

[3.141592653589793 +/- 5.61e-16] + [0.3333333333333333 +/- 7.04e-17]*I 

sage: CBF(QQbar(i/7)) 

[0.1428571428571428 +/- 9.09e-17]*I 

sage: CBF(AA(sqrt(2))) 

[1.414213562373095 +/- 4.10e-16] 

sage: CBF(CIF(0, 1)) 

1.000000000000000*I 

sage: CBF(RBF(1/3)) 

[0.3333333333333333 +/- 7.04e-17] 

sage: CBF(RBF(1/3), RBF(1/6)) 

[0.3333333333333333 +/- 7.04e-17] + [0.1666666666666667 +/- 7.04e-17]*I 

sage: CBF(1/3) 

[0.3333333333333333 +/- 7.04e-17] 

sage: CBF(1/3, 1/6) 

[0.3333333333333333 +/- 7.04e-17] + [0.1666666666666667 +/- 7.04e-17]*I 

sage: ComplexBallField(106)(1/3, 1/6) 

[0.33333333333333333333333333333333 +/- 6.94e-33] + [0.16666666666666666666666666666666 +/- 7.70e-33]*I 

sage: NF.<a> = QuadraticField(-2) 

sage: CBF(1/5 + a/2) 

[0.2000000000000000 +/- 4.45e-17] + [0.707106781186547 +/- 5.73e-16]*I 

sage: CBF(infinity, NaN) 

[+/- inf] + nan*I 

sage: CBF(x) 

Traceback (most recent call last): 

... 

TypeError: unable to convert x to a ComplexBall 

  

.. SEEALSO:: 

  

:meth:`sage.rings.real_arb.RealBallField._element_constructor_` 

  

TESTS:: 

  

sage: CBF(1+I, 2) 

Traceback (most recent call last): 

... 

TypeError: unable to convert I + 1 to a RealBall 

""" 

try: 

return self.element_class(self, x, y) 

except TypeError: 

pass 

  

if y is None: 

try: 

x = self._base(x) 

return self.element_class(self, x) 

except (TypeError, ValueError): 

pass 

try: 

y = self._base(x.imag()) 

x = self._base(x.real()) 

return self.element_class(self, x, y) 

except (AttributeError, TypeError): 

pass 

try: 

x = ComplexIntervalField(self._prec)(x) 

return self.element_class(self, x) 

except TypeError: 

pass 

raise TypeError("unable to convert {!r} to a ComplexBall".format(x)) 

else: 

x = self._base(x) 

y = self._base(y) 

return self.element_class(self, x, y) 

  

def _an_element_(self): 

r""" 

Construct an element. 

  

EXAMPLES:: 

  

sage: CBF.an_element() # indirect doctest 

[0.3333333333333333 +/- 1.49e-17] - [0.1666666666666667 +/- 4.26e-17]*I 

""" 

return self(1.0/3, -1.0/6) 

  

def precision(self): 

""" 

Return the bit precision used for operations on elements of this field. 

  

EXAMPLES:: 

  

sage: ComplexBallField().precision() 

53 

""" 

return self._prec 

  

def is_exact(self): 

""" 

Complex ball fields are not exact. 

  

EXAMPLES:: 

  

sage: ComplexBallField().is_exact() 

False 

""" 

return False 

  

def is_finite(self): 

""" 

Complex ball fields are infinite. 

  

They already specify it via their category, but we currently need to 

re-implement this method due to the legacy implementation in 

:class:`sage.rings.ring.Ring`. 

  

EXAMPLES:: 

  

sage: ComplexBallField().is_finite() 

False 

""" 

return False 

  

def characteristic(self): 

""" 

Complex ball fields have characteristic zero. 

  

EXAMPLES:: 

  

sage: ComplexBallField().characteristic() 

0 

""" 

return 0 

  

def some_elements(self): 

""" 

Complex ball fields contain elements with exact, inexact, infinite, or 

undefined real and imaginary parts. 

  

EXAMPLES:: 

  

sage: CBF.some_elements() 

[1.000000000000000, 

-0.5000000000000000*I, 

1.000000000000000 + [0.3333333333333333 +/- 1.49e-17]*I, 

[-0.3333333333333333 +/- 1.49e-17] + 0.2500000000000000*I, 

[-2.175556475109056e+181961467118333366510562 +/- 1.29e+181961467118333366510545], 

[+/- inf], 

[0.3333333333333333 +/- 1.49e-17] + [+/- inf]*I, 

[+/- inf] + [+/- inf]*I, 

nan, 

nan + nan*I, 

[+/- inf] + nan*I] 

""" 

return [self(1), self(0, -1./2), self(1, 1./3), self(-1./3, 1./4), 

-self(1, 1)**(sage.rings.integer.Integer(2)**80), 

self('inf'), self(1./3, 'inf'), self('inf', 'inf'), 

self('nan'), self('nan', 'nan'), self('inf', 'nan')] 

  

def _sum_of_products(self, terms): 

r""" 

Compute a sum of product of complex balls without creating temporary 

Python objects 

  

The input objects should be complex balls, but need not belong to this 

parent. The computation is performed at the precision of this parent. 

  

EXAMPLES:: 

  

sage: Pol.<x> = ComplexBallField(1000)[] 

sage: pol = (x + 1/3)^100 

sage: CBF._sum_of_products((c, c) for c in pol) 

[6.3308767660842e+23 +/- 4.59e+9] 

  

TESTS:: 

  

sage: CBF._sum_of_products([]) 

0 

sage: CBF._sum_of_products([[]]) 

1.000000000000000 

sage: CBF._sum_of_products([["a"]]) 

Traceback (most recent call last): 

... 

TypeError: Cannot convert str to sage.rings.complex_arb.ComplexBall 

""" 

cdef ComplexBall res = ComplexBall.__new__(ComplexBall) 

cdef ComplexBall factor 

cdef acb_t tmp 

res._parent = self 

acb_zero(res.value) 

acb_init(tmp) 

try: 

for term in terms: 

acb_one(tmp) 

for factor in term: 

acb_mul(tmp, tmp, factor.value, self._prec) 

acb_add(res.value, res.value, tmp, self._prec) 

finally: 

acb_clear(tmp) 

return res 

  

# Constants 

  

def pi(self): 

r""" 

Return a ball enclosing `\pi`. 

  

EXAMPLES:: 

  

sage: CBF.pi() 

[3.141592653589793 +/- 5.61e-16] 

sage: ComplexBallField(128).pi() 

[3.1415926535897932384626433832795028842 +/- 1.65e-38] 

  

sage: CBF.pi().parent() 

Complex ball field with 53 bits of precision 

""" 

cdef ComplexBall res = ComplexBall.__new__(ComplexBall) 

res._parent = self 

if _do_sig(self._prec): sig_on() 

arb_const_pi(acb_realref(res.value), self._prec) 

arb_zero(acb_imagref(res.value)) 

if _do_sig(self._prec): sig_off() 

return res 

  

def integral(self, func, a, b, params=None, 

rel_tol=None, abs_tol=None, 

deg_limit=None, eval_limit=None, depth_limit=None, 

use_heap=None, verbose=None): 

r""" 

Compute a rigorous enclosure of the integral of ``func`` on the 

interval [``a``, ``b``]. 

  

INPUT: 

  

- ``func`` -- a callable object accepting two parameters, a complex 

ball ``x`` and a boolean flag ``analytic``, and returning an element 

of this ball field (or some value that coerces into this ball field), 

such that: 

  

- ``func(x, False)`` evaluates the integrand `f` on the ball ``x``. 

There are no restrictions on the behavior of `f` on ``x``; in 

particular, it can be discontinuous. 

  

- ``func(x, True)`` evaluates `f(x)` if `f` is analytic on the 

whole ``x``, and returns some non-finite ball (e.g., ``self(NaN)``) 

otherwise. 

  

(The ``analytic`` flag only needs to be checked for integrands that 

are non-analytic but bounded in some regions, typically complex 

functions with branch cuts, like `\sqrt{z}`. In particular, it can be 

ignored for meromorphic functions.) 

  

- ``a``, ``b`` -- integration bounds. The bounds can be real or complex 

balls, or elements of any parent that coerces into this ball field, 

e.g. rational or algebraic numbers. 

  

- ``rel_tol`` (optional, default `2^{-p}` where `p` is the precision of 

the ball field) -- relative accuracy goal 

  

- ``abs_tol`` (optional, default `2^{-p}` where `p` is the precision of 

the ball field) -- absolute accuracy goal 

  

Additionally, the following optional parameters can be used to control 

the integration algorithm. See the `Arb documentation <http://arblib.org/acb_calc.html>`_ 

for more information. 

  

- ``deg_limit`` -- maximum quadrature degree for each 

subinterval 

  

- ``eval_limit`` -- maximum number of function 

evaluations 

  

- ``depth_limit`` -- maximum search depth for 

adaptive subdivision 

  

- ``use_heap`` (boolean, default ``False``) -- if ``True``, use a 

priority queue instead of a stack to manage subintervals. This 

sometimes gives better results for integrals with slow convergence but 

may require more memory and increasing ``depth_limit``. 

  

- ``verbose`` (integer, default 0) -- If set to 1, some information 

about the overall integration process is printed to standard 

output. If set to 2, information about each subinterval is printed. 

  

EXAMPLES: 

  

Some analytic integrands:: 

  

sage: CBF.integral(lambda x, _: x, 0, 1) 

[0.500000000000000 +/- 2.09e-16] 

  

sage: CBF.integral(lambda x, _: x.gamma(), 1 - CBF(i), 1 + CBF(i)) 

[+/- 3.95e-15] + [1.5723926694981 +/- 4.53e-14]*I 

  

sage: C = ComplexBallField(100) 

sage: C.integral(lambda x, _: x.cos() * x.sin(), 0, 1) 

[0.35403670913678559674939205737 +/- 8.89e-30] 

  

sage: CBF.integral(lambda x, _: (x + x.exp()).sin(), 0, 8) 

[0.34740017266 +/- 6.36e-12] 

  

sage: C = ComplexBallField(2000) 

sage: C.integral(lambda x, _: (x + x.exp()).sin(), 0, 8) # long time 

[0.34740017...55347713 +/- 6.72e-598] 

  

Here the integration path crosses the branch cut of the square root:: 

  

sage: def my_sqrt(z, analytic): 

....: if (analytic and not z.real() > 0 

....: and z.imag().contains_zero()): 

....: return CBF(NaN) 

....: else: 

....: return z.sqrt() 

sage: CBF.integral(my_sqrt, -1 + CBF(i), -1 - CBF(i)) 

[+/- 1.14e-14] + [-0.4752076627926 +/- 5.18e-14]*I 

  

Note, though, that proper handling of the ``analytic`` flag is required 

even when the path does not touch the branch cut:: 

  

sage: correct = CBF.integral(my_sqrt, 1, 2); correct 

[1.21895141649746 +/- 3.73e-15] 

sage: RBF(integral(sqrt(x), x, 1, 2)) 

[1.21895141649746 +/- 1.79e-15] 

sage: wrong = CBF.integral(lambda z, _: z.sqrt(), 1, 2) # WRONG! 

sage: correct - wrong 

[-5.640636259e-5 +/- 6.80e-15] 

  

We can integrate the real absolute value function by defining a 

piecewise holomorphic extension:: 

  

sage: def real_abs(z, analytic): 

....: if z.real().contains_zero(): 

....: if analytic: 

....: return z.parent()(NaN) 

....: else: 

....: return z.union(-z) 

....: elif z.real() > 0: 

....: return z 

....: else: 

....: return -z 

sage: CBF.integral(real_abs, -1, 1) 

[1.00000000000...] 

sage: CBF.integral(lambda z, analytic: real_abs(z.sin(), analytic), 0, 2*CBF.pi()) 

[4.00000000000...] 

  

Here the integrand has a pole on or very close to the integration path, 

but there is no need to explicitly handle the ``analytic`` flag since 

the integrand is unbounded:: 

  

sage: CBF.integral(lambda x, _: 1/x, -1, 1) 

[+/- inf] + [+/- inf]*I 

sage: CBF.integral(lambda x, _: 1/x, 10^-1000, 1) 

[+/- inf] + [+/- inf]*I 

sage: CBF.integral(lambda x, _: 1/x, 10^-1000, 1, abs_tol=1e-10) 

[2302.5850930 +/- 1.26e-8] 

  

Tolerances:: 

  

sage: CBF.integral(lambda x, _: x.exp(), -1020, -1010) 

[+/- 2.31e-438] 

sage: CBF.integral(lambda x, _: x.exp(), -1020, -1010, abs_tol=1e-450) 

[2.304377150950e-439 +/- 9.74e-452] 

sage: CBF.integral(lambda x, _: x.exp(), -1020, -1010, abs_tol=0) 

[2.304377150949e-439 +/- 7.53e-452] 

sage: CBF.integral(lambda x, _: x.exp(), -1020, -1010, rel_tol=1e-4, abs_tol=0) 

[2.30438e-439 +/- 3.90e-445] 

  

sage: CBF.integral(lambda x, _: x*(1/x).sin(), 0, 1) 

[+/- 0.644] 

sage: CBF.integral(lambda x, _: x*(1/x).sin(), 0, 1, use_heap=True) 

[0.3785300 +/- 4.32e-8] 

  

ALGORITHM: 

  

Uses the `acb_calc <http://arblib.org/acb_calc.html>`_ module of the Arb 

library. 

  

TESTS:: 

  

sage: CBF.integral(lambda x, _: x, 0, 10, rel_tol=1e-10, 

....: abs_tol=1e-10, deg_limit=1, eval_limit=20, depth_limit=4, 

....: use_heap=False) 

[50.00000000 +/- 2.20e-9] 

  

sage: i = QuadraticField(-1).gen() 

sage: CBF.integral(lambda x, _: (1 + i*x).gamma(), -1, 1) 

[1.5723926694981 +/- 4.53e-14] + [+/- 3.95e-15]*I 

  

sage: ComplexBallField(10000).integral(lambda x, _: x.sin(), 0, 1, rel_tol=1e-400) 

[0.459... +/- ...e-4...] 

sage: CBF.integral(lambda x, _: x.sin(), 0, 100, rel_tol=10) 

[+/- 7.61] 

  

sage: ComplexBallField(10000).integral(lambda x, _: x.sin(), 0, 1, abs_tol=1e-400) 

[0.459697... +/- ...e-4...] 

sage: CBF.integral(lambda x, _: x.sin(), 0, 1, abs_tol=10) 

[+/- 0.980] 

  

sage: ComplexBallField(100).integral(lambda x, _: sin(x), RBF(0), RBF(1)) 

[0.4596976941318602825990633926 +/- 5.09e-29] 

""" 

cdef IntegrationContext ctx = IntegrationContext() 

cdef acb_calc_integrate_opt_t arb_opts 

cdef long cgoal, expo 

cdef mag_t ctol 

cdef RealNumber tmp 

cdef ComplexBall ca, cb 

  

if isinstance(a, (RealBall, ComplexBall)): 

ca = <ComplexBall> self(a) 

else: 

ca = <ComplexBall> self.coerce(a) 

if isinstance(b, (RealBall, ComplexBall)): 

cb = <ComplexBall> self(b) 

else: 

cb = <ComplexBall> self.coerce(b) 

  

mag_init(ctol) 

  

ctx.f = func 

ctx.parent = self 

ctx.exn_type = None 

  

acb_calc_integrate_opt_init(arb_opts) 

if deg_limit is not None: 

arb_opts.deg_limit = deg_limit 

if eval_limit is not None: 

arb_opts.eval_limit = eval_limit 

if depth_limit is not None: 

arb_opts.depth_limit = depth_limit 

if use_heap is not None: 

arb_opts.use_heap = use_heap 

if verbose is not None: 

arb_opts.verbose = verbose 

  

RR = RealField() 

if rel_tol is None: 

cgoal = self._prec 

else: 

tmp = <RealNumber> RR(rel_tol) 

mpfr_get_d_2exp(&cgoal, tmp.value, MPFR_RNDD) 

cgoal = -cgoal 

  

if abs_tol is None: 

mag_set_ui_2exp_si(ctol, 1, -self._prec) 

else: 

tmp = <RealNumber> RR(abs_tol) 

mag_set_d(ctol, mpfr_get_d_2exp(&expo, tmp.value, MPFR_RNDD)) 

mag_mul_2exp_si(ctol, ctol, expo) 

  

cdef ComplexBall res = ComplexBall.__new__(ComplexBall) 

res._parent = self 

  

try: 

sig_on() 

acb_calc_integrate( 

res.value, 

<acb_calc_func_t> acb_calc_func_callback, 

<void *> ctx, 

ca.value, cb.value, 

cgoal, ctol, arb_opts, self._prec) 

sig_off() 

finally: 

mag_clear(ctol) 

  

if ctx.exn_type is not None: 

raise ctx.exn_type, ctx.exn_obj, ctx.exn_tb 

  

return res 

  

cdef inline bint _do_sig(long prec): 

""" 

Whether signal handlers should be installed for calls to arb. 

""" 

return (prec > 1000) 

  

cdef inline long prec(ComplexBall ball): 

return ball._parent._prec 

  

cdef inline real_ball_field(ComplexBall ball): 

return ball._parent._base 

  

cdef class ComplexBall(RingElement): 

""" 

Hold one ``acb_t`` of the `Arb library 

<http://fredrikj.net/arb/>`_ 

  

EXAMPLES:: 

  

sage: a = ComplexBallField()(1, 1) 

sage: a 

1.000000000000000 + 1.000000000000000*I 

""" 

def __cinit__(self): 

""" 

Allocate memory for the encapsulated value. 

  

EXAMPLES:: 

  

sage: ComplexBallField(2)(0) # indirect doctest 

0 

""" 

acb_init(self.value) 

  

def __dealloc__(self): 

""" 

Deallocate memory of the encapsulated value. 

  

EXAMPLES:: 

  

sage: a = ComplexBallField(2)(0) # indirect doctest 

sage: del a 

""" 

acb_clear(self.value) 

  

def __init__(self, parent, x=None, y=None): 

""" 

Initialize the :class:`ComplexBall`. 

  

INPUT: 

  

- ``parent`` -- a :class:`ComplexBallField`. 

  

- ``x``, ``y`` (optional) -- either a complex number, interval or ball, 

or two real ones. 

  

.. SEEALSO:: :meth:`ComplexBallField._element_constructor_` 

  

TESTS:: 

  

sage: from sage.rings.complex_arb import ComplexBall 

sage: CBF53, CBF100 = ComplexBallField(53), ComplexBallField(100) 

sage: ComplexBall(CBF100) 

0 

sage: ComplexBall(CBF100, ComplexBall(CBF53, ComplexBall(CBF100, 1/3))) 

[0.333333333333333333333333333333 +/- 4.65e-31] 

sage: ComplexBall(CBF100, RBF(pi)) 

[3.141592653589793 +/- 5.61e-16] 

  

sage: ComplexBall(CBF100, -3r) 

Traceback (most recent call last): 

... 

TypeError: unsupported initializer 

sage: CBF100(-3r) 

-3.000000000000000000000000000000 

  

sage: ComplexBall(CBF100, 10^100) 

1.000000000000000000000000000000e+100 

sage: ComplexBall(CBF100, CIF(1, 2)) 

1.000000000000000000000000000000 + 2.000000000000000000000000000000*I 

sage: ComplexBall(CBF100, RBF(1/3), RBF(1)) 

[0.3333333333333333 +/- 7.04e-17] + 1.000000000000000000000000000000*I 

sage: NF.<a> = QuadraticField(-1, embedding=CC(0, -1)) 

sage: CBF(a) 

-1.000000000000000*I 

  

sage: NF.<a> = QuadraticField(-1, embedding=None) 

sage: CBF(a) 

1.000000000000000*I 

sage: CBF.coerce(a) 

Traceback (most recent call last): 

... 

TypeError: no canonical coercion ... 

  

sage: NF.<a> = QuadraticField(-2) 

sage: CBF(1/3 + a).real() 

[0.3333333333333333 +/- 7.04e-17] 

  

sage: ComplexBall(CBF, 1, 1/2) 

1.000000000000000 + 0.5000000000000000*I 

sage: ComplexBall(CBF, 1, 1) 

1.000000000000000 + 1.000000000000000*I 

sage: ComplexBall(CBF, 1, 1/2) 

1.000000000000000 + 0.5000000000000000*I 

sage: ComplexBall(CBF, 1/2, 1) 

0.5000000000000000 + 1.000000000000000*I 

sage: ComplexBall(CBF, 1/2, 1/2) 

0.5000000000000000 + 0.5000000000000000*I 

sage: ComplexBall(CBF, 1/2, 'a') 

Traceback (most recent call last): 

... 

TypeError: unsupported initializer 

sage: ComplexBall(CBF, 'a') 

Traceback (most recent call last): 

... 

TypeError: unsupported initializer 

  

""" 

cdef fmpz_t tmpz 

cdef fmpq_t tmpq 

cdef long myprec 

cdef bint cplx = False 

  

Element.__init__(self, parent) 

  

if x is None: 

return 

elif isinstance(x, ComplexBall): 

acb_set(self.value, (<ComplexBall> x).value) 

cplx = True 

elif isinstance(x, RealBall): 

arb_set(acb_realref(self.value), (<RealBall> x).value) 

elif isinstance(x, sage.rings.integer.Integer): 

if _do_sig(prec(self)): sig_on() 

fmpz_init(tmpz) 

fmpz_set_mpz(tmpz, (<sage.rings.integer.Integer> x).value) 

arb_set_fmpz(acb_realref(self.value), tmpz) 

fmpz_clear(tmpz) 

if _do_sig(prec(self)): sig_off() 

elif isinstance(x, sage.rings.rational.Rational): 

if _do_sig(prec(self)): sig_on() 

fmpq_init(tmpq) 

fmpq_set_mpq(tmpq, (<sage.rings.rational.Rational> x).value) 

arb_set_fmpq(acb_realref(self.value), tmpq, prec(self)) 

fmpq_clear(tmpq) 

if _do_sig(prec(self)): sig_off() 

elif isinstance(x, ComplexIntervalFieldElement): 

ComplexIntervalFieldElement_to_acb(self.value, 

<ComplexIntervalFieldElement> x) 

cplx = True 

else: 

raise TypeError("unsupported initializer") 

  

if y is None: 

return 

elif cplx: 

raise TypeError("unsupported initializer") 

elif isinstance(y, RealBall): 

arb_set(acb_imagref(self.value), (<RealBall> y).value) 

elif isinstance(y, sage.rings.integer.Integer): 

if _do_sig(prec(self)): sig_on() 

fmpz_init(tmpz) 

fmpz_set_mpz(tmpz, (<sage.rings.integer.Integer> y).value) 

arb_set_fmpz(acb_imagref(self.value), tmpz) 

fmpz_clear(tmpz) 

if _do_sig(prec(self)): sig_off() 

elif isinstance(y, sage.rings.rational.Rational): 

if _do_sig(prec(self)): sig_on() 

fmpq_init(tmpq) 

fmpq_set_mpq(tmpq, (<sage.rings.rational.Rational> y).value) 

arb_set_fmpq(acb_imagref(self.value), tmpq, prec(self)) 

fmpq_clear(tmpq) 

if _do_sig(prec(self)): sig_off() 

else: 

raise TypeError("unsupported initializer") 

  

def __hash__(self): 

""" 

TESTS:: 

  

sage: hash(CBF(1/3)) == hash(RBF(1/3)) 

True 

sage: hash(CBF(1/3 + 2*i)) != hash(CBF(1/3 + i)) 

True 

""" 

if self.is_real(): 

return hash(self.real()) 

else: 

return (hash(self.real()) // 3) ^ hash(self.imag()) 

  

def _repr_(self): 

""" 

Return a string representation of ``self``. 

  

OUTPUT: 

  

A string. 

  

EXAMPLES:: 

  

sage: CBF(1/3) 

[0.3333333333333333 +/- 7.04e-17] 

sage: CBF(0, 1/3) 

[0.3333333333333333 +/- 7.04e-17]*I 

sage: CBF(1/3, 1/6) 

[0.3333333333333333 +/- 7.04e-17] + [0.1666666666666667 +/- 7.04e-17]*I 

  

TESTS:: 

  

sage: CBF(1-I/2) 

1.000000000000000 - 0.5000000000000000*I 

""" 

cdef arb_t real = acb_realref(self.value) 

cdef arb_t imag = acb_imagref(self.value) 

if arb_is_zero(imag): 

return self.real()._repr_() 

elif arb_is_zero(real): 

return "{}*I".format(self.imag()._repr_()) 

elif arb_is_exact(imag) and arb_is_negative(imag): 

return "{} - {}*I".format(self.real()._repr_(), 

(-self.imag())._repr_()) 

else: 

return "{} + {}*I".format(self.real()._repr_(), 

self.imag()._repr_()) 

  

def _is_atomic(self): 

r""" 

Declare that complex balls print atomically in some cases. 

  

TESTS:: 

  

sage: CBF(-1/3)._is_atomic() 

True 

  

This method should in principle ensure that ``CBF['x']([1, -1/3])`` 

is printed as:: 

  

sage: CBF['x']([1, -1/3]) # todo - not tested 

[-0.3333333333333333 +/- 7.04e-17]*x + 1.000000000000000 

  

However, this facility is not really used in Sage at this point, and we 

still get:: 

  

sage: CBF['x']([1, -1/3]) 

([-0.3333333333333333 +/- 7.04e-17])*x + 1.000000000000000 

""" 

return self.is_real() or self.real().is_zero() 

  

# Conversions 

  

cpdef ComplexIntervalFieldElement _complex_mpfi_(self, parent): 

""" 

Return :class:`ComplexIntervalFieldElement` of the same value. 

  

EXAMPLES:: 

  

sage: CIF(CBF(1/3, 1/3)) # indirect doctest 

0.3333333333333333? + 0.3333333333333333?*I 

""" 

cdef ComplexIntervalFieldElement res = parent.zero() 

res = res._new() # FIXME after modernizing CIF 

acb_to_ComplexIntervalFieldElement(res, self.value) 

return res 

  

def _integer_(self, _): 

""" 

Check that this ball contains a single integer and return that integer. 

  

EXAMPLES:: 

  

sage: ZZ(CBF(-42, RBF(.1, rad=.2))) # indirect doctest 

-42 

sage: ZZ(CBF(i)) 

Traceback (most recent call last): 

... 

ValueError: 1.000000000000000*I does not contain a unique integer 

""" 

cdef sage.rings.integer.Integer res 

cdef fmpz_t tmp 

fmpz_init(tmp) 

try: 

if acb_get_unique_fmpz(tmp, self.value): 

res = sage.rings.integer.Integer.__new__(sage.rings.integer.Integer) 

fmpz_get_mpz(res.value, tmp) 

else: 

raise ValueError("{} does not contain a unique integer".format(self)) 

finally: 

fmpz_clear(tmp) 

return res 

  

def _rational_(self): 

""" 

Check that this ball contains a single rational number and return that 

number. 

  

EXAMPLES:: 

  

sage: QQ(CBF(12345/2^5)) 

12345/32 

sage: QQ(CBF(i)) 

Traceback (most recent call last): 

... 

ValueError: 1.000000000000000*I does not contain a unique rational number 

""" 

if acb_is_real(self.value) and acb_is_exact(self.value): 

return self.real().mid().exact_rational() 

else: 

raise ValueError("{} does not contain a unique rational number".format(self)) 

  

def _complex_mpfr_field_(self, parent): 

r""" 

Convert this complex ball to a complex number. 

  

INPUT: 

  

- ``parent`` - :class:`~sage.rings.complex_field.ComplexField_class`, 

target parent. 

  

EXAMPLES:: 

  

sage: CC(CBF(1/3, 1/3)) 

0.333333333333333 + 0.333333333333333*I 

sage: ComplexField(100)(CBF(1/3, 1/3)) 

0.33333333333333331482961625625 + 0.33333333333333331482961625625*I 

  

Check nan and inf:: 

  

sage: CC(CBF('nan', 1/3)) 

NaN + 0.333333333333333*I 

sage: CC(CBF('+inf')) 

+infinity 

""" 

real_field = parent._base 

return parent(real_field(self.real()), real_field(self.imag())) 

  

def _real_mpfi_(self, parent): 

r""" 

Try to convert this complex ball to a real interval. 

  

Fail if the imaginary part is not exactly zero. 

  

INPUT: 

  

- ``parent`` - :class:`~sage.rings.real_mpfi.RealIntervalField_class`, 

target parent. 

  

EXAMPLES:: 

  

sage: RIF(CBF(RBF(1/3, rad=1e-5))) 

0.3334? 

sage: RIF(CBF(RBF(1/3, rad=1e-5), 1e-10)) 

Traceback (most recent call last): 

... 

ValueError: nonzero imaginary part 

""" 

if acb_is_real(self.value): 

return parent(self.real()) 

else: 

raise ValueError("nonzero imaginary part") 

  

def _mpfr_(self, parent): 

r""" 

Try to convert this complex ball to a real number. 

  

Fail if the imaginary part is not exactly zero. 

  

INPUT: 

  

- ``parent`` - :class:`~sage.rings.real_mpfr.RealField_class`, 

target parent. 

  

EXAMPLES:: 

  

sage: RR(CBF(1/3)) 

0.333333333333333 

sage: RR(CBF(1, 1/3) - CBF(0, 1/3)) 

Traceback (most recent call last): 

... 

ValueError: nonzero imaginary part 

""" 

if acb_is_real(self.value): 

return parent(self.real()) 

else: 

raise ValueError("nonzero imaginary part") 

  

def __float__(self): 

""" 

Convert ``self`` to a ``float``. 

  

EXAMPLES:: 

  

sage: float(CBF(1)) 

1.0 

sage: float(CBF(1/3)) 

0.3333333333333333 

sage: float(CBF(1,1)) 

Traceback (most recent call last): 

... 

TypeError: can't convert complex ball to float 

""" 

if not arb_is_zero(acb_imagref(self.value)): 

raise TypeError("can't convert complex ball to float") 

return arf_get_d(arb_midref(acb_realref(self.value)), ARF_RND_NEAR) 

  

def __complex__(self): 

""" 

Convert ``self`` to a ``complex``. 

  

EXAMPLES:: 

  

sage: complex(CBF(1)) 

(1+0j) 

sage: complex(CBF(1,1)) 

(1+1j) 

  

Check nan and inf:: 

  

sage: complex(CBF(0, 'nan')) 

nanj 

sage: complex(CBF('+inf', '-inf')) 

(inf-infj) 

""" 

return PyComplex_FromDoubles( 

arf_get_d(arb_midref(acb_realref(self.value)), ARF_RND_NEAR), 

arf_get_d(arb_midref(acb_imagref(self.value)), ARF_RND_NEAR)) 

  

def _real_double_(self, parent): 

r""" 

Convert this complex ball to a real double. 

  

EXAMPLES:: 

  

sage: RDF(CBF(3)) 

3.0 

sage: RDF(CBF(3/7)) 

0.42857142857142855 

sage: RDF(CBF(1 + I)) 

Traceback (most recent call last): 

... 

TypeError: can't convert complex ball to float 

  

sage: RDF(CBF(3)).parent() 

Real Double Field 

  

Check nan and inf:: 

  

sage: RDF(CBF('nan')) 

NaN 

sage: RDF(CBF('nan')).parent() 

Real Double Field 

sage: RDF(CBF('+inf')) 

+infinity 

sage: RDF(CBF('+inf')).parent() 

Real Double Field 

  

TESTS: 

  

Check that conversions go through this method:: 

  

sage: RDF.convert_map_from(CBF) 

Conversion via _real_double_ method map: 

From: Complex ball field with 53 bits of precision 

To: Real Double Field 

""" 

if not arb_is_zero(acb_imagref(self.value)): 

raise TypeError("can't convert complex ball to float") 

cdef RealDoubleElement x 

x = PY_NEW(RealDoubleElement) 

x._value = arf_get_d(arb_midref(acb_realref(self.value)), ARF_RND_NEAR) 

return x 

  

def _complex_double_(self, parent): 

r""" 

Convert this complex ball to a complex double. 

  

EXAMPLES:: 

  

sage: CDF(CBF(1+I)) 

1.0 + 1.0*I 

sage: CDF(CBF(3/7, -21/13)) 

0.42857142857142855 - 1.6153846153846152*I 

  

Check nan and inf:: 

  

sage: CDF(CBF('nan', 'nan')) 

NaN + NaN*I 

sage: CDF(CBF('+inf', 'nan')) 

+infinity + NaN*I 

sage: CDF(CBF('+inf', '-inf')) 

+infinity - +infinity*I 

  

TESTS: 

  

The conversion map should go through this method. However, it is 

manually called in the constructor of complex double elements:: 

  

sage: CDF.convert_map_from(CBF) # bug 

Conversion map: 

From: Complex ball field with 53 bits of precision 

To: Complex Double Field 

""" 

cdef ComplexDoubleElement x = ComplexDoubleElement.__new__(ComplexDoubleElement) 

x._complex = gsl_complex_rect( 

arf_get_d(arb_midref(acb_realref(self.value)), ARF_RND_NEAR), 

arf_get_d(arb_midref(acb_imagref(self.value)), ARF_RND_NEAR)) 

return x 

  

# Real and imaginary part, midpoint, radius 

  

cpdef RealBall real(self): 

""" 

Return the real part of this ball. 

  

OUTPUT: 

  

A :class:`~sage.rings.real_arb.RealBall`. 

  

EXAMPLES:: 

  

sage: a = CBF(1/3, 1/5) 

sage: a.real() 

[0.3333333333333333 +/- 7.04e-17] 

sage: a.real().parent() 

Real ball field with 53 bits of precision 

""" 

cdef RealBall r = RealBall.__new__(RealBall) 

r._parent = real_ball_field(self) 

arb_set(r.value, acb_realref(self.value)) 

return r 

  

cpdef RealBall imag(self): 

""" 

Return the imaginary part of this ball. 

  

OUTPUT: 

  

A :class:`~sage.rings.real_arb.RealBall`. 

  

EXAMPLES:: 

  

sage: a = CBF(1/3, 1/5) 

sage: a.imag() 

[0.2000000000000000 +/- 4.45e-17] 

sage: a.imag().parent() 

Real ball field with 53 bits of precision 

""" 

cdef RealBall r = RealBall.__new__(RealBall) 

r._parent = real_ball_field(self) 

arb_set(r.value, acb_imagref(self.value)) 

return r 

  

def __abs__(self): 

""" 

Return the absolute value of this complex ball. 

  

EXAMPLES:: 

  

sage: CBF(1 + i).abs() # indirect doctest 

[1.414213562373095 +/- 2.99e-16] 

sage: abs(CBF(i)) 

1.000000000000000 

  

sage: CBF(1 + i).abs().parent() 

Real ball field with 53 bits of precision 

""" 

cdef RealBall r = RealBall(real_ball_field(self)) 

acb_abs(r.value, self.value, prec(self)) 

return r 

  

def below_abs(self, test_zero=False): 

""" 

Return a lower bound for the absolute value of this complex ball. 

  

INPUT: 

  

- ``test_zero`` (boolean, default ``False``) -- if ``True``, 

make sure that the returned lower bound is positive, raising 

an error if the ball contains zero. 

  

OUTPUT: 

  

A ball with zero radius 

  

EXAMPLES:: 

  

sage: b = ComplexBallField(8)(1+i).below_abs() 

sage: b 

[1.4 +/- 0.0141] 

sage: b.is_exact() 

True 

sage: QQ(b)*128 

181 

sage: (CBF(1/3) - 1/3).below_abs() 

0 

sage: (CBF(1/3) - 1/3).below_abs(test_zero=True) 

Traceback (most recent call last): 

... 

ValueError: ball contains zero 

  

.. SEEALSO:: :meth:`above_abs` 

""" 

cdef RealBall res = RealBall(real_ball_field(self)) 

acb_get_abs_lbound_arf(arb_midref(res.value), self.value, prec(self)) 

if test_zero and arb_contains_zero(res.value): 

assert acb_contains_zero(self.value) 

raise ValueError("ball contains zero") 

return res 

  

def above_abs(self): 

""" 

Return an upper bound for the absolute value of this complex ball. 

  

OUTPUT: 

  

A ball with zero radius 

  

EXAMPLES:: 

  

sage: b = ComplexBallField(8)(1+i).above_abs() 

sage: b 

[1.4 +/- 0.0219] 

sage: b.is_exact() 

True 

sage: QQ(b)*128 

182 

  

.. SEEALSO:: :meth:`below_abs` 

""" 

cdef RealBall res = RealBall(real_ball_field(self)) 

acb_get_abs_ubound_arf(arb_midref(res.value), self.value, prec(self)) 

return res 

  

def arg(self): 

""" 

Return the argument of this complex ball. 

  

EXAMPLES:: 

  

sage: CBF(1 + i).arg() 

[0.785398163397448 +/- 3.91e-16] 

sage: CBF(-1).arg() 

[3.141592653589793 +/- 5.61e-16] 

sage: CBF(-1).arg().parent() 

Real ball field with 53 bits of precision 

""" 

cdef RealBall r = RealBall(real_ball_field(self)) 

acb_arg(r.value, self.value, prec(self)) 

return r 

  

def mid(self): 

""" 

Return the midpoint of this ball. 

  

OUTPUT: 

  

:class:`~sage.rings.complex_number.ComplexNumber`, floating-point 

complex number formed by the centers of the real and imaginary parts of 

this ball. 

  

EXAMPLES:: 

  

sage: CBF(1/3, 1).mid() 

0.333333333333333 + 1.00000000000000*I 

sage: CBF(1/3, 1).mid().parent() 

Complex Field with 53 bits of precision 

sage: CBF('inf', 'nan').mid() 

+infinity + NaN*I 

sage: CBF('nan', 'inf').mid() 

NaN + +infinity*I 

sage: CBF('nan').mid() 

NaN 

sage: CBF('inf').mid() 

+infinity 

sage: CBF(0, 'inf').mid() 

+infinity*I 

  

.. SEEALSO:: :meth:`squash` 

""" 

re, im = self.real().mid(), self.imag().mid() 

field = sage.rings.complex_field.ComplexField( 

max(prec(self), re.prec(), im.prec())) 

return field(re, im) 

  

def squash(self): 

""" 

Return an exact ball with the same midpoint as this ball. 

  

OUTPUT: 

  

A :class:`ComplexBall`. 

  

EXAMPLES:: 

  

sage: mid = CBF(1/3, 1/10).squash() 

sage: mid 

[0.3333333333333333 +/- 1.49e-17] + [0.09999999999999999 +/- 1.68e-18]*I 

sage: mid.parent() 

Complex ball field with 53 bits of precision 

sage: mid.is_exact() 

True 

  

.. SEEALSO:: :meth:`mid` 

""" 

cdef ComplexBall res = self._new() 

arf_set(arb_midref(acb_realref(res.value)), arb_midref(acb_realref(self.value))) 

arf_set(arb_midref(acb_imagref(res.value)), arb_midref(acb_imagref(self.value))) 

mag_zero(arb_radref(acb_realref(res.value))) 

mag_zero(arb_radref(acb_imagref(res.value))) 

return res 

  

def rad(self): 

""" 

Return an upper bound for the error radius of this ball. 

  

OUTPUT: 

  

A :class:`~sage.rings.real_mpfr.RealNumber` of the same precision as 

the radii of real balls. 

  

.. WARNING:: 

  

Unlike a :class:`~sage.rings.real_arb.RealBall`, 

a :class:`ComplexBall` is *not* defined 

by its midpoint and radius. (Instances of :class:`ComplexBall` are 

actually rectangles, not balls.) 

  

EXAMPLES:: 

  

sage: CBF(1 + i).rad() 

0.00000000 

sage: CBF(i/3).rad() 

1.1102230e-16 

sage: CBF(i/3).rad().parent() 

Real Field with 30 bits of precision 

  

.. SEEALSO:: :meth:`diameter`, :meth:`mid` 

  

TESTS:: 

  

sage: (CBF(0, 1/3) << (2^64)).rad() 

Traceback (most recent call last): 

... 

RuntimeError: unable to convert the radius to MPFR (exponent out of range?) 

""" 

# Should we return a real number with rounding towards +∞ (or away from 

# zero if/when implemented)? 

cdef RealField_class rad_field = RealField(MAG_BITS) 

cdef RealNumber rad = RealNumber(rad_field, None) 

cdef arf_t tmp 

arf_init(tmp) 

acb_get_rad_ubound_arf(tmp, self.value, MAG_BITS) 

sig_str("unable to convert the radius to MPFR (exponent out of range?)") 

if arf_get_mpfr(rad.value, tmp, MPFR_RNDU): 

sig_error() 

sig_off() 

arf_clear(tmp) 

return rad 

  

# Should we implement rad_as_ball? If we do, should it return an enclosure 

# of the radius (which radius?), or an upper bound? 

  

def diameter(self): 

r""" 

Return the diameter of this ball. 

  

EXAMPLES:: 

  

sage: CBF(1 + i).diameter() 

0.00000000 

sage: CBF(i/3).diameter() 

2.2204460e-16 

sage: CBF(i/3).diameter().parent() 

Real Field with 30 bits of precision 

sage: CBF(CIF(RIF(1.02, 1.04), RIF(2.1, 2.2))).diameter() 

0.20000000 

  

.. SEEALSO:: :meth:`rad`, :meth:`mid` 

""" 

return 2 * self.rad() 

  

def union(self, other): 

r""" 

Return a ball containing the convex hull of ``self`` and ``other``. 

  

EXAMPLES:: 

  

sage: b = CBF(1 + i).union(0) 

sage: b.real().endpoints() 

(-9.31322574615479e-10, 1.00000000093133) 

""" 

cdef ComplexBall my_other = self._parent.coerce(other) 

cdef ComplexBall res = self._new() 

if _do_sig(prec(self)): sig_on() 

acb_union(res.value, self.value, my_other.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return res 

  

# Precision and accuracy 

  

def round(self): 

""" 

Return a copy of this ball rounded to the precision of the parent. 

  

EXAMPLES: 

  

It is possible to create balls whose midpoint is more precise that 

their parent's nominal precision (see :mod:`~sage.rings.real_arb` for 

more information):: 

  

sage: b = CBF(exp(I*pi/3).n(100)) 

sage: b.mid() 

0.50000000000000000000000000000 + 0.86602540378443864676372317075*I 

  

The ``round()`` method rounds such a ball to its parent's precision:: 

  

sage: b.round().mid() 

0.500000000000000 + 0.866025403784439*I 

  

.. SEEALSO:: :meth:`trim` 

""" 

cdef ComplexBall res = self._new() 

if _do_sig(prec(self)): sig_on() 

acb_set_round(res.value, self.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return res 

  

def accuracy(self): 

""" 

Return the effective relative accuracy of this ball measured in bits. 

  

This is computed as if calling 

:meth:`~sage.rings.real_arb.RealBall.accuracy()` 

on the real ball whose midpoint is the larger out of the real and 

imaginary midpoints of this complex ball, and whose radius is the 

larger out of the real and imaginary radii of this complex ball. 

  

EXAMPLES:: 

  

sage: CBF(exp(I*pi/3)).accuracy() 

52 

sage: CBF(I/2).accuracy() == CBF.base().maximal_accuracy() 

True 

sage: CBF('nan', 'inf').accuracy() == -CBF.base().maximal_accuracy() 

True 

  

.. SEEALSO:: 

  

:meth:`~sage.rings.real_arb.RealBallField.maximal_accuracy` 

""" 

return acb_rel_accuracy_bits(self.value) 

  

def trim(self): 

""" 

Return a trimmed copy of this ball. 

  

Return a copy of this ball with both the real and imaginary parts 

trimmed (see :meth:`~sage.rings.real_arb.RealBall.trim()`). 

  

EXAMPLES:: 

  

sage: b = CBF(1/3, RBF(1/3, rad=.01)) 

sage: b.mid() 

0.333333333333333 + 0.333333333333333*I 

sage: b.trim().mid() 

0.333333333333333 + 0.333333015441895*I 

  

.. SEEALSO:: :meth:`round` 

""" 

cdef ComplexBall res = self._new() 

if _do_sig(prec(self)): sig_on() 

acb_trim(res.value, self.value) 

if _do_sig(prec(self)): sig_off() 

return res 

  

def add_error(self, ampl): 

""" 

Increase the radii of the real and imaginary parts by (an upper bound 

on) ``ampl``. 

  

If ``ampl`` is negative, the radii remain unchanged. 

  

INPUT: 

  

- ``ampl`` - A **real** ball (or an object that can be coerced to a 

real ball). 

  

OUTPUT: 

  

A new complex ball. 

  

EXAMPLES:: 

  

sage: CBF(1+i).add_error(10^-16) 

[1.000000000000000 +/- 1.01e-16] + [1.000000000000000 +/- 1.01e-16]*I 

""" 

return ComplexBall(self._parent, self.real().add_error(ampl), self.imag().add_error(ampl)) 

  

# Comparisons and predicates 

  

def is_NaN(self): 

""" 

Return ``True`` iff either the real or the imaginary part 

is not-a-number. 

  

EXAMPLES:: 

  

sage: CBF(NaN).is_NaN() 

True 

sage: CBF(-5).gamma().is_NaN() 

True 

sage: CBF(oo).is_NaN() 

False 

sage: CBF(42+I).is_NaN() 

False 

""" 

return (arf_is_nan(arb_midref(acb_realref(self.value))) 

or arf_is_nan(arb_midref(acb_imagref(self.value)))) 

  

def is_zero(self): 

""" 

Return ``True`` iff the midpoint and radius of this ball are both zero. 

  

EXAMPLES:: 

  

sage: CBF(0).is_zero() 

True 

sage: CBF(RIF(-0.5, 0.5)).is_zero() 

False 

  

.. SEEALSO:: :meth:`is_nonzero` 

""" 

return acb_is_zero(self.value) 

  

def is_nonzero(self): 

""" 

Return ``True`` iff zero is not contained in the interval represented 

by this ball. 

  

.. NOTE:: 

  

This method is not the negation of :meth:`is_zero`: it only 

returns ``True`` if zero is known not to be contained in the ball. 

  

Use ``bool(b)`` (or, equivalently, ``not b.is_zero()``) to check if 

a ball ``b`` **may** represent a nonzero number (for instance, to 

determine the “degree” of a polynomial with ball coefficients). 

  

EXAMPLES:: 

  

sage: CBF(pi, 1/3).is_nonzero() 

True 

sage: CBF(RIF(-0.5, 0.5), 1/3).is_nonzero() 

True 

sage: CBF(1/3, RIF(-0.5, 0.5)).is_nonzero() 

True 

sage: CBF(RIF(-0.5, 0.5), RIF(-0.5, 0.5)).is_nonzero() 

False 

  

.. SEEALSO:: :meth:`is_zero` 

""" 

return (arb_is_nonzero(acb_realref(self.value)) 

or arb_is_nonzero(acb_imagref(self.value))) 

  

def __nonzero__(self): 

""" 

Return ``True`` iff this complex ball is not the zero ball, i.e. if the 

midpoint and radius of its real and imaginary parts are not all zero. 

  

This is the preferred way, for instance, to determine the “degree” of a 

polynomial with ball coefficients. 

  

.. WARNING:: 

  

A “nonzero” ball in the sense of this method may represent the 

value zero. Use :meth:`is_nonzero` to check that a complex number 

represented by a ``ComplexBall`` object is known to be nonzero. 

  

EXAMPLES:: 

  

sage: bool(CBF(0)) # indirect doctest 

False 

sage: bool(CBF(i)) 

True 

sage: bool(CBF(RIF(-0.5, 0.5))) 

True 

""" 

return not acb_is_zero(self.value) 

  

def is_exact(self): 

""" 

Return ``True`` iff the radius of this ball is zero. 

  

EXAMPLES:: 

  

sage: CBF(1).is_exact() 

True 

sage: CBF(1/3, 1/3).is_exact() 

False 

""" 

return acb_is_exact(self.value) 

  

def is_real(self): 

""" 

Return ``True`` iff the imaginary part of this ball is exactly zero. 

  

EXAMPLES:: 

  

sage: CBF(1/3, 0).is_real() 

True 

sage: (CBF(i/3) - CBF(1, 1/3)).is_real() 

False 

sage: CBF('inf').is_real() 

True 

""" 

return acb_is_real(self.value) 

  

cpdef _richcmp_(left, right, int op): 

""" 

Compare ``left`` and ``right``. 

  

For more information, see :mod:`sage.rings.complex_arb`. 

  

EXAMPLES:: 

  

sage: a = CBF(1) 

sage: b = CBF(1) 

sage: a is b 

False 

sage: a == b 

True 

sage: a = CBF(1/3) 

sage: a.is_exact() 

False 

sage: b = CBF(1/3) 

sage: b.is_exact() 

False 

sage: a == b 

False 

sage: a = CBF(1, 2) 

sage: b = CBF(1, 2) 

sage: a is b 

False 

sage: a == b 

True 

  

TESTS: 

  

Balls whose intersection consists of one point:: 

  

sage: a = CBF(RIF(1, 2), RIF(1, 2)) 

sage: b = CBF(RIF(2, 4), RIF(2, 4)) 

sage: a < b 

Traceback (most recent call last): 

... 

TypeError: No order is defined for ComplexBalls. 

sage: a > b 

Traceback (most recent call last): 

... 

TypeError: No order is defined for ComplexBalls. 

sage: a <= b 

Traceback (most recent call last): 

... 

TypeError: No order is defined for ComplexBalls. 

sage: a >= b 

Traceback (most recent call last): 

... 

TypeError: No order is defined for ComplexBalls. 

sage: a == b 

False 

sage: a != b 

False 

  

Balls with non-trivial intersection:: 

  

sage: a = CBF(RIF(1, 4), RIF(1, 4)) 

sage: a = CBF(RIF(2, 5), RIF(2, 5)) 

sage: a == b 

False 

sage: a != b 

False 

  

One ball contained in another:: 

  

sage: a = CBF(RIF(1, 4), RIF(1, 4)) 

sage: b = CBF(RIF(2, 3), RIF(2, 3)) 

sage: a == b 

False 

sage: a != b 

False 

  

Disjoint balls:: 

  

sage: a = CBF(1/3, 1/3) 

sage: b = CBF(1/5, 1/5) 

sage: a == b 

False 

sage: a != b 

True 

  

Exact elements:: 

  

sage: a = CBF(2, 2) 

sage: b = CBF(2, 2) 

sage: a.is_exact() 

True 

sage: b.is_exact() 

True 

sage: a == b 

True 

sage: a != b 

False 

""" 

cdef ComplexBall lt, rt 

cdef acb_t difference 

  

lt = left 

rt = right 

  

if op == Py_EQ: 

return acb_eq(lt.value, rt.value) 

elif op == Py_NE: 

return acb_ne(lt.value, rt.value) 

elif op == Py_GT or op == Py_GE or op == Py_LT or op == Py_LE: 

raise TypeError("No order is defined for ComplexBalls.") 

  

def identical(self, ComplexBall other): 

""" 

Return whether ``self`` and ``other`` represent the same ball. 

  

INPUT: 

  

- ``other`` -- a :class:`ComplexBall`. 

  

OUTPUT: 

  

Return True iff ``self`` and ``other`` are equal as sets, i.e. if their 

real and imaginary parts each have the same midpoint and radius. 

  

Note that this is not the same thing as testing whether both ``self`` 

and ``other`` certainly represent the complex real number, unless 

either ``self`` or ``other`` is exact (and neither contains NaN). To 

test whether both operands might represent the same mathematical 

quantity, use :meth:`overlaps` or ``in``, depending on the 

circumstance. 

  

EXAMPLES:: 

  

sage: CBF(1, 1/3).identical(1 + CBF(0, 1)/3) 

True 

sage: CBF(1, 1).identical(1 + CBF(0, 1/3)*3) 

False 

""" 

return acb_equal(self.value, other.value) 

  

def overlaps(self, ComplexBall other): 

""" 

Return True iff ``self`` and ``other`` have some point in common. 

  

INPUT: 

  

- ``other`` -- a :class:`ComplexBall`. 

  

EXAMPLES:: 

  

sage: CBF(1, 1).overlaps(1 + CBF(0, 1/3)*3) 

True 

sage: CBF(1, 1).overlaps(CBF(1, 'nan')) 

True 

sage: CBF(1, 1).overlaps(CBF(0, 'nan')) 

False 

""" 

return acb_overlaps(self.value, other.value) 

  

def contains_exact(self, other): 

""" 

Return ``True`` *iff* ``other`` is contained in ``self``. 

  

Use ``other in self`` for a test that works for a wider range of inputs 

but may return false negatives. 

  

INPUT: 

  

- ``other`` -- :class:`ComplexBall`, 

:class:`~sage.rings.integer.Integer`, 

or :class:`~sage.rings.rational.Rational` 

  

EXAMPLES:: 

  

sage: CBF(RealBallField(100)(1/3), 0).contains_exact(1/3) 

True 

sage: CBF(1).contains_exact(1) 

True 

sage: CBF(1).contains_exact(CBF(1)) 

True 

  

sage: CBF(sqrt(2)).contains_exact(sqrt(2)) 

Traceback (most recent call last): 

... 

TypeError: unsupported type: <type 'sage.symbolic.expression.Expression'> 

""" 

cdef fmpz_t tmpz 

cdef fmpq_t tmpq 

if _do_sig(prec(self)): sig_on() 

try: 

if isinstance(other, ComplexBall): 

res = acb_contains(self.value, (<ComplexBall> other).value) 

elif isinstance(other, sage.rings.integer.Integer): 

fmpz_init(tmpz) 

fmpz_set_mpz(tmpz, (<sage.rings.integer.Integer> other).value) 

res = acb_contains_fmpz(self.value, tmpz) 

fmpz_clear(tmpz) 

elif isinstance(other, sage.rings.rational.Rational): 

fmpq_init(tmpq) 

fmpq_set_mpq(tmpq, (<sage.rings.rational.Rational> other).value) 

res = acb_contains_fmpq(self.value, tmpq) 

fmpq_clear(tmpq) 

else: 

raise TypeError("unsupported type: " + str(type(other))) 

finally: 

if _do_sig(prec(self)): sig_off() 

return res 

  

def __contains__(self, other): 

""" 

Return True if ``other`` can be verified to be contained in ``self``. 

  

Depending on the type of ``other``, the test may use interval 

arithmetic with a precision determined by the parent of ``self`` and 

may return false negatives. 

  

EXAMPLES:: 

  

sage: 1/3*i in CBF(0, 1/3) 

True 

  

A false negative:: 

  

sage: RLF(1/3) in CBF(RealBallField(100)(1/3), 0) 

False 

  

.. SEEALSO:: :meth:`contains_exact` 

""" 

if not isinstance(other, ( 

ComplexBall, 

sage.rings.integer.Integer, 

sage.rings.rational.Rational)): 

other = self._parent(other) 

return self.contains_exact(other) 

  

def contains_zero(self): 

""" 

Return ``True`` iff this ball contains zero. 

  

EXAMPLES:: 

  

sage: CBF(0).contains_zero() 

True 

sage: CBF(RIF(-1,1)).contains_zero() 

True 

sage: CBF(i).contains_zero() 

False 

""" 

return acb_contains_zero(self.value) 

  

def contains_integer(self): 

""" 

Return ``True`` iff this ball contains any integer. 

  

EXAMPLES:: 

  

sage: CBF(3, RBF(0.1)).contains_integer() 

False 

sage: CBF(3, RBF(0.1,0.1)).contains_integer() 

True 

""" 

return acb_contains_int(self.value) 

  

# Arithmetic 

  

def __neg__(self): 

""" 

Return the opposite of this ball. 

  

EXAMPLES:: 

  

sage: -CBF(1/3 + I) 

[-0.3333333333333333 +/- 7.04e-17] - 1.000000000000000*I 

""" 

cdef ComplexBall res = self._new() 

acb_neg(res.value, self.value) 

return res 

  

def conjugate(self): 

""" 

Return the complex conjugate of this ball. 

  

EXAMPLES:: 

  

sage: CBF(-2 + I/3).conjugate() 

-2.000000000000000 + [-0.3333333333333333 +/- 7.04e-17]*I 

""" 

cdef ComplexBall res = self._new() 

acb_conj(res.value, self.value) 

return res 

  

cpdef _add_(self, other): 

""" 

Return the sum of two balls, rounded to the ambient field's precision. 

  

The resulting ball is guaranteed to contain the sums of any two points 

of the respective input balls. 

  

EXAMPLES:: 

  

sage: CBF(1) + CBF(I) 

1.000000000000000 + 1.000000000000000*I 

""" 

cdef ComplexBall res = self._new() 

if _do_sig(prec(self)): sig_on() 

acb_add(res.value, self.value, (<ComplexBall> other).value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return res 

  

cpdef _sub_(self, other): 

""" 

Return the difference of two balls, rounded to the ambient field's 

precision. 

  

The resulting ball is guaranteed to contain the differences of any two 

points of the respective input balls. 

  

EXAMPLES:: 

  

sage: CBF(1) - CBF(I) 

1.000000000000000 - 1.000000000000000*I 

""" 

cdef ComplexBall res = self._new() 

if _do_sig(prec(self)): sig_on() 

acb_sub(res.value, self.value, (<ComplexBall> other).value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return res 

  

def __invert__(self): 

""" 

Return the inverse of this ball. 

  

The result is guaranteed to contain the inverse of any point of the 

input ball. 

  

EXAMPLES:: 

  

sage: ~CBF(i/3) 

[-3.00000000000000 +/- 9.44e-16]*I 

sage: ~CBF(0) 

[+/- inf] 

sage: ~CBF(RIF(10,11)) 

[0.1 +/- 9.53e-3] 

""" 

cdef ComplexBall res = self._new() 

if _do_sig(prec(self)): sig_on() 

acb_inv(res.value, self.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return res 

  

cpdef _mul_(self, other): 

""" 

Return the product of two balls, rounded to the ambient field's 

precision. 

  

The resulting ball is guaranteed to contain the products of any two 

points of the respective input balls. 

  

EXAMPLES:: 

  

sage: CBF(-2, 1)*CBF(1, 1/3) 

[-2.333333333333333 +/- 5.37e-16] + [0.333333333333333 +/- 4.82e-16]*I 

""" 

cdef ComplexBall res = self._new() 

if _do_sig(prec(self)): sig_on() 

acb_mul(res.value, self.value, (<ComplexBall> other).value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return res 

  

def __lshift__(val, shift): 

r""" 

If ``val`` is a ``ComplexBall`` and ``shift`` is an integer, return the 

ball obtained by shifting the center and radius of ``val`` to the left 

by ``shift`` bits. 

  

INPUT: 

  

- ``shift`` -- integer, may be negative. 

  

EXAMPLES:: 

  

sage: CBF(i/3) << 2 

[1.333333333333333 +/- 4.82e-16]*I 

sage: CBF(i) << -2 

0.2500000000000000*I 

  

TESTS:: 

  

sage: CBF(i) << (2^65) 

[3.636549880934858e+11106046577046714264 +/- 1.91e+11106046577046714248]*I 

sage: 'a' << CBF(1/3) 

Traceback (most recent call last): 

... 

TypeError: unsupported operand type(s) for <<: 'str' and 

'ComplexBall' 

sage: CBF(1) << 1/2 

Traceback (most recent call last): 

... 

TypeError: shift should be an integer 

""" 

cdef fmpz_t tmpz 

# the ComplexBall might be shift, not val 

if not isinstance(val, ComplexBall): 

raise TypeError("unsupported operand type(s) for <<: '{}' and '{}'" 

.format(type(val).__name__, type(shift).__name__)) 

cdef ComplexBall self = val 

cdef ComplexBall res = self._new() 

if isinstance(shift, int): 

acb_mul_2exp_si(res.value, self.value, PyInt_AS_LONG(shift)) 

elif isinstance(shift, sage.rings.integer.Integer): 

sig_on() 

fmpz_init(tmpz) 

fmpz_set_mpz(tmpz, (<sage.rings.integer.Integer> shift).value) 

acb_mul_2exp_fmpz(res.value, self.value, tmpz) 

fmpz_clear(tmpz) 

sig_off() 

else: 

raise TypeError("shift should be an integer") 

return res 

  

def __rshift__(val, shift): 

r""" 

If ``val`` is a ``ComplexBall`` and ``shift`` is an integer, return the 

ball obtained by shifting the center and radius of ``val`` to the right 

by ``shift`` bits. 

  

INPUT: 

  

- ``shift`` -- integer, may be negative. 

  

EXAMPLES:: 

  

sage: CBF(1+I) >> 2 

0.2500000000000000 + 0.2500000000000000*I 

  

TESTS:: 

  

sage: 'a' >> CBF(1/3) 

Traceback (most recent call last): 

... 

TypeError: unsupported operand type(s) for >>: 'str' and 

'ComplexBall' 

""" 

# the ComplexBall might be shift, not val 

if isinstance(val, ComplexBall): 

return val << (-shift) 

else: 

raise TypeError("unsupported operand type(s) for >>: '{}' and '{}'" 

.format(type(val).__name__, type(shift).__name__)) 

  

cpdef _div_(self, other): 

""" 

Return the quotient of two balls, rounded to the ambient field's 

precision. 

  

The resulting ball is guaranteed to contain the quotients of any two 

points of the respective input balls. 

  

EXAMPLES:: 

  

sage: CBF(-2, 1)/CBF(1, 1/3) 

[-1.500000000000000 +/- 8.83e-16] + [1.500000000000000 +/- 5.64e-16]*I 

sage: CBF(2+I)/CBF(0) 

[+/- inf] + [+/- inf]*I 

sage: CBF(1)/CBF(0) 

[+/- inf] 

sage: CBF(1)/CBF(RBF(0, 1.)) 

nan 

""" 

cdef ComplexBall res = self._new() 

if _do_sig(prec(self)): sig_on() 

acb_div(res.value, self.value, (<ComplexBall> other).value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return res 

  

def __pow__(base, expo, _): 

""" 

EXAMPLES:: 

  

sage: CBF(-1)**(1/2) 

1.000000000000000*I 

sage: CBF(e)**CBF(i*pi) 

[-1.0000000000000 +/- 1.98e-15] + [+/- 2.32e-15]*I 

sage: CBF(0, 1)**AA(2)**(1/2) 

[-0.60569986707881 +/- 4.36e-15] + [0.79569320156748 +/- 2.53e-15]*I 

  

sage: CBF(i)**RBF(2**1000) 

[+/- 2.51] + [+/- 2.87]*I 

sage: CBF(i)**(2**1000) 

1.000000000000000 

  

sage: CBF(0)^(1/3) 

0 

sage: CBF(0)^(-1) 

[+/- inf] 

sage: CBF(0)^(-2) 

[+/- inf] + [+/- inf]*I 

  

TESTS:: 

  

sage: (CBF(e)**CBF(i))**RBF(pi) 

[-1.0000000000000 +/- 5.48e-15] + [+/- 4.14e-15]*I 

sage: CBF(2*i)**10r 

-1024.000000000000 

sage: CBF(1,1) ^ -1r 

0.5000000000000000 - 0.5000000000000000*I 

  

""" 

cdef fmpz_t tmpz 

if not isinstance(base, ComplexBall): 

return sage.structure.element.bin_op(base, expo, operator.pow) 

cdef ComplexBall self = base 

cdef ComplexBall res = self._new() 

if isinstance(expo, int): 

if _do_sig(prec(self)): sig_on() 

acb_pow_si(res.value, self.value, PyInt_AS_LONG(expo), prec(self)) 

if _do_sig(prec(self)): sig_off() 

elif isinstance(expo, sage.rings.integer.Integer): 

if _do_sig(prec(self)): sig_on() 

fmpz_init(tmpz) 

fmpz_set_mpz(tmpz, (<sage.rings.integer.Integer> expo).value) 

acb_pow_fmpz(res.value, self.value, tmpz, prec(self)) 

fmpz_clear(tmpz) 

if _do_sig(prec(self)): sig_off() 

elif isinstance(expo, ComplexBall): 

if _do_sig(prec(self)): sig_on() 

acb_pow(res.value, self.value, (<ComplexBall> expo).value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

elif isinstance(expo, RealBall): 

if _do_sig(prec(self)): sig_on() 

acb_pow_arb(res.value, self.value, (<RealBall> expo).value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

else: 

return sage.structure.element.bin_op(base, expo, operator.pow) 

return res 

  

def sqrt(self): 

""" 

Return the square root of this ball. 

  

If either the real or imaginary part is exactly zero, only a single 

real square root is needed. 

  

EXAMPLES:: 

  

sage: CBF(-2).sqrt() 

[1.414213562373095 +/- 2.99e-16]*I 

""" 

cdef ComplexBall res = self._new() 

if _do_sig(prec(self)): sig_on() 

acb_sqrt(res.value, self.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return res 

  

def rsqrt(self): 

""" 

Return the reciprocal square root of ``self``. 

  

If either the real or imaginary part is exactly zero, only a single 

real reciprocal square root is needed. 

  

EXAMPLES:: 

  

sage: CBF(-2).rsqrt() 

[-0.707106781186547 +/- 5.73e-16]*I 

sage: CBF(0, 1/2).rsqrt() 

1.000000000000000 - 1.000000000000000*I 

sage: CBF(0).rsqrt() 

nan 

""" 

cdef ComplexBall res = self._new() 

if _do_sig(prec(self)): sig_on() 

acb_rsqrt(res.value, self.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return res 

  

def cube(self): 

""" 

Return the cube of this ball. 

  

The result is computed efficiently using two real squarings, two real 

multiplications, and scalar operations. 

  

EXAMPLES:: 

  

sage: CBF(1, 1).cube() 

-2.000000000000000 + 2.000000000000000*I 

""" 

cdef ComplexBall res = self._new() 

if _do_sig(prec(self)): sig_on() 

acb_cube(res.value, self.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return res 

  

def rising_factorial(self, n): 

""" 

Return the ``n``-th rising factorial of this ball. 

  

The `n`-th rising factorial of `x` is equal to `x (x+1) \cdots (x+n-1)`. 

  

For complex `n`, it is a quotient of gamma functions. 

  

EXAMPLES:: 

  

sage: CBF(1).rising_factorial(5) 

120.0000000000000 

sage: CBF(1/3, 1/2).rising_factorial(300) 

[-3.87949484514e+612 +/- 5.23e+600] + [-3.52042209763e+612 +/- 5.55e+600]*I 

  

sage: CBF(1).rising_factorial(-1) 

nan 

sage: CBF(1).rising_factorial(2**64) 

[+/- 2.30e+347382171305201370464] 

sage: ComplexBallField(128)(1).rising_factorial(2**64) 

[2.343691126796861348e+347382171305201285713 +/- 4.71e+347382171305201285694] 

sage: CBF(1/2).rising_factorial(CBF(2,3)) 

[-0.123060451458124 +/- 4.43e-16] + [0.040641263167655 +/- 3.72e-16]*I 

  

""" 

cdef ComplexBall result = self._new() 

cdef ComplexBall my_n = self._parent.coerce(n) 

if _do_sig(prec(self)): sig_on() 

acb_rising(result.value, self.value, my_n.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return result 

  

# Elementary functions 

  

def log(self, base=None): 

""" 

General logarithm (principal branch). 

  

INPUT: 

  

- ``base`` (optional, complex ball or number) -- if ``None``, return 

the principal branch of the natural logarithm ``ln(self)``, 

otherwise, return the general logarithm ``ln(self)/ln(base)`` 

  

EXAMPLES:: 

  

sage: CBF(2*i).log() 

[0.6931471805599453 +/- 4.16e-17] + [1.570796326794897 +/- 6.65e-16]*I 

sage: CBF(-1).log() 

[3.141592653589793 +/- 5.61e-16]*I 

  

sage: CBF(2*i).log(2) 

[1.000000000000000 +/- 8.01e-17] + [2.26618007091360 +/- 4.23e-15]*I 

sage: CBF(2*i).log(CBF(i)) 

[1.000000000000000 +/- 2.83e-16] + [-0.441271200305303 +/- 2.82e-16]*I 

  

sage: CBF('inf').log() 

nan + nan*I 

sage: CBF(2).log(0) 

nan + nan*I 

""" 

cdef ComplexBall cst 

cdef ComplexBall res = self._new() 

if _do_sig(prec(self)): sig_on() 

acb_log(res.value, self.value, prec(self)) 

if base is not None: 

cst = self._parent.coerce(base).log() 

if _do_sig(prec(self)): sig_on() 

acb_div(res.value, res.value, cst.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

if _do_sig(prec(self)): sig_off() 

return res 

  

def log1p(self): 

""" 

Return ``log(1 + self)``, computed accurately when ``self`` is close to 

zero. 

  

EXAMPLES:: 

  

sage: eps = RBF(1e-50) 

sage: CBF(1+eps, eps).log() 

[+/- 2.23e-16] + [1.000000000000000e-50 +/- 2.30e-66]*I 

sage: CBF(eps, eps).log1p() 

[1.000000000000000e-50 +/- 7.63e-68] + [1.00000000000000e-50 +/- 2.30e-66]*I 

""" 

cdef ComplexBall res = self._new() 

if _do_sig(prec(self)): sig_on() 

acb_log1p(res.value, self.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return res 

  

def exp(self): 

""" 

Return the exponential of this ball. 

  

.. SEEALSO:: :meth:`exppii` 

  

EXAMPLES:: 

  

sage: CBF(i*pi).exp() 

[-1.00000000000000 +/- 6.67e-16] + [+/- 5.68e-16]*I 

""" 

cdef ComplexBall res = self._new() 

if _do_sig(prec(self)): sig_on() 

acb_exp(res.value, self.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return res 

  

def exppii(self): 

""" 

Return ``exp(pi*i*self)``. 

  

EXAMPLES:: 

  

sage: CBF(1/2).exppii() 

1.000000000000000*I 

sage: CBF(0, -1/pi).exppii() 

[2.71828182845904 +/- 6.20e-15] 

""" 

cdef ComplexBall res = self._new() 

if _do_sig(prec(self)): sig_on() 

acb_exp_pi_i(res.value, self.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return res 

  

def sin(self): 

""" 

Return the sine of this ball. 

  

EXAMPLES:: 

  

sage: CBF(i*pi).sin() 

[11.5487393572577 +/- 5.34e-14]*I 

""" 

cdef ComplexBall res = self._new() 

if _do_sig(prec(self)): sig_on() 

acb_sin(res.value, self.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return res 

  

def cos(self): 

""" 

Return the cosine of this ball. 

  

EXAMPLES:: 

  

sage: CBF(i*pi).cos() 

[11.59195327552152 +/- 8.38e-15] 

""" 

cdef ComplexBall res = self._new() 

if _do_sig(prec(self)): sig_on() 

acb_cos(res.value, self.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return res 

  

def tan(self): 

""" 

Return the tangent of this ball. 

  

EXAMPLES:: 

  

sage: CBF(pi/2, 1/10).tan() 

[+/- 2.87e-14] + [10.0333111322540 +/- 2.36e-14]*I 

sage: CBF(pi/2).tan() 

[+/- inf] 

""" 

cdef ComplexBall res = self._new() 

if _do_sig(prec(self)): sig_on() 

acb_tan(res.value, self.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return res 

  

def cot(self): 

""" 

Return the cotangent of this ball. 

  

EXAMPLES:: 

  

sage: CBF(pi, 1/10).cot() 

[+/- 5.74e-14] + [-10.0333111322540 +/- 2.81e-14]*I 

sage: CBF(pi).cot() 

[+/- inf] 

""" 

cdef ComplexBall res = self._new() 

if _do_sig(prec(self)): sig_on() 

acb_cot(res.value, self.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return res 

  

def arcsin(self): 

""" 

Return the arcsine of this ball. 

  

EXAMPLES:: 

  

sage: CBF(1+i).arcsin() 

[0.66623943249252 +/- 5.40e-15] + [1.06127506190504 +/- 5.04e-15]*I 

""" 

cdef ComplexBall res = self._new() 

if _do_sig(prec(self)): sig_on() 

acb_asin(res.value, self.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return res 

  

def arccos(self): 

""" 

Return the arccosine of this ball. 

  

EXAMPLES:: 

  

sage: CBF(1+i).arccos() 

[0.90455689430238 +/- 2.18e-15] + [-1.06127506190504 +/- 5.04e-15]*I 

""" 

cdef ComplexBall res = self._new() 

if _do_sig(prec(self)): sig_on() 

acb_acos(res.value, self.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return res 

  

def arctan(self): 

""" 

Return the arctangent of this ball. 

  

EXAMPLES:: 

  

sage: CBF(1+i).arctan() 

[1.017221967897851 +/- 4.93e-16] + [0.4023594781085251 +/- 8.52e-17]*I 

sage: CBF(i).arctan() 

nan + nan*I 

""" 

cdef ComplexBall res = self._new() 

if _do_sig(prec(self)): sig_on() 

acb_atan(res.value, self.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return res 

  

def arcsinh(self): 

""" 

Return the hyperbolic arcsine of this ball. 

  

EXAMPLES:: 

  

sage: CBF(1+i).arcsinh() 

[1.06127506190504 +/- 5.04e-15] + [0.66623943249252 +/- 5.40e-15]*I 

""" 

cdef ComplexBall res = self._new() 

if _do_sig(prec(self)): sig_on() 

acb_asinh(res.value, self.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return res 

  

def arccosh(self): 

""" 

Return the hyperbolic arccosine of this ball. 

  

EXAMPLES:: 

  

sage: CBF(1+i).arccosh() 

[1.061275061905035 +/- 8.44e-16] + [0.904556894302381 +/- 8.22e-16]*I 

""" 

cdef ComplexBall res = self._new() 

if _do_sig(prec(self)): sig_on() 

acb_acosh(res.value, self.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return res 

  

def arctanh(self): 

""" 

Return the hyperbolic arctangent of this ball. 

  

EXAMPLES:: 

  

sage: CBF(1+i).arctanh() 

[0.4023594781085251 +/- 8.52e-17] + [1.017221967897851 +/- 4.93e-16]*I 

""" 

cdef ComplexBall res = self._new() 

if _do_sig(prec(self)): sig_on() 

acb_atanh(res.value, self.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return res 

  

# Special functions 

  

def gamma(self, z=None): 

""" 

Return the image of this ball by the Euler Gamma function (if 

``z = None``) or the incomplete Gamma function (otherwise). 

  

EXAMPLES:: 

  

sage: CBF(1, 1).gamma() 

[0.498015668118356 +/- 9.16e-16] + [-0.154949828301811 +/- 7.08e-16]*I 

sage: CBF(-1).gamma() 

nan 

sage: CBF(1, 1).gamma(0) 

[0.498015668118356 +/- 9.16e-16] + [-0.154949828301811 +/- 7.08e-16]*I 

sage: CBF(1, 1).gamma(100) 

[-3.6143867454139e-45 +/- 6.88e-59] + [-3.7022961377791e-44 +/- 4.41e-58]*I 

sage: CBF(1, 1).gamma(CLF(i)) 

[0.32886684193500 +/- 5.04e-15] + [-0.18974945045621 +/- 1.26e-15]*I 

""" 

cdef ComplexBall my_z 

cdef ComplexBall res = self._new() 

if z is None: 

if _do_sig(prec(self)): sig_on() 

acb_gamma(res.value, self.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

else: 

my_z = self._parent.coerce(z) 

if _do_sig(prec(self)): sig_on() 

acb_hypgeom_gamma_upper(res.value, self.value, my_z.value, 0, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return res 

  

def log_gamma(self): 

r""" 

Return the image of this ball by the logarithmic Gamma function. 

  

The branch cut of the logarithmic gamma function is placed on the 

negative half-axis, which means that 

``log_gamma(z) + log z = log_gamma(z+1)`` holds for all `z`, 

whereas ``log_gamma(z) != log(gamma(z))`` in general. 

  

EXAMPLES:: 

  

sage: CBF(1000, 1000).log_gamma() 

[5466.22252162990 +/- 3.05e-12] + [7039.33429191119 +/- 3.81e-12]*I 

sage: CBF(-1/2).log_gamma() 

[1.265512123484645 +/- 8.82e-16] + [-3.141592653589793 +/- 5.68e-16]*I 

sage: CBF(-1).log_gamma() 

nan + [-3.141592653589793 +/- 5.68e-16]*I 

""" 

cdef ComplexBall res = self._new() 

if _do_sig(prec(self)): sig_on() 

acb_lgamma(res.value, self.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return res 

  

def rgamma(self): 

""" 

Compute the reciprocal gamma function with argument ``self``. 

  

EXAMPLES:: 

  

sage: CBF(6).rgamma() 

[0.00833333333333333 +/- 4.96e-18] 

sage: CBF(-1).rgamma() 

0 

""" 

cdef ComplexBall result = self._new() 

if _do_sig(prec(self)): sig_on() 

acb_rgamma(result.value, self.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return result 

  

def psi(self, n=None): 

""" 

Compute the digamma function with argument ``self``. 

  

If ``n`` is provided, compute the polygamma function of order ``n`` 

and argument ``self``. 

  

EXAMPLES:: 

  

sage: CBF(1, 1).psi() 

[0.0946503206224770 +/- 7.74e-17] + [1.076674047468581 +/- 2.58e-16]*I 

sage: CBF(-1).psi() 

nan 

sage: CBF(1,1).psi(10) 

[56514.8269344249 +/- 4.70e-11] + [56215.1218005823 +/- 5.70e-11]*I 

  

""" 

cdef ComplexBall my_n 

cdef ComplexBall result = self._new() 

if n is None: 

if _do_sig(prec(self)): sig_on() 

acb_digamma(result.value, self.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

else: 

my_n = self._parent.coerce(n) 

if _do_sig(prec(self)): sig_on() 

acb_polygamma(result.value, my_n.value, self.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return result 

  

def zeta(self, a=None): 

""" 

Return the image of this ball by the Hurwitz zeta function. 

  

For ``a = None``, this computes the Riemann zeta function. 

  

EXAMPLES:: 

  

sage: CBF(1, 1).zeta() 

[0.5821580597520036 +/- 5.26e-17] + [-0.9268485643308071 +/- 2.80e-17]*I 

sage: CBF(1, 1).zeta(1) 

[0.5821580597520036 +/- 5.26e-17] + [-0.9268485643308071 +/- 2.80e-17]*I 

sage: CBF(1, 1).zeta(1/2) 

[1.497919876084167 +/- 2.91e-16] + [0.2448655353684164 +/- 4.22e-17]*I 

sage: CBF(1, 1).zeta(CBF(1, 1)) 

[-0.3593983122202835 +/- 3.01e-17] + [-2.875283329756940 +/- 4.52e-16]*I 

sage: CBF(1, 1).zeta(-1) 

nan + nan*I 

""" 

cdef ComplexBall a_ball 

cdef ComplexBall res = self._new() 

if a is None: 

if _do_sig(prec(self)): sig_on() 

acb_zeta(res.value, self.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

else: 

a_ball = self._parent.coerce(a) 

if _do_sig(prec(self)): sig_on() 

acb_hurwitz_zeta(res.value, self.value, a_ball.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return res 

  

def polylog(self, s): 

""" 

Return the polylogarithm `\operatorname{Li}_s(\mathrm{self})`. 

  

EXAMPLES:: 

  

sage: CBF(2).polylog(1) 

[+/- 4.65e-15] + [-3.14159265358979 +/- 8.15e-15]*I 

sage: CBF(1, 1).polylog(CBF(1, 1)) 

[0.3708160030469 +/- 2.38e-14] + [2.7238016577979 +/- 4.20e-14]*I 

  

TESTS:: 

  

sage: CBF(2).polylog(1r) 

[+/- 4.65e-15] + [-3.14159265358979 +/- 8.15e-15]*I 

""" 

cdef ComplexBall s_as_ball 

cdef sage.rings.integer.Integer s_as_Integer 

cdef ComplexBall res = self._new() 

try: 

s_as_Integer = ZZ.coerce(s) 

if mpz_fits_slong_p(s_as_Integer.value): 

if _do_sig(prec(self)): sig_on() 

acb_polylog_si(res.value, mpz_get_si(s_as_Integer.value), self.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return res 

except TypeError: 

pass 

s_as_ball = self._parent.coerce(s) 

if _do_sig(prec(self)): sig_on() 

acb_polylog(res.value, s_as_ball.value, self.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return res 

  

def barnes_g(self): 

""" 

Return the Barnes G-function of ``self``. 

  

EXAMPLES:: 

  

sage: CBF(-4).barnes_g() 

0 

sage: CBF(8).barnes_g() 

24883200.00000000 

sage: CBF(500,10).barnes_g() 

[4.54078781e+254873 +/- 5.43e+254864] + [8.65835455e+254873 +/- 7.28e+254864]*I 

""" 

cdef ComplexBall res = self._new() 

if _do_sig(prec(self)): sig_on() 

acb_barnes_g(res.value, self.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return res 

  

def log_barnes_g(self): 

""" 

Return the logarithmic Barnes G-function of ``self``. 

  

EXAMPLES:: 

  

sage: CBF(10^100).log_barnes_g() 

[1.14379254649702e+202 +/- 4.09e+187] 

sage: CBF(0,1000).log_barnes_g() 

[-2702305.04929258 +/- 2.60e-9] + [-790386.325561423 +/- 9.72e-10]*I 

""" 

cdef ComplexBall res = self._new() 

if _do_sig(prec(self)): sig_on() 

acb_log_barnes_g(res.value, self.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return res 

  

def agm1(self): 

""" 

Return the arithmetic-geometric mean of 1 and ``self``. 

  

The arithmetic-geometric mean is defined such that the function is 

continuous in the complex plane except for a branch cut along the 

negative half axis (where it is continuous from above). This 

corresponds to always choosing an "optimal" branch for the square root 

in the arithmetic-geometric mean iteration. 

  

EXAMPLES:: 

  

sage: CBF(0, -1).agm1() 

[0.599070117367796 +/- 3.9...e-16] + [-0.599070117367796 +/- 5.5...e-16]*I 

""" 

cdef ComplexBall res = self._new() 

if _do_sig(prec(self)): sig_on() 

acb_agm1(res.value, self.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return res 

  

def hypergeometric(self, a, b, bint regularized=False): 

r""" 

Return the generalized hypergeometric function of ``self``. 

  

INPUT: 

  

- ``a`` -- upper parameters, list of complex numbers that coerce into 

this ball's parent; 

  

- ``b`` -- lower parameters, list of complex numbers that coerce into 

this ball's parent. 

  

- ``regularized`` -- if True, the regularized generalized hypergeometric 

function is computed. 

  

OUTPUT: 

  

The generalized hypergeometric function defined by 

  

.. MATH:: 

  

{}_pF_q(a_1,\ldots,a_p;b_1,\ldots,b_q;z) 

= \sum_{k=0}^\infty \frac{(a_1)_k\dots(a_p)_k}{(b_1)_k\dots(b_q)_k} \frac {z^k} {k!} 

  

extended using analytic continuation or regularization when the sum 

does not converge. 

  

The regularized generalized hypergeometric function 

  

.. MATH:: 

  

{}_pF_q(a_1,\ldots,a_p;b_1,\ldots,b_q;z) 

= \sum_{k=0}^\infty \frac{(a_1)_k\dots(a_p)_k}{\Gamma(b_1+k)\dots\Gamma(b_q+k)} \frac {z^k} {k!} 

  

is well-defined even when the lower parameters are nonpositive 

integers. Currently, this is only supported for some `p` and `q`. 

  

EXAMPLES:: 

  

sage: CBF(1, pi/2).hypergeometric([], []) 

[+/- 7.72e-16] + [2.71828182845904 +/- 6.45e-15]*I 

  

sage: CBF(1, pi).hypergeometric([1/4], [1/4]) 

[-2.7182818284590 +/- 7.11e-14] + [+/- 2.25e-14]*I 

  

sage: CBF(1000, 1000).hypergeometric([10], [AA(sqrt(2))]) 

[9.79300951360e+454 +/- 5.01e+442] + [5.522579106816e+455 +/- 3.56e+442]*I 

sage: CBF(1000, 1000).hypergeometric([100], [AA(sqrt(2))]) 

[1.27967355557e+590 +/- 8.60e+578] + [-9.32333491987e+590 +/- 8.18e+578]*I 

  

sage: CBF(0, 1).hypergeometric([], [1/2, 1/3, 1/4]) 

[-3.7991962344383 +/- 8.78e-14] + [23.878097177805 +/- 3.87e-13]*I 

  

sage: CBF(0).hypergeometric([1], []) 

1.000000000000000 

sage: CBF(1, 1).hypergeometric([1], []) 

1.000000000000000*I 

  

sage: CBF(2+3*I).hypergeometric([1/4,1/3],[1/2]) 

[0.7871684267473 +/- 7.34e-14] + [0.2749254173721 +/- 9.23e-14]*I 

sage: CBF(2+3*I).hypergeometric([1/4,1/3],[1/2],regularized=True) 

[0.4441122268685 +/- 3.96e-14] + [0.1551100567338 +/- 5.75e-14]*I 

  

sage: CBF(5).hypergeometric([2,3], [-5]) 

nan + nan*I 

sage: CBF(5).hypergeometric([2,3], [-5], regularized=True) 

[5106.925964355 +/- 5.41e-10] 

  

sage: CBF(2016).hypergeometric([], [2/3]) 

[2.025642692328e+38 +/- 3.00e+25] 

sage: CBF(-2016).hypergeometric([], [2/3], regularized=True) 

[-0.0005428550847 +/- 5.00e-14] 

  

sage: CBF(-7).hypergeometric([4], []) 

0.0002441406250000000 

  

sage: CBF(0, 3).hypergeometric([CBF(1,1)], [-4], regularized=True) 

[239.514000752841 +/- 8.03e-13] + [105.175157349015 +/- 6.28e-13]*I 

  

TESTS:: 

  

sage: CBF(0, 1).hypergeometric([QQbar(sqrt(2)), RLF(pi)], [1r, 1/2]) 

[-8.7029449215408 +/- 6.17e-14] + [-0.8499070546106 +/- 5.21e-14]*I 

  

""" 

cdef ComplexBall tmp, my_a, my_b, my_c 

cdef ComplexBall res = self._new() 

cdef long p = len(a) 

cdef long q = len(b) 

if p == q == 0: 

return self.exp() 

if p == 1 and q == 0: 

my_a = self._parent.coerce(a[0]) 

return (1-self)**(-my_a) 

if p == 0 and q == 1: 

my_b = self._parent.coerce(b[0]) 

if _do_sig(prec(self)): sig_on() 

acb_hypgeom_0f1(res.value, my_b.value, self.value, 

regularized, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return res 

if p == q == 1: 

my_a = self._parent.coerce(a[0]) 

my_b = self._parent.coerce(b[0]) 

if _do_sig(prec(self)): sig_on() 

acb_hypgeom_m(res.value, my_a.value, my_b.value, self.value, 

regularized, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return res 

if p == 2 and q == 1: 

my_a = self._parent.coerce(a[0]) 

my_b = self._parent.coerce(a[1]) 

my_c = self._parent.coerce(b[0]) 

if _do_sig(prec(self)): sig_on() 

acb_hypgeom_2f1(res.value, my_a.value, my_b.value, my_c.value, 

self.value, regularized, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return res 

if regularized: 

raise NotImplementedError("regularized=True not yet supported in this case") 

cdef long i1 = -1 

cdef long s 

try: 

i1 = a.index(1) 

s = 1 

except ValueError: 

s = 0 

cdef acb_ptr vec_a = _acb_vec_init(p - s) 

cdef acb_ptr vec_b = _acb_vec_init(q + 1 - s) 

cdef long j = 0 

for i in xrange(p): 

if i != i1: 

tmp = self._parent.coerce(a[i]) 

acb_set(&(vec_a[j]), tmp.value) 

j += 1 

for i in range(q): 

tmp = self._parent.coerce(b[i]) 

acb_set(&(vec_b[i]), tmp.value) 

if s == 0: 

acb_one(&(vec_b[q])) 

if _do_sig(prec(self)): sig_on() 

acb_hypgeom_pfq_direct(res.value, vec_a, p - s, vec_b, q + 1 - s, 

self.value, -1, prec(self)) 

if _do_sig(prec(self)): sig_off() 

_acb_vec_clear(vec_b, q + 1 - s) 

_acb_vec_clear(vec_a, p - s) 

return res 

  

def hypergeometric_U(self, a, b): 

""" 

Return the Tricomi confluent hypergeometric function U(a, b, self) of 

this ball. 

  

EXAMPLES:: 

  

sage: CBF(1000, 1000).hypergeometric_U(RLF(pi), -100) 

[-7.261605907166e-11 +/- 5.04e-24] + [-7.928136216391e-11 +/- 5.52e-24]*I 

sage: CBF(1000, 1000).hypergeometric_U(0, -100) 

1.000000000000000 

""" 

cdef ComplexBall res = self._new() 

cdef ComplexBall my_a = self._parent.coerce(a) 

cdef ComplexBall my_b = self._parent.coerce(b) 

if _do_sig(prec(self)): sig_on() 

acb_hypgeom_u(res.value, my_a.value, my_b.value, self.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return res 

  

def erf(self): 

""" 

Return the error function with argument ``self``. 

  

EXAMPLES:: 

  

sage: CBF(1, 1).erf() 

[1.316151281697947 +/- 7.26e-16] + [0.1904534692378347 +/- 6.03e-17]*I 

""" 

  

cdef ComplexBall result = self._new() 

if _do_sig(prec(self)): sig_on() 

acb_hypgeom_erf(result.value, self.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return result 

  

def erfc(self): 

""" 

Compute the complementary error function with argument ``self``. 

  

EXAMPLES:: 

  

sage: CBF(20).erfc() 

[5.39586561160790e-176 +/- 6.73e-191] 

sage: CBF(100, 100).erfc() 

[0.00065234366376858 +/- 8.37e-18] + [-0.00393572636292141 +/- 7.21e-18]*I 

""" 

cdef ComplexBall result = self._new() 

if _do_sig(prec(self)): sig_on() 

acb_hypgeom_erfc(result.value, self.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return result 

  

def airy(self): 

""" 

Return the Airy functions Ai, Ai', Bi, Bi' with argument ``self``, 

evaluated simultaneously. 

  

EXAMPLES:: 

  

sage: CBF(10*pi).airy() 

([1.2408955946101e-52 +/- 5.50e-66], 

[-6.965048886977e-52 +/- 5.23e-65], 

[2.288295683344e+50 +/- 5.10e+37], 

[1.2807602335816e+51 +/- 4.97e+37]) 

sage: ai, aip, bi, bip = CBF(1,2).airy() 

sage: (ai * bip - bi * aip) * CBF(pi) 

[1.0000000000000 +/- 1.25e-15] + [+/- 3.27e-16]*I 

  

""" 

cdef ComplexBall ai = self._new() 

cdef ComplexBall aip = self._new() 

cdef ComplexBall bi = self._new() 

cdef ComplexBall bip = self._new() 

if _do_sig(prec(self)): sig_on() 

acb_hypgeom_airy(ai.value, aip.value, bi.value, bip.value, self.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return (ai, aip, bi, bip) 

  

def airy_ai(self): 

""" 

Return the Airy function Ai with argument ``self``. 

  

EXAMPLES:: 

  

sage: CBF(1,2).airy_ai() 

[-0.2193862549814276 +/- 7.47e-17] + [-0.1753859114081094 +/- 4.06e-17]*I 

""" 

cdef ComplexBall result = self._new() 

if _do_sig(prec(self)): sig_on() 

acb_hypgeom_airy(result.value, NULL, NULL, NULL, self.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return result 

  

def airy_ai_prime(self): 

""" 

Return the Airy function derivative Ai' with argument ``self``. 

  

EXAMPLES:: 

  

sage: CBF(1,2).airy_ai_prime() 

[0.1704449781789148 +/- 3.12e-17] + [0.387622439413295 +/- 1.06e-16]*I 

""" 

cdef ComplexBall result = self._new() 

if _do_sig(prec(self)): sig_on() 

acb_hypgeom_airy(NULL, result.value, NULL, NULL, self.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return result 

  

def airy_bi(self): 

""" 

Return the Airy function Bi with argument ``self``. 

  

EXAMPLES:: 

  

sage: CBF(1,2).airy_bi() 

[0.0488220324530612 +/- 1.30e-17] + [0.1332740579917484 +/- 6.25e-17]*I 

""" 

cdef ComplexBall result = self._new() 

if _do_sig(prec(self)): sig_on() 

acb_hypgeom_airy(NULL, NULL, result.value, NULL, self.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return result 

  

def airy_bi_prime(self): 

""" 

Return the Airy function derivative Bi' with argument ``self``. 

  

EXAMPLES:: 

  

sage: CBF(1,2).airy_bi_prime() 

[-0.857239258605362 +/- 3.47e-16] + [0.4955063363095674 +/- 9.22e-17]*I 

""" 

cdef ComplexBall result = self._new() 

if _do_sig(prec(self)): sig_on() 

acb_hypgeom_airy(NULL, NULL, NULL, result.value, self.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return result 

  

def bessel_J(self, nu): 

""" 

Return the Bessel function of the first kind with argument ``self`` 

and index ``nu``. 

  

EXAMPLES:: 

  

sage: CBF(1, 1).bessel_J(1) 

[0.614160334922903 +/- 6.38e-16] + [0.365028028827088 +/- 3.96e-16]*I 

sage: CBF(100, -100).bessel_J(1/3) 

[1.108431870251e+41 +/- 5.53e+28] + [-8.952577603125e+41 +/- 2.93e+28]*I 

""" 

cdef ComplexBall result = self._new() 

cdef ComplexBall my_nu = self._parent.coerce(nu) 

if _do_sig(prec(self)): sig_on() 

acb_hypgeom_bessel_j(result.value, my_nu.value, self.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return result 

  

def bessel_J_Y(self, nu): 

""" 

Return the Bessel function of the first and second kind with argument 

``self`` and index ``nu``, computed simultaneously. 

  

EXAMPLES:: 

  

sage: J, Y = CBF(1, 1).bessel_J_Y(1) 

sage: J - CBF(1, 1).bessel_J(1) 

[+/- 3.75e-16] + [+/- 2.64e-16]*I 

sage: Y - CBF(1, 1).bessel_Y(1) 

[+/- 1.64e-14] + [+/- 1.62e-14]*I 

  

""" 

cdef ComplexBall result1 = self._new() 

cdef ComplexBall result2 = self._new() 

cdef ComplexBall my_nu = self._parent.coerce(nu) 

if _do_sig(prec(self)): sig_on() 

acb_hypgeom_bessel_jy(result1.value, result2.value, 

my_nu.value, self.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return result1, result2 

  

def bessel_Y(self, nu): 

""" 

Return the Bessel function of the second kind with argument ``self`` 

and index ``nu``. 

  

EXAMPLES:: 

  

sage: CBF(1, 1).bessel_Y(1) 

[-0.6576945355913 +/- 5.29e-14] + [0.6298010039929 +/- 2.45e-14]*I 

sage: CBF(100, -100).bessel_Y(1/3) 

[-8.952577603125e+41 +/- 4.66e+28] + [-1.108431870251e+41 +/- 6.31e+28]*I 

""" 

cdef ComplexBall result = self._new() 

cdef ComplexBall my_nu = self._parent.coerce(nu) 

if _do_sig(prec(self)): sig_on() 

acb_hypgeom_bessel_y(result.value, my_nu.value, self.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return result 

  

def bessel_I(self, nu): 

""" 

Return the modified Bessel function of the first kind with argument ``self`` 

and index ``nu``. 

  

EXAMPLES:: 

  

sage: CBF(1, 1).bessel_I(1) 

[0.365028028827088 +/- 3.96e-16] + [0.614160334922903 +/- 6.38e-16]*I 

sage: CBF(100, -100).bessel_I(1/3) 

[5.4362189595644e+41 +/- 6.40e+27] + [7.1989436985321e+41 +/- 2.92e+27]*I 

""" 

cdef ComplexBall result = self._new() 

cdef ComplexBall my_nu = self._parent.coerce(nu) 

if _do_sig(prec(self)): sig_on() 

acb_hypgeom_bessel_i(result.value, my_nu.value, self.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return result 

  

def bessel_K(self, nu): 

""" 

Return the modified Bessel function of the second kind with argument 

``self`` and index ``nu``. 

  

EXAMPLES:: 

  

sage: CBF(1, 1).bessel_K(0) 

[0.08019772694652 +/- 3.19e-15] + [-0.35727745928533 +/- 1.08e-15]*I 

sage: CBF(1, 1).bessel_K(1) 

[0.02456830552374 +/- 4.84e-15] + [-0.45971947380119 +/- 5.35e-15]*I 

sage: CBF(100, 100).bessel_K(QQbar(i)) 

[3.8693896656383e-45 +/- 2.76e-59] + [5.507100423418e-46 +/- 4.01e-59]*I 

""" 

cdef ComplexBall result = self._new() 

cdef ComplexBall my_nu = self._parent.coerce(nu) 

if _do_sig(prec(self)): sig_on() 

acb_hypgeom_bessel_k(result.value, my_nu.value, self.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return result 

  

def exp_integral_e(self, s): 

""" 

Return the image of this ball by the generalized exponential integral 

with index ``s``. 

  

EXAMPLES:: 

  

sage: CBF(1+i).exp_integral_e(1) 

[0.00028162445198 +/- 2.79e-15] + [-0.17932453503936 +/- 2.12e-15]*I 

sage: CBF(1+i).exp_integral_e(QQbar(i)) 

[-0.10396361883964 +/- 3.78e-15] + [-0.16268401277783 +/- 3.69e-15]*I 

""" 

cdef ComplexBall res = self._new() 

cdef ComplexBall my_s = self._parent.coerce(s) 

if _do_sig(prec(self)): sig_on() 

acb_hypgeom_expint(res.value, my_s.value, self.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return res 

  

def ei(self): 

""" 

Return the exponential integral with argument ``self``. 

  

EXAMPLES:: 

  

sage: CBF(1, 1).ei() 

[1.76462598556385 +/- 5.82e-15] + [2.38776985151052 +/- 4.29e-15]*I 

sage: CBF(0).ei() 

nan 

""" 

cdef ComplexBall result = self._new() 

if _do_sig(prec(self)): sig_on() 

acb_hypgeom_ei(result.value, self.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return result 

  

def si(self): 

""" 

Return the sine integral with argument ``self``. 

  

EXAMPLES:: 

  

sage: CBF(1, 1).si() 

[1.10422265823558 +/- 2.48e-15] + [0.88245380500792 +/- 3.36e-15]*I 

sage: CBF(0).si() 

0 

""" 

cdef ComplexBall result = self._new() 

if _do_sig(prec(self)): sig_on() 

acb_hypgeom_si(result.value, self.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return result 

  

def ci(self): 

""" 

Return the cosine integral with argument ``self``. 

  

EXAMPLES:: 

  

sage: CBF(1, 1).ci() 

[0.882172180555936 +/- 4.85e-16] + [0.287249133519956 +/- 3.92e-16]*I 

sage: CBF(0).ci() 

nan + nan*I 

""" 

cdef ComplexBall result = self._new() 

if _do_sig(prec(self)): sig_on() 

acb_hypgeom_ci(result.value, self.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return result 

  

def shi(self): 

""" 

Return the hyperbolic sine integral with argument ``self``. 

  

EXAMPLES:: 

  

sage: CBF(1, 1).shi() 

[0.88245380500792 +/- 3.36e-15] + [1.10422265823558 +/- 2.48e-15]*I 

sage: CBF(0).shi() 

0 

""" 

  

cdef ComplexBall result = self._new() 

if _do_sig(prec(self)): sig_on() 

acb_hypgeom_shi(result.value, self.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return result 

  

def chi(self): 

""" 

Return the hyperbolic cosine integral with argument ``self``. 

  

EXAMPLES:: 

  

sage: CBF(1, 1).chi() 

[0.882172180555936 +/- 4.85e-16] + [1.28354719327494 +/- 1.07e-15]*I 

sage: CBF(0).chi() 

nan + nan*I 

""" 

cdef ComplexBall result = self._new() 

if _do_sig(prec(self)): sig_on() 

acb_hypgeom_chi(result.value, self.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return result 

  

def li(self, bint offset=False): 

""" 

Return the logarithmic integral with argument ``self``. 

  

If ``offset`` is True, return the offset logarithmic integral. 

  

EXAMPLES:: 

  

sage: CBF(1, 1).li() 

[0.61391166922120 +/- 6.40e-15] + [2.05958421419258 +/- 5.61e-15]*I 

sage: CBF(0).li() 

0 

sage: CBF(0).li(offset=True) 

[-1.045163780117493 +/- 5.54e-16] 

sage: li(0).n() 

0.000000000000000 

sage: Li(0).n() 

-1.04516378011749 

""" 

cdef ComplexBall result = self._new() 

if _do_sig(prec(self)): sig_on() 

acb_hypgeom_li(result.value, self.value, offset, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return result 

  

def jacobi_theta(self, tau): 

r""" 

Return the four Jacobi theta functions evaluated at the argument 

``self`` (representing `z`) and the parameter ``tau`` which should lie 

in the upper half plane. 

  

The following definitions are used: 

  

.. MATH:: 

  

\theta_1(z,\tau) = 2 q_{1/4} \sum_{n=0}^{\infty} (-1)^n q^{n(n+1)} \sin((2n+1) \pi z) 

  

\theta_2(z,\tau) = 2 q_{1/4} \sum_{n=0}^{\infty} q^{n(n+1)} \cos((2n+1) \pi z) 

  

\theta_3(z,\tau) = 1 + 2 \sum_{n=1}^{\infty} q^{n^2} \cos(2n \pi z) 

  

\theta_4(z,\tau) = 1 + 2 \sum_{n=1}^{\infty} (-1)^n q^{n^2} \cos(2n \pi z) 

  

where `q = \exp(\pi i \tau)` and `q_{1/4} = \exp(\pi i \tau / 4)`. 

Note that `z` is multiplied by `\pi`; some authors omit this factor. 

  

EXAMPLES:: 

  

sage: CBF(3,-1/2).jacobi_theta(CBF(1/4,2)) 

([-0.186580562274757 +/- 5.52e-16] + [0.93841744788594 +/- 2.48e-15]*I, 

[-1.02315311037951 +/- 4.10e-15] + [-0.203600094532010 +/- 7.33e-16]*I, 

[1.030613911309632 +/- 4.25e-16] + [0.030613917822067 +/- 1.89e-16]*I, 

[0.969386075665498 +/- 4.65e-16] + [-0.030613917822067 +/- 1.89e-16]*I) 

  

sage: CBF(3,-1/2).jacobi_theta(CBF(1/4,-2)) 

(nan + nan*I, nan + nan*I, nan + nan*I, nan + nan*I) 

  

sage: CBF(0).jacobi_theta(CBF(0,1)) 

(0, 

[0.91357913815612 +/- 3.96e-15], 

[1.086434811213308 +/- 8.16e-16], 

[0.913579138156117 +/- 8.89e-16]) 

  

""" 

  

cdef ComplexBall res1 = self._new() 

cdef ComplexBall res2 = self._new() 

cdef ComplexBall res3 = self._new() 

cdef ComplexBall res4 = self._new() 

cdef ComplexBall my_tau = self._parent.coerce(tau) 

if _do_sig(prec(self)): sig_on() 

acb_modular_theta(res1.value, res2.value, res3.value, res4.value, 

self.value, my_tau.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return res1, res2, res3, res4 

  

def modular_j(self): 

""" 

Return the modular j-invariant with *tau* given by ``self``. 

  

EXAMPLES:: 

  

sage: CBF(0,1).modular_j() 

[1728.0000000000 +/- 5.33e-11] 

  

""" 

cdef ComplexBall result = self._new() 

if _do_sig(prec(self)): sig_on() 

acb_modular_j(result.value, self.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return result 

  

def modular_eta(self): 

""" 

Return the Dedekind eta function with *tau* given by ``self``. 

  

EXAMPLES:: 

  

sage: CBF(0,1).modular_eta() 

[0.768225422326057 +/- 9.18e-16] 

sage: CBF(12,1).modular_eta() 

[-0.768225422326057 +/- 9.18e-16] 

  

""" 

cdef ComplexBall result = self._new() 

if _do_sig(prec(self)): sig_on() 

acb_modular_eta(result.value, self.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return result 

  

def modular_lambda(self): 

""" 

Return the modular lambda function with *tau* given by ``self``. 

  

EXAMPLES:: 

  

sage: tau = CBF(sqrt(2),pi) 

sage: tau.modular_lambda() 

[-0.00022005123884157 +/- 6.41e-18] + [-0.0007978734645994 +/- 5.15e-17]*I 

sage: (tau + 2).modular_lambda() 

[-0.00022005123884157 +/- 6.41e-18] + [-0.0007978734645994 +/- 5.15e-17]*I 

sage: (tau / (1 - 2*tau)).modular_lambda() 

[-0.00022005123884 +/- 2.53e-15] + [-0.00079787346460 +/- 2.85e-15]*I 

  

""" 

cdef ComplexBall result = self._new() 

if _do_sig(prec(self)): sig_on() 

acb_modular_lambda(result.value, self.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return result 

  

def modular_delta(self): 

""" 

Return the modular discriminant with *tau* given by ``self``. 

  

EXAMPLES:: 

  

sage: CBF(0,1).modular_delta() 

[0.0017853698506421 +/- 6.15e-17] 

sage: a, b, c, d = 2, 5, 1, 3 

sage: tau = CBF(1,3) 

sage: ((a*tau+b)/(c*tau+d)).modular_delta() 

[0.20921376655 +/- 6.94e-12] + [1.5761192552 +/- 3.47e-11]*I 

sage: (c*tau+d)^12 * tau.modular_delta() 

[0.20921376654986 +/- 4.89e-15] + [1.5761192552253 +/- 4.45e-14]*I 

  

""" 

cdef ComplexBall result = self._new() 

if _do_sig(prec(self)): sig_on() 

acb_modular_delta(result.value, self.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return result 

  

def eisenstein(self, long n): 

r""" 

Return the first ``n`` entries in the sequence of Eisenstein series 

`G_4(\tau), G_6(\tau), G_8(\tau), \ldots` where *tau* is given 

by ``self``. The output is a list. 

  

EXAMPLES:: 

  

sage: a, b, c, d = 2, 5, 1, 3 

sage: tau = CBF(1,3) 

sage: tau.eisenstein(4) 

[[2.1646498507193 +/- 6.30e-14], 

[2.0346794456073 +/- 2.44e-14], 

[2.0081609898081 +/- 3.67e-14], 

[2.0019857082706 +/- 4.60e-14]] 

sage: ((a*tau+b)/(c*tau+d)).eisenstein(3)[2] 

[331011.2004330 +/- 9.33e-8] + [-711178.1655746 +/- 7.51e-8]*I 

sage: (c*tau+d)^8 * tau.eisenstein(3)[2] 

[331011.20043304 +/- 7.62e-9] + [-711178.1655746 +/- 1.34e-8]*I 

  

""" 

if n < 0: 

raise ValueError("n must be nonnegative") 

cdef acb_ptr vec_r = _acb_vec_init(n) 

if _do_sig(prec(self)): sig_on() 

acb_modular_eisenstein(vec_r, self.value, n, prec(self)) 

if _do_sig(prec(self)): sig_off() 

result = [self._new() for i in range(n)] 

for i in range(n): 

acb_swap((<ComplexBall>(result[i])).value, &(vec_r[i])) 

_acb_vec_clear(vec_r, n) 

return result 

  

def elliptic_p(self, tau, n=None): 

r""" 

Return the Weierstrass elliptic function with lattice parameter ``tau``, 

evaluated at ``self``. The function is doubly periodic in ``self`` 

with periods 1 and ``tau``, which should lie in the upper half plane. 

  

If ``n`` is given, return a list containing the first ``n`` 

terms in the Taylor expansion at ``self``. In particular, with 

``n`` = 2, compute the Weierstrass elliptic function together 

with its derivative, which generate the field of elliptic 

functions with periods 1 and ``tau``. 

  

EXAMPLES:: 

  

sage: tau = CBF(1,4) 

sage: z = CBF(sqrt(2), sqrt(3)) 

sage: z.elliptic_p(tau) 

[-3.28920996772709 +/- 7.63e-15] + [-0.0003673767302933 +/- 6.04e-17]*I 

sage: (z + tau).elliptic_p(tau) 

[-3.28920996772709 +/- 7.97e-15] + [-0.000367376730293 +/- 6.51e-16]*I 

sage: (z + 1).elliptic_p(tau) 

[-3.28920996772709 +/- 7.63e-15] + [-0.0003673767302933 +/- 6.04e-17]*I 

  

sage: z.elliptic_p(tau, 3) 

[[-3.28920996772709 +/- 7.62e-15] + [-0.0003673767302933 +/- 5.40e-17]*I, 

[0.002473055794309 +/- 5.01e-16] + [0.003859554040267 +/- 4.45e-16]*I, 

[-0.01299087561709 +/- 4.72e-15] + [0.00725027521915 +/- 4.32e-15]*I] 

sage: (z + 3 + 4*tau).elliptic_p(tau, 3) 

[[-3.28920996772709 +/- 8.4...e-15] + [-0.00036737673029 +/- 4.1...e-15]*I, 

[0.0024730557943 +/- 6.6...e-14] + [0.0038595540403 +/- 8.8...e-14]*I, 

[-0.01299087562 +/- 5.6...e-12] + [0.00725027522 +/- 3.5...e-12]*I] 

  

""" 

cdef ComplexBall my_tau = self._parent.coerce(tau) 

cdef ComplexBall result 

cdef long nn 

cdef acb_ptr vec_r 

if n is None: 

result = self._new() 

if _do_sig(prec(self)): sig_on() 

acb_elliptic_p(result.value, self.value, 

my_tau.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return result 

else: 

nn = n 

if nn < 0: 

raise ValueError("n must be nonnegative") 

vec_r = _acb_vec_init(nn) 

if _do_sig(prec(self)): sig_on() 

acb_modular_elliptic_p_zpx(vec_r, self.value, my_tau.value, nn, prec(self)) 

if _do_sig(prec(self)): sig_off() 

result_list = [self._new() for i in range(nn)] 

for i in range(nn): 

acb_swap((<ComplexBall>(result_list[i])).value, &(vec_r[i])) 

_acb_vec_clear(vec_r, nn) 

return result_list 

  

def elliptic_invariants(self): 

r""" 

Return the lattice invariants ``(g2, g3)``. 

  

EXAMPLES:: 

  

sage: CBF(0,1).elliptic_invariants() 

([189.07272012923 +/- 4.43e-12], [+/- 6.48e-12]) 

sage: CBF(sqrt(2)/2, sqrt(2)/2).elliptic_invariants() 

([+/- 5.32e-12] + [-332.5338031465 +/- 5.03e-11]*I, 

[1254.4684215774 +/- 9.65e-11] + [1254.468421577 +/- 4.96e-10]*I) 

""" 

cdef ComplexBall g2 = self._new() 

cdef ComplexBall g3 = self._new() 

if _do_sig(prec(self)): sig_on() 

acb_elliptic_invariants(g2.value, g3.value, self.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return (g2, g3) 

  

def elliptic_roots(self): 

r""" 

Return the lattice roots ``(e1, e2, e3)`` of `4 z^3 - g_2 z - g_3`. 

  

EXAMPLES:: 

  

sage: e1, e2, e3 = CBF(0,1).elliptic_roots() 

sage: e1, e2, e3 

([6.8751858180204 +/- 6.18e-14], 

[+/- 1.20e-14], 

[-6.8751858180204 +/- 6.24e-14]) 

sage: g2, g3 = CBF(0,1).elliptic_invariants() 

sage: 4 * e1^3 - g2 * e1 - g3 

[+/- 3.36e-11] 

""" 

cdef ComplexBall e1 = self._new() 

cdef ComplexBall e2 = self._new() 

cdef ComplexBall e3 = self._new() 

if _do_sig(prec(self)): sig_on() 

acb_elliptic_roots(e1.value, e2.value, e3.value, self.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return (e1, e2, e3) 

  

def elliptic_k(self): 

""" 

Return the complete elliptic integral of the first kind evaluated 

at *m* given by ``self``. 

  

EXAMPLES:: 

  

sage: CBF(2,3).elliptic_k() 

[1.04291329192852 +/- 5.9...e-15] + [0.62968247230864 +/- 3.4...e-15]*I 

  

""" 

cdef ComplexBall result = self._new() 

if _do_sig(prec(self)): sig_on() 

acb_elliptic_k(result.value, self.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return result 

  

def elliptic_e(self): 

""" 

Return the complete elliptic integral of the second kind evaluated 

at *m* given by ``self``. 

  

EXAMPLES:: 

  

sage: CBF(2,3).elliptic_e() 

[1.472797144959 +/- 4.5...e-13] + [-1.231604783936 +/- 9.5...e-14]*I 

  

""" 

cdef ComplexBall result = self._new() 

if _do_sig(prec(self)): sig_on() 

acb_elliptic_e(result.value, self.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return result 

  

def elliptic_pi(self, m): 

""" 

Return the complete elliptic integral of the third kind evaluated 

at *m* given by ``self``. 

  

EXAMPLES:: 

  

sage: CBF(2,3).elliptic_pi(CBF(1,1)) 

[0.27029997361983 +/- 1.31e-15] + [0.715676058329095 +/- 5.66e-16]*I 

  

""" 

cdef ComplexBall result = self._new() 

cdef ComplexBall my_m = self._parent.coerce(m) 

if _do_sig(prec(self)): sig_on() 

acb_elliptic_pi(result.value, self.value, my_m.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return result 

  

def elliptic_f(self, m): 

r""" 

Return the incomplete elliptic integral of the first kind evaluated 

at *m*. 

  

See :meth:`elliptic_k` for the corresponding complete integral 

  

INPUT: 

  

- ``m`` - complex ball 

  

EXAMPLES:: 

  

sage: CBF(1,2).elliptic_f(CBF(0,1)) 

[0.6821522911854 +/- 2.96e-14] + [1.2482780628143 +/- 4.63e-14]*I 

  

At parameter `\pi/2` it is a complete integral:: 

  

sage: phi = CBF(1,1) 

sage: (CBF.pi()/2).elliptic_f(phi) 

[1.5092369540513 +/- 6.62e-14] + [0.6251464152027 +/- 2.11e-14]*I 

sage: phi.elliptic_k() 

[1.50923695405127 +/- 5.07e-15] + [0.62514641520270 +/- 4.41e-15]*I 

  

sage: phi = CBF(2, 3/7) 

sage: (CBF.pi()/2).elliptic_f(phi) 

[1.339358963909 +/- 5.02e-13] + [1.110436969072 +/- 1.37e-13]*I 

sage: phi.elliptic_k() 

[1.33935896390938 +/- 6.73e-15] + [1.11043696907194 +/- 6.41e-15]*I 

  

""" 

cdef ComplexBall result = self._new() 

cdef ComplexBall my_m = self._parent.coerce(m) 

if _do_sig(prec(self)): sig_on() 

acb_elliptic_f(result.value, self.value, my_m.value, 0, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return result 

  

def elliptic_e_inc(self, m): 

r""" 

Return the incomplete elliptic integral of the second kind evaluated 

at *m*. 

  

See :meth:`elliptic_e` for the corresponding complete integral 

  

INPUT: 

  

- ``m`` - complex ball 

  

EXAMPLES:: 

  

sage: CBF(1,2).elliptic_e_inc(CBF(0,1)) 

[1.906576998914 +/- 5.01e-13] + [3.6896645289411 +/- 6.93e-14]*I 

  

At parameter `\pi/2` it is a complete integral:: 

  

sage: phi = CBF(1,1) 

sage: (CBF.pi()/2).elliptic_e_inc(phi) 

[1.283840957898 +/- 3.23e-13] + [-0.5317843366915 +/- 7.79e-14]*I 

sage: phi.elliptic_e() 

[1.2838409578982 +/- 5.90e-14] + [-0.5317843366915 +/- 3.35e-14]*I 

  

sage: phi = CBF(2, 3/7) 

sage: (CBF.pi()/2).elliptic_e_inc(phi) 

[0.787564350925 +/- 6.56e-13] + [-0.686896129145 +/- 4.60e-13]*I 

sage: phi.elliptic_e() 

[0.7875643509254 +/- 6.97e-14] + [-0.686896129145 +/- 3.11e-13]*I 

  

""" 

cdef ComplexBall result = self._new() 

cdef ComplexBall my_m = self._parent.coerce(m) 

if _do_sig(prec(self)): sig_on() 

acb_elliptic_e_inc(result.value, self.value, my_m.value, 0, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return result 

  

def elliptic_pi_inc(self, phi, m): 

r""" 

Return the Legendre incomplete elliptic integral of the third kind. 

  

See: :meth:`elliptic_pi` for the complete integral. 

  

INPUT: 

  

- ``phi`` - complex ball 

  

- ``m`` - complex ball 

  

EXAMPLES:: 

  

sage: CBF(1,2).elliptic_pi_inc(CBF(0,1), CBF(2,-3)) 

[0.05738864021418 +/- 4.27e-15] + [0.55557494549951 +/- 5.71e-15]*I 

  

At parameter `\pi/2` it is a complete integral:: 

  

sage: n = CBF(1,1) 

sage: m = CBF(-2/3, 3/5) 

sage: n.elliptic_pi_inc(CBF.pi()/2, m) 

[0.8934793755173 +/- 5.65e-14] + [0.9570786871075 +/- 1.98e-14]*I 

sage: n.elliptic_pi(m) 

[0.89347937551733 +/- 4.07e-15] + [0.95707868710750 +/- 1.23e-15]*I 

  

sage: n = CBF(2, 3/7) 

sage: m = CBF(-1/3, 2/9) 

sage: n.elliptic_pi_inc(CBF.pi()/2, m) 

[0.296958874642 +/- 2.58e-13] + [1.318879533274 +/- 3.87e-13]*I 

sage: n.elliptic_pi(m) 

[0.29695887464189 +/- 4.98e-15] + [1.31887953327376 +/- 5.95e-15]*I 

""" 

cdef ComplexBall result = self._new() 

cdef ComplexBall my_phi = self._parent.coerce(phi) 

cdef ComplexBall my_m = self._parent.coerce(m) 

if _do_sig(prec(self)): sig_on() 

acb_elliptic_pi_inc(result.value, self.value, my_phi.value, my_m.value, 0, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return result 

  

def elliptic_rf(self, y, z): 

r""" 

Return the Carlson symmetric elliptic integral of the first kind evaluated 

at ``(self, y, z)``. 

  

INPUT: 

  

- ``y`` - complex ball 

  

- ``z`` - complex ball 

  

EXAMPLES:: 

  

sage: CBF(0,1).elliptic_rf(CBF(-1/2,1), CBF(-1,-1)) 

[1.469800396738515 +/- 3.70e-16] + [-0.2358791199824196 +/- 4.40e-17]*I 

  

""" 

cdef ComplexBall result = self._new() 

cdef ComplexBall my_y = self._parent.coerce(y) 

cdef ComplexBall my_z = self._parent.coerce(z) 

if _do_sig(prec(self)): sig_on() 

acb_elliptic_rf(result.value, self.value, my_y.value, my_z.value, 0, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return result 

  

def elliptic_rg(self, y, z): 

r""" 

Return the Carlson symmetric elliptic integral of the second kind evaluated 

at ``(self, y, z)``. 

  

INPUT: 

  

- ``y`` - complex ball 

  

- ``z`` - complex ball 

  

EXAMPLES:: 

  

sage: CBF(0,1).elliptic_rg(CBF(-1/2,1), CBF(-1,-1)) 

[0.1586786770922370 +/- 4.31e-17] + [0.2239733128130531 +/- 3.35e-17]*I 

  

""" 

cdef ComplexBall result = self._new() 

cdef ComplexBall my_y = self._parent.coerce(y) 

cdef ComplexBall my_z = self._parent.coerce(z) 

if _do_sig(prec(self)): sig_on() 

acb_elliptic_rg(result.value, self.value, my_y.value, my_z.value, 0, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return result 

  

def elliptic_rj(self, y, z, p): 

r""" 

Return the Carlson symmetric elliptic integral of the third kind evaluated 

at ``(self, y, z)``. 

  

INPUT: 

  

- ``y`` - complex ball 

  

- ``z`` - complex ball 

  

- ``p`` - complex bamm 

  

EXAMPLES:: 

  

sage: CBF(0,1).elliptic_rj(CBF(-1/2,1), CBF(-1,-1), CBF(2)) 

[1.004386756285733 +/- 5.21e-16] + [-0.2451626834391645 +/- 3.50e-17]*I 

  

""" 

cdef ComplexBall result = self._new() 

cdef ComplexBall my_y = self._parent.coerce(y) 

cdef ComplexBall my_z = self._parent.coerce(z) 

cdef ComplexBall my_p = self._parent.coerce(p) 

if _do_sig(prec(self)): sig_on() 

acb_elliptic_rj(result.value, self.value, my_y.value, my_z.value, my_p.value, 0, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return result 

  

def elliptic_zeta(self, tau): 

r""" 

Return the value of the Weierstrass zeta function at ``(self, tau)`` 

  

EXAMPLES:: 

  

- ``tau`` - a complex ball with positive imaginary part 

  

EXAMPLES:: 

  

sage: CBF(1,1).elliptic_zeta(CBF(1,3)) 

[3.2898676194970 +/- 5.93e-14] + [0.1365414361782 +/- 7.27e-14]*I 

""" 

cdef ComplexBall result = self._new() 

cdef ComplexBall my_tau = self._parent.coerce(tau) 

if _do_sig(prec(self)): sig_on() 

acb_elliptic_zeta(result.value, self.value, my_tau.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return result 

  

def elliptic_sigma(self, tau): 

r""" 

Return the value of the Weierstrass sigma function at ``(self, tau)`` 

  

EXAMPLES:: 

  

- ``tau`` - a complex ball with positive imaginary part 

  

EXAMPLES:: 

  

sage: CBF(1,1).elliptic_sigma(CBF(1,3)) 

[-0.543073363596 +/- 3.39e-13] + [3.635729118624 +/- 5.08e-13]*I 

  

""" 

cdef ComplexBall result = self._new() 

cdef ComplexBall my_tau = self._parent.coerce(tau) 

if _do_sig(prec(self)): sig_on() 

acb_elliptic_sigma(result.value, self.value, my_tau.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return result 

  

def chebyshev_T(self, n): 

""" 

Return the Chebyshev function of the first kind of order ``n`` 

evaluated at ``self``. 

  

EXAMPLES:: 

  

sage: CBF(1/3).chebyshev_T(20) 

[0.8710045668809 +/- 6.15e-14] 

sage: CBF(1/3).chebyshev_T(CBF(5,1)) 

[1.8429685451876 +/- 3.57e-14] + [0.20053614301799 +/- 7.05e-15]*I 

  

""" 

cdef ComplexBall my_n = self._parent.coerce(n) 

cdef ComplexBall result = self._new() 

if _do_sig(prec(self)): sig_on() 

acb_hypgeom_chebyshev_t(result.value, my_n.value, self.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return result 

  

def chebyshev_U(self, n): 

""" 

Return the Chebyshev function of the second kind of order ``n`` 

evaluated at ``self``. 

  

EXAMPLES:: 

  

sage: CBF(1/3).chebyshev_U(20) 

[0.6973126541184 +/- 2.83e-14] 

sage: CBF(1/3).chebyshev_U(CBF(5,1)) 

[1.7588496489342 +/- 5.99e-14] + [0.7497317165104 +/- 4.35e-14]*I 

  

""" 

cdef ComplexBall my_n = self._parent.coerce(n) 

cdef ComplexBall result = self._new() 

if _do_sig(prec(self)): sig_on() 

acb_hypgeom_chebyshev_u(result.value, my_n.value, self.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return result 

  

def jacobi_P(self, n, a, b): 

r""" 

Return the Jacobi polynomial (or function) `P_n^{(a,b)}(z)` 

evaluated at ``self``. 

  

EXAMPLES:: 

  

sage: CBF(5,-6).jacobi_P(8, CBF(1,2), CBF(2,3)) 

[-920983000.45982 +/- 2.22e-6] + [6069919969.92857 +/- 4.77e-6]*I 

  

""" 

cdef ComplexBall my_n = self._parent.coerce(n) 

cdef ComplexBall my_a = self._parent.coerce(a) 

cdef ComplexBall my_b = self._parent.coerce(b) 

cdef ComplexBall result = self._new() 

if _do_sig(prec(self)): sig_on() 

acb_hypgeom_jacobi_p(result.value, my_n.value, 

my_a.value, my_b.value, self.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return result 

  

def gegenbauer_C(self, n, m): 

r""" 

Return the Gegenbauer polynomial (or function) `C_n^m(z)` 

evaluated at ``self``. 

  

EXAMPLES:: 

  

sage: CBF(-10).gegenbauer_C(7, 1/2) 

[-263813415.6250000 +/- 9.57e-8] 

  

""" 

cdef ComplexBall my_n = self._parent.coerce(n) 

cdef ComplexBall my_m = self._parent.coerce(m) 

cdef ComplexBall result = self._new() 

if _do_sig(prec(self)): sig_on() 

acb_hypgeom_gegenbauer_c(result.value, my_n.value, 

my_m.value, self.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return result 

  

def laguerre_L(self, n, m=0): 

r""" 

Return the Laguerre polynomial (or function) `L_n^m(z)` 

evaluated at ``self``. 

  

EXAMPLES:: 

  

sage: CBF(10).laguerre_L(3) 

[-45.6666666666666 +/- 9.28e-14] 

sage: CBF(10).laguerre_L(3, 2) 

[-6.666666666667 +/- 4.15e-13] 

sage: CBF(5,7).laguerre_L(CBF(2,3), CBF(1,-2)) 

[5515.315030271 +/- 4.37e-10] + [-12386.942845271 +/- 5.47e-10]*I 

  

""" 

cdef ComplexBall my_n = self._parent.coerce(n) 

cdef ComplexBall my_m = self._parent.coerce(m) 

cdef ComplexBall result = self._new() 

if _do_sig(prec(self)): sig_on() 

acb_hypgeom_laguerre_l(result.value, my_n.value, 

my_m.value, self.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return result 

  

def hermite_H(self, n): 

""" 

Return the Hermite function (or polynomial) of order ``n`` 

evaluated at ``self``. 

  

EXAMPLES:: 

  

sage: CBF(10).hermite_H(1) 

20.00000000000000 

sage: CBF(10).hermite_H(30) 

[8.0574670961707e+37 +/- 3.28e+23] 

  

""" 

cdef ComplexBall my_n = self._parent.coerce(n) 

cdef ComplexBall result = self._new() 

if _do_sig(prec(self)): sig_on() 

acb_hypgeom_hermite_h(result.value, my_n.value, self.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return result 

  

def legendre_P(self, n, m=0, type=2): 

r""" 

Return the Legendre function of the first kind `P_n^m(z)` 

evaluated at ``self``. 

  

The ``type`` parameter can be either 2 or 3. This selects between 

different branch cut conventions. The definitions of the "type 2" 

and "type 3" functions are the same as those used by *Mathematica* 

and *mpmath*. 

  

EXAMPLES:: 

  

sage: CBF(1/2).legendre_P(5) 

[0.08984375000000000 +/- 4.5...e-18] 

sage: CBF(1,2).legendre_P(CBF(2,3), CBF(0,1)) 

[0.10996180744364 +/- 7.45e-15] + [0.14312767804055 +/- 8.38e-15]*I 

sage: CBF(-10).legendre_P(5, 325/100) 

[-22104403.487377 +/- 6.81e-7] + [53364750.687392 +/- 7.25e-7]*I 

sage: CBF(-10).legendre_P(5, 325/100, type=3) 

[-57761589.914581 +/- 6.99e-7] + [+/- 5.14e-7]*I 

  

""" 

cdef ComplexBall my_n = self._parent.coerce(n) 

cdef ComplexBall my_m = self._parent.coerce(m) 

cdef ComplexBall result = self._new() 

cdef int my_type = type 

if my_type != 2 and my_type != 3: 

raise ValueError("expected type 2 or 3") 

if _do_sig(prec(self)): sig_on() 

acb_hypgeom_legendre_p(result.value, my_n.value, 

my_m.value, self.value, my_type - 2, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return result 

  

def legendre_Q(self, n, m=0, type=2): 

r""" 

Return the Legendre function of the second kind `Q_n^m(z)` 

evaluated at ``self``. 

  

The ``type`` parameter can be either 2 or 3. This selects between 

different branch cut conventions. The definitions of the "type 2" 

and "type 3" functions are the same as those used by *Mathematica* 

and *mpmath*. 

  

EXAMPLES:: 

  

sage: CBF(1/2).legendre_Q(5) 

[0.55508089057168 +/- 2.79e-15] 

sage: CBF(1,2).legendre_Q(CBF(2,3), CBF(0,1)) 

[0.167678710 +/- 4.60e-10] + [-0.161558598 +/- 7.47e-10]*I 

sage: CBF(-10).legendre_Q(5, 325/100) 

[-83825154.36008 +/- 4.94e-6] + [-34721515.80396 +/- 5.40e-6]*I 

sage: CBF(-10).legendre_Q(5, 325/100, type=3) 

[-4.797306921692e-6 +/- 6.82e-19] + [-4.797306921692e-6 +/- 6.57e-19]*I 

  

""" 

cdef ComplexBall my_n = self._parent.coerce(n) 

cdef ComplexBall my_m = self._parent.coerce(m) 

cdef ComplexBall result = self._new() 

cdef int my_type = type 

if my_type != 2 and my_type != 3: 

raise ValueError("expected type 2 or 3") 

if _do_sig(prec(self)): sig_on() 

acb_hypgeom_legendre_q(result.value, my_n.value, 

my_m.value, self.value, my_type - 2, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return result 

  

def spherical_harmonic(self, phi, n, m): 

r""" 

Return the spherical harmonic `Y_n^m(\theta,\phi)` 

evaluated at `\theta` given by ``self``. 

In the current implementation, ``n`` and ``m`` must be small integers. 

  

EXAMPLES:: 

  

sage: CBF(1+I).spherical_harmonic(1/2, -3, -2) 

[0.80370071745224 +/- 4.02e-15] + [-0.07282031864711 +/- 4.69e-15]*I 

""" 

cdef ComplexBall my_phi = self._parent.coerce(phi) 

cdef long my_n = n 

cdef long my_m = m 

cdef ComplexBall result = self._new() 

if _do_sig(prec(self)): sig_on() 

acb_hypgeom_spherical_y(result.value, my_n, my_m, 

self.value, my_phi.value, prec(self)) 

if _do_sig(prec(self)): sig_off() 

return result 

  

  

CBF = ComplexBallField()