@@ -36,13 +36,7 @@ Basic arithmetic with C integers
36
36
# The int definitions
37
37
38
38
from libc.math cimport sqrt
39
- from sage.libs.gmp.mpz cimport mpz_set_ui
40
39
41
- from sage.ext.stdsage cimport PY_NEW
42
-
43
- from cypari2.paridecl cimport *
44
- from cypari2.gen cimport Gen as pari_gen
45
- from sage.libs.pari.all import pari
46
40
from sage.rings.integer cimport Integer
47
41
48
42
cpdef prime_range(start, stop = None , algorithm = None , bint py_ints = False ):
@@ -152,8 +146,6 @@ cpdef prime_range(start, stop=None, algorithm=None, bint py_ints=False):
152
146
- Robert Bradshaw ( speedup using Pari prime table, py_ints option)
153
147
"""
154
148
cdef Integer z
155
- cdef long c_start, c_stop, p
156
- cdef byteptr pari_prime_ptr
157
149
# input to pari.init_primes cannot be greater than 436273290 (hardcoded bound)
158
150
DEF init_primes_max = 436273290
159
151
DEF small_prime_max = 436273009 # a prime < init_primes_max (preferably the largest)
@@ -187,42 +179,32 @@ cpdef prime_range(start, stop=None, algorithm=None, bint py_ints=False):
187
179
algorithm = " pari_isprime"
188
180
189
181
if algorithm == " pari_primes" :
182
+ from sage.libs.pari.convert_sage import pari_maxprime, pari_prime_range
183
+ from sage.libs.pari import pari
190
184
191
185
if max (start, stop or 0 ) > small_prime_max:
192
186
raise ValueError (' algorithm "pari_primes" is limited to primes larger than'
193
187
+ ' {}' .format(small_prime_max - 1 ))
194
188
195
189
if stop is None :
196
190
# In this case, "start" is really stop
197
- c_start = 1
198
- c_stop = start
191
+ stop = start
192
+ start = 1
199
193
else :
200
- c_start = start
201
- c_stop = stop
202
- if c_start < 1 :
203
- c_start = 1
204
- if c_stop <= c_start :
194
+ start = start
195
+ stop = stop
196
+ if start < 1 :
197
+ start = 1
198
+ if stop <= start :
205
199
return []
206
200
207
- if maxprime () < c_stop :
201
+ if pari_maxprime () < stop :
208
202
# Adding prime_gap_bound should be sufficient to guarantee an
209
203
# additional prime, given that c_stop <= small_prime_max.
210
- pari.init_primes(min (c_stop + prime_gap_bound, init_primes_max))
211
- assert maxprime() >= c_stop
212
-
213
- pari_prime_ptr = diffptr
214
- p = 0
215
- res = []
216
- while p < c_start:
217
- NEXT_PRIME_VIADIFF(p, pari_prime_ptr)
218
- while p < c_stop:
219
- if py_ints:
220
- res.append(p)
221
- else :
222
- z = < Integer> PY_NEW(Integer)
223
- mpz_set_ui(z.value, p)
224
- res.append(z)
225
- NEXT_PRIME_VIADIFF(p, pari_prime_ptr)
204
+ pari.init_primes(min (stop + prime_gap_bound, init_primes_max))
205
+ assert pari_maxprime() >= stop
206
+
207
+ res = pari_prime_range(start, stop, py_ints)
226
208
227
209
elif (algorithm == " pari_isprime" ) or (algorithm == " pari_primes" ):
228
210
from sage.arith.all import primes
0 commit comments