Opened 13 years ago

Closed 12 years ago

#4670 closed defect (fixed)

prime_pi for input ~ 10^10 causes PariError

Reported by: roed Owned by: was
Priority: minor Milestone: sage-4.3.1
Component: number theory Keywords:
Cc: Merged in: sage-4.3.1.rc1
Authors: Kevin Stueve Reviewers: Sebastian Pancratz
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description (last modified by mabshoff)

Calling the primepi function on a large pari integer (10^10) causes an error. The issue is that in sage/libs/pari/gen.pyx the function init_primes casts the input to an unsigned long. If we don't want to allow initialization with input bigger than this, we should give a better error.

sage: prime_pi(10^10)
PariError                                 Traceback (most recent call last)

/Users/Roed/Math/sage-3.2/<ipython console> in <module>()

/Users/Roed/Math/sage-3.2/local/lib/python2.5/site-packages/sage/functions/transcendental.pyc in __call__(self, x)
    363             from sage.rings.integer import Integer
    364             pari.init_primes(pari(x)+Integer(1))
--> 365             return ZZ(pari(x).primepi())
    367     def plot(self, xmin=0, xmax=100, *args, **kwds):

/Users/Roed/Math/sage-3.2/local/lib/python2.5/site-packages/sage/libs/pari/ in sage.libs.pari.gen._pari_trap (sage/libs/pari/gen.c:37972)()

PariError: impossible assignment I-->S (23)

Attachments (2)

4670.patch (432 bytes) - added by kevin.stueve 12 years ago.
added prime_pi(1010) doctest
trac4670.patch (802 bytes) - added by spancratz 12 years ago.
Only the relevant lines from Kevin's patch

Download all attachments as: .zip

Change History (8)

comment:1 Changed 13 years ago by mabshoff

  • Description modified (diff)
  • Milestone set to sage-3.2.2

comment:2 Changed 13 years ago by fwclarke

Note also #3658.

comment:3 Changed 13 years ago by boothby

ohanar is fixing this!

comment:4 Changed 12 years ago by kevin.stueve

  • Report Upstream set to N/A
  • Status changed from new to needs_review

Andrew Ohana's optimized Legendre prime_pi fixes this error. The attached patch adds prime_pi(1010) to the doctests of Andrew's code. It may still be desired to give a better error in the PARI implementation.

Kevin Stueve

Changed 12 years ago by kevin.stueve

added prime_pi(1010) doctest

comment:5 Changed 12 years ago by spancratz

  • Status changed from needs_review to positive_review

The patch above includes left overs from another patch. I'll upload a new one now.

Changed 12 years ago by spancratz

Only the relevant lines from Kevin's patch

comment:6 Changed 12 years ago by rlm

  • Authors set to Kevin Stueve
  • Merged in set to sage-4.3.1.rc1
  • Resolution set to fixed
  • Reviewers set to Sebastian Pancratz
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.