Opened 11 years ago

Closed 11 years ago

#12105 closed defect (fixed)

RuntimeError: Segmentation fault with nth_root

Reported by: lfousse Owned by: jason, jkantor
Priority: major Milestone: sage-5.0
Component: numerical Keywords:
Cc: Merged in: sage-5.0.beta3
Authors: Johan Bosman Reviewers: Karl-Dieter Crisman
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

GitHub link to the corresponding issue

Description (last modified by johanbosman)

sage: RealField(53)(0.05).nth_root(7 * 10^8)
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)

/opt/sage-4.7.2/<ipython console> in <module>()

/opt/sage-4.7.2/local/lib/python2.6/site-packages/sage/rings/real_mpfr.so in sage.rings.real_mpfr.RealNumber.nth_root (sage/rings/real_mpfr.c:23889)()

RuntimeError: Segmentation fault

Apply 12105.patch to the Sage repository.

Attachments (1)

12105.patch (1.3 KB) - added by johanbosman 11 years ago.

Download all attachments as: .zip

Change History (7)

comment:1 Changed 11 years ago by johanbosman

The bug is in line 4708 of sage/rings/real_mpfr.pyx:

        if algorithm == 0 and fld.__prec * n < 10000:

The result of that multiplication as a signed int may become negative and actually does so in your example.

Changed 11 years ago by johanbosman

Attachment: 12105.patch added

comment:2 Changed 11 years ago by johanbosman

Authors: Johan Bosman
Description: modified (diff)
Milestone: sage-4.8
Status: newneeds_review

comment:3 Changed 11 years ago by kcrisman

Reviewers: Karl-Dieter Crisman

On Mac I don't get an error, but it hangs and eventually consumes all resources, so fair enough!

This patch gives

sage: timeit("RealField(53)(0.05).nth_root(7 * 10^8)")
625 loops, best of 3: 69.2 µs per loop

One question I have is whether this is the most appropriate test with this precision.

sage: RealField(53)(0.05).nth_root(7 * 10^8) 
0.999999995720382
sage: _^(7*10^8)
0.0499999991341384

Is that good enough?

Otherwise this is fine, passes tests, etc. on 5.0.beta1.

comment:4 Changed 11 years ago by johanbosman

It'll be difficult to get a more accurate answer with that precision. Let's turn the last 2 into a 3:

sage: 0.999999995720383^(7*10^8)
0.0500000185630449

comment:5 in reply to:  4 Changed 11 years ago by kcrisman

Status: needs_reviewpositive_review

It'll be difficult to get a more accurate answer with that precision.

Well, that's what I figured, but I'm not a numerical analysis expert. Thanks.

Positive review.

comment:6 Changed 11 years ago by jdemeyer

Merged in: sage-5.0.beta3
Resolution: fixed
Status: positive_reviewclosed
Note: See TracTickets for help on using tickets.