Ticket #3658: trac-3658.patch

File trac-3658.patch, 2.3 KB (added by craigcitro, 14 years ago)
• sage/functions/transcendental.py

```# HG changeset patch
# User Craig Citro <craigcitro@gmail.com>
# Date 1232720155 28800
# Node ID 12007b5253cfe3bc550dfb80ec4e3177da5576a3
# Parent  daa90769ff1093afc4e69d5331032b7b26d8c10f
Fix trac #3658: incorrect results from pari primepi.

diff -r daa90769ff10 -r 12007b5253cf sage/functions/transcendental.py```
 a 0 sage: prime_pi(-10) 0 sage: prime_pi(500509) 41581 The prime_pi function also has a special plotting method, so it plots quickly and perfectly as a step function. def __call__(self, x): if x < 2: return ZZ(0) try: return ZZ(pari(x).primepi()) except PariError: from sage.rings.integer import Integer pari.init_primes(pari(x)+Integer(1)) return ZZ(pari(x).primepi()) return ZZ(pari(x).primepi()) def plot(self, xmin=0, xmax=100, *args, **kwds): primes = prime_range(xmin, xmax+2)
• sage/libs/pari/gen.pyx

`diff -r daa90769ff10 -r 12007b5253cf sage/libs/pari/gen.pyx`
 a 0 sage: pari(-15).primepi() 0 """ _sig_on sage: pari(500509).primepi() 41581 """ global num_primes _sig_on if self > num_primes: P.init_primes(self + 10) if signe(self.g) != 1: return P(0) return P.new_gen(primepi(self.g)) ############################################## def _primelimit(self): """ Return the number of primes already computed in this Pari instance. EXAMPLES: sage: pari._primelimit() 500519 sage: pari.init_primes(600000) sage: pari._primelimit() 600000 """ global num_primes from sage.rings.all import ZZ return ZZ(num_primes) def prime_list(self, long n): """ prime_list(n): returns list of the first n primes