forked from flintlib/python-flint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathacb.pyx
2757 lines (2391 loc) · 96.8 KB
/
acb.pyx
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
from cpython.complex cimport PyComplex_Check
from cpython.complex cimport PyComplex_RealAsDouble
from cpython.complex cimport PyComplex_ImagAsDouble
from flint.utils.typecheck cimport typecheck
from flint.flint_base.flint_base cimport flint_scalar
from flint.flint_base.flint_context cimport getprec
from flint.flint_base.flint_context cimport thectx
from flint.types.arb cimport arb_set_mpmath_mpf
from flint.types.arb cimport arb_set_python
from flint.types.arb cimport any_as_arb
from flint.types.arb cimport arb
from flint.types.fmpz cimport fmpz
from flint.types.fmpz cimport any_as_fmpz
from flint.types.dirichlet cimport dirichlet_char
from flint.flintlib.flint cimport FMPZ_TMP, FMPZ_REF, FMPZ_UNKNOWN
from flint.flintlib.mag cimport *
from flint.flintlib.arb cimport *
from flint.flintlib.arf cimport *
from flint.flintlib.acb cimport *
from flint.flintlib.acb_modular cimport *
from flint.flintlib.acb_hypgeom cimport *
from flint.flintlib.acb_dirichlet cimport *
from flint.flintlib.acb_elliptic cimport *
from flint.flintlib.acb_calc cimport *
from flint.flintlib.acb_dft cimport *
cimport libc.stdlib
cimport cython
ctx = thectx
cdef int acb_set_python(acb_t x, obj, bint allow_conversion):
cdef double re, im
if typecheck(obj, acb):
acb_set(x, (<acb>obj).val)
return 1
if arb_set_python(acb_realref(x), obj, allow_conversion):
arb_zero(acb_imagref(x))
return 1
if PyComplex_Check(obj):
re = PyComplex_RealAsDouble(obj)
im = PyComplex_ImagAsDouble(obj)
arf_set_d(arb_midref(acb_realref(x)), re)
arf_set_d(arb_midref(acb_imagref(x)), im)
mag_zero(arb_radref(acb_realref(x)))
mag_zero(arb_radref(acb_imagref(x)))
return 1
if hasattr(obj, "_mpc_"):
xre, xim = obj._mpc_
arb_set_mpmath_mpf(acb_realref(x), xre)
arb_set_mpmath_mpf(acb_imagref(x), xim)
return 1
return 0
cdef inline int acb_set_any_ref(acb_t x, obj):
if typecheck(obj, acb): # should be exact check?
x[0] = (<acb>obj).val[0]
return FMPZ_REF
acb_init(x)
if acb_set_python(x, obj, 0):
return FMPZ_TMP
return FMPZ_UNKNOWN
cdef any_as_acb(x):
cdef acb t
if typecheck(x, acb):
return x
t = acb()
if acb_set_python(t.val, x, 0) == 0:
raise TypeError("cannot create acb from type %s" % type(x))
return t
cdef any_as_acb_or_notimplemented(x):
cdef acb t
if typecheck(x, acb):
return x
t = acb()
if acb_set_python(t.val, x, 0) == 0:
return NotImplemented
return t
"""
cdef any_as_arb_or_acb(x):
if typecheck(x, arb) or typecheck(x, acb):
return x
try:
return arb(x)
except (TypeError, ValueError):
return acb(x)
"""
# Copied with modifications from sage/rings/complex_arb.pyx
@cython.internal
cdef class IntegrationContext:
cdef object f
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):
cdef IntegrationContext ictx
cdef acb x
try:
ictx = <IntegrationContext>param
if ictx.exn_type is not None or order >= 2:
acb_indeterminate(out)
return 0
x = acb.__new__(acb)
acb_set(x.val, inp)
try:
y = ictx.f(x, (order == 1))
if not typecheck(y, acb):
raise TypeError("integrand must return an acb")
acb_set(out, (<acb> y).val)
except:
import sys
ictx.exn_type, ictx.exn_obj, ictx.exn_tb = sys.exc_info()
acb_indeterminate(out)
return 0
finally:
pass
cdef class acb(flint_scalar):
r"""
An *acb* represents a complex number by a rectangular enclosure
consisting of *arb* balls for the real and imaginary parts.
>>> from flint import fmpq
>>> acb(2)
2.00000000000000
>>> acb(2+3j)
2.00000000000000 + 3.00000000000000j
>>> acb("2 +/- 0.001", fmpq(2,3))
[2.00 +/- 1.01e-3] + [0.666666666666667 +/- 4.82e-16]j
>>> acb(-1) ** 0.25
[0.707106781186547 +/- 6.14e-16] + [0.707106781186547 +/- 6.15e-16]j
"""
# cdef acb_t val
def __cinit__(self):
acb_init(self.val)
def __dealloc__(self):
acb_clear(self.val)
def __init__(self, real=None, imag=None):
if real is not None:
if not acb_set_python(self.val, real, 1):
raise TypeError("cannot create acb from type %s" % type(real))
if imag is not None:
if not arb_is_zero(acb_imagref(self.val)):
raise ValueError("must create acb from one complex number or two real numbers")
if not arb_set_python(acb_imagref(self.val), imag, 1):
raise TypeError("cannot create arb from type %s" % type(imag))
cpdef bint is_zero(self):
return acb_is_zero(self.val)
cpdef bint is_finite(self):
return acb_is_finite(self.val)
cpdef bint is_exact(self):
return acb_is_exact(self.val)
@property
def real(self):
cdef arb re = arb()
arb_set(re.val, acb_realref(self.val))
return re
@property
def imag(self):
cdef arb im = arb()
arb_set(im.val, acb_imagref(self.val))
return im
@property
def _mpc_(self):
return (self.real._mpf_, self.imag._mpf_)
def __richcmp__(s, t, int op):
cdef acb_struct tval[1]
cdef bint res
cdef int ttype
if not (op == 2 or op == 3):
raise ValueError("comparing complex numbers")
ttype = acb_set_any_ref(tval, t)
if ttype == FMPZ_UNKNOWN:
return NotImplemented
if op == 2:
res = acb_eq(s.val, tval)
else:
res = acb_ne(s.val, tval)
if ttype == FMPZ_TMP: acb_clear(tval)
return res
def __contains__(self, other):
other = any_as_acb(other)
return acb_contains(self.val, (<acb>other).val)
def contains(self, other):
other = any_as_acb(other)
return bool(acb_contains(self.val, (<acb>other).val))
def contains_interior(self, other):
other = any_as_acb(other)
return bool(acb_contains_interior(self.val, (<acb>other).val))
def overlaps(self, other):
other = any_as_acb(other)
return bool(acb_overlaps((<acb>self).val, (<acb>other).val))
def contains_integer(self):
return bool(acb_contains_int(self.val))
def mid(self):
"""
Returns an exact *acb* representing the midpoint of *self*:
>>> acb("1 +/- 0.3", "2 +/- 0.4").mid()
1.00000000000000 + 2.00000000000000j
"""
cdef acb u = acb()
arf_set(arb_midref(acb_realref(u.val)), arb_midref(acb_realref(self.val)))
arf_set(arb_midref(acb_imagref(u.val)), arb_midref(acb_imagref(self.val)))
return u
def rad(self):
"""
Returns an upper bound for the radius (magnitude of error) of self as an *arb*.
>>> print(acb("1 +/- 0.3", "2 +/- 0.4").rad().str(5, radius=False))
0.50000
"""
cdef arb u = arb()
mag_hypot(arb_radref(u.val), arb_radref(acb_realref(self.val)), arb_radref(acb_imagref(self.val)))
arf_set_mag(arb_midref(u.val), arb_radref(u.val))
mag_zero(arb_radref(u.val))
return u
def complex_rad(self):
"""
Returns an *acb* representing the radii of the real and imaginary parts of *self*
together a single complex number.
>>> print(acb("1 +/- 0.3", "2 +/- 0.4").complex_rad().str(5, radius=False))
0.30000 + 0.40000j
"""
cdef acb u = acb()
arf_set_mag(arb_midref(acb_realref(u.val)), arb_radref(acb_realref(self.val)))
arf_set_mag(arb_midref(acb_imagref(u.val)), arb_radref(acb_imagref(self.val)))
return u
def repr(self):
real = self.real
imag = self.imag
if imag.is_zero():
return "acb(%s)" % real.repr()
else:
return "acb(%s, %s)" % (real.repr(), imag.repr())
def str(self, *args, **kwargs):
real = self.real
imag = self.imag
if imag.is_zero():
return real.str(*args, **kwargs)
elif real.is_zero():
return imag.str(*args, **kwargs) + "j"
else:
re = real.str(*args, **kwargs)
im = imag.str(*args, **kwargs)
if im.startswith("-"):
return "%s - %sj" % (re, im[1:])
else:
return "%s + %sj" % (re, im)
def __complex__(self):
return complex(arf_get_d(arb_midref(acb_realref(self.val)), ARF_RND_NEAR),
arf_get_d(arb_midref(acb_imagref(self.val)), ARF_RND_NEAR))
def __pos__(self):
res = acb.__new__(acb)
acb_set_round((<acb>res).val, (<acb>self).val, getprec())
return res
def __neg__(self):
res = acb.__new__(acb)
acb_neg_round((<acb>res).val, (<acb>self).val, getprec())
return res
def neg(self, bint exact=False):
res = acb.__new__(acb)
if exact:
acb_set((<acb>res).val, (<acb>self).val)
else:
acb_set_round((<acb>res).val, (<acb>self).val, getprec())
return res
def conjugate(self, bint exact=False):
res = acb.__new__(acb)
if exact:
acb_conj((<acb>res).val, (<acb>self).val)
else:
acb_set_round((<acb>res).val, (<acb>self).val, getprec())
acb_conj((<acb>res).val, (<acb>res).val)
return res
def __abs__(self):
res = arb.__new__(arb)
acb_abs((<arb>res).val, (<acb>self).val, getprec())
return res
def abs_lower(self):
"""
Lower bound for the absolute value of *self*.
The output is an *arb* holding an exact floating-point number
that has been rounded down to the current precision.
>>> print(acb(3, "-5 +/- 2").abs_lower().str(5, radius=False))
4.2426
"""
cdef arb x = arb()
acb_get_abs_lbound_arf(arb_midref(x.val), self.val, getprec())
return x
def abs_upper(self):
"""
Upper bound for the absolute value of *self*.
The output is an *arb* holding an exact floating-point number
that has been rounded up to the current precision.
>>> print(acb(3, "-5 +/- 2").abs_upper().str(5, radius=False))
7.6158
"""
cdef arb x = arb()
acb_get_abs_ubound_arf(arb_midref(x.val), self.val, getprec())
return x
def csgn(self):
"""
Complex sign function defined as a piecewise extension of
the real sign function.
>>> from flint import showgood
>>> showgood(lambda: acb(2,3).csgn(), dps=25)
1.000000000000000000000000
>>> showgood(lambda: acb(-1).csgn(), dps=25)
-1.000000000000000000000000
"""
res = arb.__new__(arb)
acb_csgn((<arb>res).val, (<acb>self).val)
return res
def sgn(self):
"""
Complex sign function.
>>> from flint import showgood
>>> showgood(lambda: acb(-1).sgn(), dps=25)
-1.000000000000000000000000
>>> showgood(lambda: acb(5,5).sgn(), dps=25)
0.7071067811865475244008444 + 0.7071067811865475244008444j
>>> showgood(lambda: acb(0).sgn(), dps=25)
0
"""
res = acb.__new__(acb)
acb_sgn((<acb>res).val, (<acb>self).val, getprec())
return res
def arg(self):
"""
Complex argument (phase).
>>> from flint import showgood
>>> showgood(lambda: acb("3.3").arg(), dps=25)
0
>>> showgood(lambda: acb(-1).arg(), dps=25)
3.141592653589793238462643
>>> acb(-1, "+/- 1").arg()
[+/- 3.15]
"""
res = arb.__new__(arb)
acb_arg((<arb>res).val, (<acb>self).val, getprec())
return res
def __add__(s, t):
cdef acb_struct tval[1]
cdef int ttype
ttype = acb_set_any_ref(tval, t)
if ttype == FMPZ_UNKNOWN:
return NotImplemented
u = acb.__new__(acb)
acb_add((<acb>u).val, (<acb>s).val, tval, getprec())
if ttype == FMPZ_TMP: acb_clear(tval)
return u
def __radd__(s, t):
cdef acb_struct tval[1]
cdef int ttype
ttype = acb_set_any_ref(tval, t)
if ttype == FMPZ_UNKNOWN:
return NotImplemented
u = acb.__new__(acb)
acb_add((<acb>u).val, tval, s.val, getprec())
if ttype == FMPZ_TMP: acb_clear(tval)
return u
def __sub__(s, t):
cdef acb_struct tval[1]
cdef int ttype
ttype = acb_set_any_ref(tval, t)
if ttype == FMPZ_UNKNOWN:
return NotImplemented
u = acb.__new__(acb)
acb_sub((<acb>u).val, (<acb>s).val, tval, getprec())
if ttype == FMPZ_TMP: acb_clear(tval)
return u
def __rsub__(s, t):
cdef acb_struct tval[1]
cdef int ttype
ttype = acb_set_any_ref(tval, t)
if ttype == FMPZ_UNKNOWN:
return NotImplemented
u = acb.__new__(acb)
acb_sub((<acb>u).val, tval, s.val, getprec())
if ttype == FMPZ_TMP: acb_clear(tval)
return u
def __mul__(s, t):
cdef acb_struct tval[1]
cdef int ttype
ttype = acb_set_any_ref(tval, t)
if ttype == FMPZ_UNKNOWN:
return NotImplemented
u = acb.__new__(acb)
acb_mul((<acb>u).val, (<acb>s).val, tval, getprec())
if ttype == FMPZ_TMP: acb_clear(tval)
return u
def __rmul__(s, t):
cdef acb_struct tval[1]
cdef int ttype
ttype = acb_set_any_ref(tval, t)
if ttype == FMPZ_UNKNOWN:
return NotImplemented
u = acb.__new__(acb)
acb_mul((<acb>u).val, tval, s.val, getprec())
if ttype == FMPZ_TMP: acb_clear(tval)
return u
def __truediv__(s, t):
cdef acb_struct tval[1]
cdef int ttype
ttype = acb_set_any_ref(tval, t)
if ttype == FMPZ_UNKNOWN:
return NotImplemented
u = acb.__new__(acb)
acb_div((<acb>u).val, (<acb>s).val, tval, getprec())
if ttype == FMPZ_TMP: acb_clear(tval)
return u
def __rtruediv__(s, t):
cdef acb_struct tval[1]
cdef int ttype
ttype = acb_set_any_ref(tval, t)
if ttype == FMPZ_UNKNOWN:
return NotImplemented
u = acb.__new__(acb)
acb_div((<acb>u).val, tval, s.val, getprec())
if ttype == FMPZ_TMP: acb_clear(tval)
return u
def __pow__(s, t, u):
cdef acb_struct tval[1]
cdef int ttype
if u is not None:
raise ValueError("modular exponentiation of complex number")
ttype = acb_set_any_ref(tval, t)
if ttype == FMPZ_UNKNOWN:
return NotImplemented
u = acb.__new__(acb)
acb_pow((<acb>u).val, (<acb>s).val, tval, getprec())
if ttype == FMPZ_TMP: acb_clear(tval)
return u
def __rpow__(s, t, u):
cdef acb_struct tval[1]
cdef int ttype
if u is not None:
raise ValueError("modular exponentiation of complex number")
ttype = acb_set_any_ref(tval, t)
if ttype == FMPZ_UNKNOWN:
return NotImplemented
u = acb.__new__(acb)
acb_pow((<acb>u).val, tval, s.val, getprec())
if ttype == FMPZ_TMP: acb_clear(tval)
return u
def union(s, t):
v = acb.__new__(acb)
t = any_as_acb(t)
acb_union((<acb>v).val, (<acb>s).val, (<acb>t).val, getprec())
return v
def pow(s, t, bint analytic=False):
"""
Power `s^t`.
The *analytic* flag allows verifying that the branch cut is not
touched; this is useful for numerical integration.
>>> acb.integral(lambda z, a: z.pow(acb("1/3")), -5-1j, -5+1j) # WRONG!!!
[+/- 5.03e-15] + [1.81137435753228 +/- 7.32e-15]j
>>> acb.integral(lambda z, a: z.pow(acb("1/3"), analytic=a), -5-1j, -5+1j)
[+/- 2.66e-14] + [1.8108516218463 +/- 3.58e-14]j
"""
t = any_as_acb(t)
u = acb.__new__(acb)
acb_pow_analytic((<acb>u).val, (<acb>s).val, (<acb>t).val, analytic, getprec())
return u
def log(s, bint analytic=False):
r"""
Natural logarithm `\log(s)`.
The *analytic* flag allows verifying that the branch cut is not
touched; this is useful for numerical integration.
>>> from flint import showgood
>>> showgood(lambda: acb(1,2).log(), dps=25)
0.8047189562170501873003797 + 1.107148717794090503017065j
>>> showgood(lambda: acb(-5).log(), dps=25)
1.609437912434100374600759 + 3.141592653589793238462643j
"""
u = acb.__new__(acb)
acb_log_analytic((<acb>u).val, (<acb>s).val, analytic, getprec())
return u
def log1p(s):
r"""
Computes `\log(1+s)`, accurately for small *s*.
>>> from flint import showgood
>>> showgood(lambda: acb(1,2).log1p(), dps=25)
1.039720770839917964125848 + 0.7853981633974483096156608j
>>> showgood(lambda: acb(0,"1e-100000000000000000").log1p(), dps=25)
5.000000000000000000000000e-200000000000000001 + 1.000000000000000000000000e-100000000000000000j
"""
u = acb.__new__(acb)
acb_log1p((<acb>u).val, (<acb>s).val, getprec())
return u
def asin(s):
r"""
Inverse sine `\operatorname{asin}(s)`.
>>> from flint import showgood
>>> showgood(lambda: acb(2).asin(), dps=25)
1.570796326794896619231322 - 1.316957896924816708625046j
"""
u = acb.__new__(acb)
acb_asin((<acb>u).val, (<acb>s).val, getprec())
return u
def acos(s):
r"""
Inverse cosine `\operatorname{acos}(s)`.
>>> from flint import showgood
>>> showgood(lambda: acb(2).acos(), dps=25)
1.316957896924816708625046j
"""
u = acb.__new__(acb)
acb_acos((<acb>u).val, (<acb>s).val, getprec())
return u
def atan(s):
r"""
Computes the inverse tangent `\operatorname{atan}(s)`.
>>> from flint import showgood
>>> showgood(lambda: acb(1,2).atan(), dps=25)
1.338972522294493561124194 + 0.4023594781085250936501898j
"""
u = acb.__new__(acb)
acb_atan((<acb>u).val, (<acb>s).val, getprec())
return u
def asinh(s):
r"""
Inverse hyperbolic sine `\operatorname{asinh}(s)`.
>>> from flint import showgood
>>> showgood(lambda: acb(2,3).asinh(), dps=25)
1.968637925793096291788665 + 0.9646585044076027920454111j
"""
u = acb.__new__(acb)
acb_asinh((<acb>u).val, (<acb>s).val, getprec())
return u
def acosh(s):
r"""
Inverse hyperbolic cosine `\operatorname{acosh}(s)`.
>>> from flint import showgood
>>> showgood(lambda: acb(2,3).acosh(), dps=25)
1.983387029916535432347077 + 1.000143542473797218521038j
"""
u = acb.__new__(acb)
acb_acosh((<acb>u).val, (<acb>s).val, getprec())
return u
def atanh(s):
r"""
Inverse hyperbolic tangent `\operatorname{atanh}(s)`.
>>> from flint import showgood
>>> showgood(lambda: acb(2,3).atanh(), dps=25)
0.1469466662255297520474328 + 1.338972522294493561124194j
"""
u = acb.__new__(acb)
acb_atanh((<acb>u).val, (<acb>s).val, getprec())
return u
def agm(s, t=None):
"""
Arithmetic-geometric mean `M(s,t)`, or `M(s) = M(s,1)`
if no extra parameter is passed.
>>> from flint import showgood
>>> showgood(lambda: acb(2).agm(), dps=25)
1.456791031046906869186432
>>> showgood(lambda: acb(1,1).agm(), dps=25)
1.049160528732780220531827 + 0.4781557460881612293261882j
>>> showgood(lambda: (acb(-95,-65)/100).agm(acb(684,747)/1000), dps=25)
-0.3711072435676023931065922 + 0.3199561471173686568561674j
"""
if t is None:
u = acb.__new__(acb)
acb_agm1((<acb>u).val, (<acb>s).val, getprec())
return u
else:
t = acb(t)
u = acb.__new__(acb)
acb_agm((<acb>u).val, (<acb>s).val, (<acb>t).val, getprec())
return u
def gamma(s):
"""
Gamma function `\Gamma(s)`.
>>> from flint import showgood
>>> showgood(lambda: acb(1,2).gamma(), dps=25)
0.1519040026700361374481610 + 0.01980488016185498197191013j
"""
u = acb.__new__(acb)
acb_gamma((<acb>u).val, (<acb>s).val, getprec())
return u
def rgamma(s):
"""
Reciprocal gamma function `1/\Gamma(s)`, avoiding
division by zero at the poles of the gamma function.
>>> from flint import showgood
>>> showgood(lambda: acb(1,2).rgamma(), dps=25)
6.473073626019134501563613 - 0.8439438407732021454882999j
>>> print(acb(0).rgamma())
0
>>> print(acb(-1).rgamma())
0
"""
u = acb.__new__(acb)
acb_rgamma((<acb>u).val, (<acb>s).val, getprec())
return u
def lgamma(s):
"""
Logarithmic gamma function `\log \Gamma(s)`.
The function is defined to be continuous away from the
negative half-axis and thus differs from `\log(\Gamma(s))` in general.
>>> from flint import arb
>>> from flint import showgood
>>> showgood(lambda: acb(1,2).lgamma(), dps=25)
-1.876078786430929341229996 + 0.1296463163097883113837075j
>>> showgood(lambda: (acb(0,10).lgamma() - acb(0,10).gamma().log()).imag / arb.pi(), dps=25)
4.000000000000000000000000
"""
u = acb.__new__(acb)
acb_lgamma((<acb>u).val, (<acb>s).val, getprec())
return u
def digamma(s):
"""
Digamma function `\psi(s)`.
>>> from flint import showgood
>>> showgood(lambda: acb(1,2).digamma(), dps=25)
0.7145915153739775266568699 + 1.320807282642230228386088j
"""
u = acb.__new__(acb)
acb_digamma((<acb>u).val, (<acb>s).val, getprec())
return u
def zeta(s, a=None):
"""
Riemann zeta function `\zeta(s)`, or the Hurwitz
zeta function `\zeta(s,a)` if a second parameter is passed.
>>> from flint import showgood
>>> showgood(lambda: acb(0.5,1000).zeta(), dps=25)
0.3563343671943960550744025 + 0.9319978312329936651150604j
>>> showgood(lambda: acb(1,2).zeta(acb(2,3)), dps=25)
-2.953059572088556722876240 + 3.410962524512050603254574j
"""
if a is None:
u = acb.__new__(acb)
acb_zeta((<acb>u).val, (<acb>s).val, getprec())
return u
else:
a = any_as_acb(a)
u = acb.__new__(acb)
acb_hurwitz_zeta((<acb>u).val, (<acb>s).val, (<acb>a).val, getprec())
return u
def dirichlet_l(s, chi):
cdef dirichlet_char cchar
if isinstance(chi, dirichlet_char):
cchar = chi
else:
cchar = dirichlet_char(chi[0], chi[1])
u = acb.__new__(acb)
acb_dirichlet_l((<acb>u).val, (<acb>s).val, cchar.G.val, cchar.val, getprec())
return u
@staticmethod
def pi():
"""
Returns tthe constant `\pi` as an *acb*.
>>> from flint import showgood
>>> showgood(lambda: acb.pi(), dps=25)
3.141592653589793238462643
"""
u = acb.__new__(acb)
acb_const_pi((<acb>u).val, getprec())
return u
def sqrt(s, bint analytic=False):
r"""
Square root `\sqrt{s}`.
>>> from flint import showgood
>>> showgood(lambda: acb(1,2).sqrt(), dps=25)
1.272019649514068964252422 + 0.7861513777574232860695586j
The *analytic* flag allows verifying that the branch cut is not
touched; this is useful for numerical integration.
>>> from flint import showgood
>>> showgood(lambda: acb.integral(lambda z, a: z.sqrt(), 0, 1).real, dps=25) # WRONG!!!
0.6738873386790491615691993
>>> showgood(lambda: acb.integral(lambda z, a: z.sqrt(analytic=a), 0, 1).real, dps=25)
0.6666666666666666666666667
"""
u = acb.__new__(acb)
acb_sqrt_analytic((<acb>u).val, (<acb>s).val, analytic, getprec())
return u
def rsqrt(s, bint analytic=False):
r"""
Reciprocal square root `1/\sqrt{s}`.
The *analytic* flag allows verifying that the branch cut is not
touched; this is useful for numerical integration.
>>> from flint import showgood
>>> showgood(lambda: acb(1,2).rsqrt(), dps=25)
0.5688644810057831072783079 - 0.3515775842541429284870573j
"""
u = acb.__new__(acb)
acb_rsqrt_analytic((<acb>u).val, (<acb>s).val, analytic, getprec())
return u
def exp(s):
r"""
Exponential function `\exp(s)`.
>>> from flint import showgood
>>> showgood(lambda: acb(1,2).exp(), dps=25)
-1.131204383756813638431255 + 2.471726672004818927616931j
"""
u = acb.__new__(acb)
acb_exp((<acb>u).val, (<acb>s).val, getprec())
return u
def exp_pi_i(s):
r"""
Exponential function of modified argument `\exp(\pi i s)`.
>>> from flint import showgood
>>> showgood(lambda: acb(1,2).exp_pi_i(), dps=25)
-0.001867442731707988814430213
>>> showgood(lambda: acb(1.5,2.5).exp_pi_i(), dps=25)
-0.0003882032039267662472325299j
>>> showgood(lambda: acb(1.25,2.25).exp_pi_i(), dps=25)
-0.0006020578259597635239581705 - 0.0006020578259597635239581705j
"""
u = acb.__new__(acb)
acb_exp_pi_i((<acb>u).val, (<acb>s).val, getprec())
return u
def expm1(s):
r"""
Exponential function `\exp(s)-1`, computed accurately for small *s*.
>>> from flint import showgood
>>> showgood(lambda: acb("1e-10000").expm1(), dps=25)
1.000000000000000000000000e-10000
"""
u = acb.__new__(acb)
acb_expm1((<acb>u).val, (<acb>s).val, getprec())
return u
def sin(s):
r"""
Sine function `\sin(s)`.
>>> from flint import showgood
>>> showgood(lambda: acb(1,2).sin(), dps=25)
3.165778513216168146740735 + 1.959601041421605897070352j
"""
u = acb.__new__(acb)
acb_sin((<acb>u).val, (<acb>s).val, getprec())
return u
def cos(s):
r"""
Cosine function `\cos(s)`.
>>> from flint import showgood
>>> showgood(lambda: acb(1,2).cos(), dps=25)
2.032723007019665529436343 - 3.051897799151800057512116j
"""
u = acb.__new__(acb)
acb_cos((<acb>u).val, (<acb>s).val, getprec())
return u
def sin_cos(s):
r"""
Computes `\sin(s)` and `\cos(s)` simultaneously.
>>> from flint import showgood
>>> showgood(lambda: acb(1,2).sin_cos(), dps=15)
(3.16577851321617 + 1.95960104142161j, 2.03272300701967 - 3.05189779915180j)
"""
u = acb.__new__(acb)
v = acb.__new__(acb)
acb_sin_cos((<acb>u).val, (<acb>v).val, (<acb>s).val, getprec())
return u, v
def tan(s):
r"""
Tangent function `\tan(s)`.
>>> from flint import showgood
>>> showgood(lambda: acb(1,2).tan(), dps=25)
0.03381282607989669028437056 + 1.014793616146633568117054j
"""
u = acb.__new__(acb)
acb_tan((<acb>u).val, (<acb>s).val, getprec())
return u
def cot(s):
r"""
Cotangent function `\cot(s)`.
>>> from flint import showgood
>>> showgood(lambda: acb(1,2).cot(), dps=25)
0.03279775553375259406276455 - 0.9843292264581910294718882j
"""
u = acb.__new__(acb)
acb_cot((<acb>u).val, (<acb>s).val, getprec())
return u
def sin_pi(s):
r"""
Sine function `\sin(\pi s)`.
>>> from flint import showgood
>>> showgood(lambda: acb(1,2).sin_pi(), dps=25)
-267.7448940410165142571174j
"""
u = acb.__new__(acb)
acb_sin_pi((<acb>u).val, (<acb>s).val, getprec())
return u
def cos_pi(s):
r"""
Cosine function `\cos(\pi s)`.
>>> from flint import showgood
>>> showgood(lambda: acb(1,2).cos_pi(), dps=25)
-267.7467614837482222459319
"""
u = acb.__new__(acb)
acb_cos_pi((<acb>u).val, (<acb>s).val, getprec())
return u
def sin_cos_pi(s):
r"""
Computes `\sin(\pi s)` and `\cos(\pi s)` simultaneously.
>>> from flint import showgood
>>> showgood(lambda: acb(1,2).sin_cos_pi(), dps=25)
(-267.7448940410165142571174j, -267.7467614837482222459319)
"""
u = acb.__new__(acb)
v = acb.__new__(acb)
acb_sin_cos_pi((<acb>u).val, (<acb>v).val, (<acb>s).val, getprec())
return u, v
def tan_pi(s):
r"""
Tangent function `\tan(\pi s)`.
>>> from flint import showgood
>>> showgood(lambda: acb(1,2).tan_pi(), dps=25)
0.9999930253396106106051072j
"""
u = acb.__new__(acb)
acb_tan_pi((<acb>u).val, (<acb>s).val, getprec())
return u
def cot_pi(s):
r"""
Cotangent function `\cot(\pi s)`.
>>> from flint import showgood
>>> showgood(lambda: acb(1,2).cot_pi(), dps=25)
-1.000006974709035616233122j
"""
u = acb.__new__(acb)
acb_cot_pi((<acb>u).val, (<acb>s).val, getprec())
return u
def sec(s):
r"""
Secant function `\sec(s)`.
>>> from flint import showgood
>>> showgood(lambda: acb(2,3).sec(), dps=25)
-0.04167496441114427004834991 + 0.09061113719623759652966120j
"""
u = acb.__new__(acb)
acb_sec((<acb>u).val, (<acb>s).val, getprec())
return u
def csc(s):
r"""
Cosecant function `\sec(s)`.
>>> from flint import showgood
>>> showgood(lambda: acb(2,3).csc(), dps=25)
0.09047320975320743980579048 + 0.04120098628857412646300981j
"""
u = acb.__new__(acb)
acb_csc((<acb>u).val, (<acb>s).val, getprec())
return u
def sinh(s):
r"""
Hyperbolic sine function `\sinh(s)`.
>>> from flint import showgood
>>> showgood(lambda: acb(2,3).sinh(), dps=25)
-3.590564589985779952012565 + 0.5309210862485198052670401j
"""
u = acb.__new__(acb)
acb_sinh((<acb>u).val, (<acb>s).val, getprec())
return u
def cosh(s):
r"""
Hyperbolic cosine function `\cosh(s)`.
>>> from flint import showgood
>>> showgood(lambda: acb(2,3).cosh(), dps=25)
-3.724545504915322565473971 + 0.5118225699873846088344638j
"""