@@ -86,6 +86,37 @@ from .auto_paridecl cimport *
86
86
87
87
include ' auto_gen.pxi'
88
88
89
+
90
+ cdef bint ellwp_flag1_bug = - 1
91
+ cdef inline bint have_ellwp_flag1_bug():
92
+ """
93
+ The PARI function ``ellwp(..., flag=1)`` has a bug in PARI versions
94
+ up to 2.9.3 where the derivative is a factor 2 too small.
95
+
96
+ This function does a cached check for this bug, returning 1 if
97
+ the bug is there and 0 if not.
98
+ """
99
+ global ellwp_flag1_bug
100
+ if ellwp_flag1_bug >= 0 :
101
+ return ellwp_flag1_bug
102
+
103
+ # Check whether our PARI/GP version is buggy or not. This
104
+ # computation should return 1.0, but in older PARI versions it
105
+ # returns 0.5.
106
+ sig_on()
107
+ cdef GEN res = gp_read_str(b" localbitprec(128); my(E=ellinit([0,1/4])); ellwp(E,ellpointtoz(E,[0,1/2]),1)[2]" )
108
+ cdef double d = gtodouble(res)
109
+ sig_off()
110
+
111
+ if d == 1.0 :
112
+ ellwp_flag1_bug = 0
113
+ elif d == 0.5 :
114
+ ellwp_flag1_bug = 1
115
+ else :
116
+ raise AssertionError (f" unexpected result from ellwp() test: {d}" )
117
+ return ellwp_flag1_bug
118
+
119
+
89
120
@cython.final
90
121
cdef class Gen(Gen_auto):
91
122
"""
@@ -4736,18 +4767,24 @@ cdef class Gen(Gen_auto):
4736
4767
With flag=1, compute the pair P(z) and P'(z):
4737
4768
4738
4769
>>> E.ellwp(1, flag=1)
4739
- [13.9658695257485, 50.5619300880073 ]
4770
+ [13.9658695257485, 101.123860176015 ]
4740
4771
"""
4741
4772
cdef Gen t0 = objtogen(z)
4742
4773
cdef GEN g0 = t0.g
4743
4774
4744
- # Emulate toser_i() but with given precision
4745
4775
sig_on()
4776
+ # Polynomial or rational function as input:
4777
+ # emulate toser_i() but with given precision
4746
4778
if typ(g0) == t_POL:
4747
4779
g0 = RgX_to_ser(g0, n+ 4 )
4748
4780
elif typ(g0) == t_RFRAC:
4749
4781
g0 = rfrac_to_ser(g0, n+ 4 )
4750
- return new_gen(ellwp0(self .g, g0, flag, prec_bits_to_words(precision)))
4782
+
4783
+ cdef GEN r = ellwp0(self .g, g0, flag, prec_bits_to_words(precision))
4784
+ if flag == 1 and have_ellwp_flag1_bug():
4785
+ # Work around ellwp() bug: double the second element
4786
+ set_gel(r, 2 , gmulgs(gel(r, 2 ), 2 ))
4787
+ return new_gen(r)
4751
4788
4752
4789
def debug (self , long depth = - 1 ):
4753
4790
r """
0 commit comments