Re: nth root



Mark Dickinson wrote:
I'd also be a bit worried about accuracy. Is it important to you
that the
integer part of the result is *exactly* right, or is it okay if
(n**13)**(1./13) sometimes comes out as slightly less than n, or if
(n**13-1)**(1./13) sometimes comes out as n?

I don't think accuracy is too big a problem here actually (at least for 13th roots). I just tested it with several hundred thousand random 100 digit numbers and it never made a mistake. The precision of double ought to easily guarantee a correct result. If you let x=int(1e100**(1./13)) then ((x+1)**13-x**13)/x**13=2.6e-7 so you only need around the first 8 or 9 digits of the 100 digit number to compute the 13th root exactly (well within the accuracy of a double).

OTOH, suppose you were doing cube roots instead then you would need the first 35 digits of the 100 digit number and this is more accurate than a double. So for example int(1e100**(1./3)) is a long way from being the integer part of the true cube root (it's between 10**18 and 10**19 away).

Dan

.



Relevant Pages

  • Re: Human calculation record - but why does he bother?
    ... numbers that have integral roots. ... A 200 digit number will have a cube root 15 digits long. ... problem is reduced to bracketing within the remaining 12 digits. ...
    (uk.philosophy.humanism)
  • Re: algorithms + data structures = programs
    ... Richard Heathfield wrote: ... Yes, okay, I agree. ... And dis the digit that will be displayed at ... Wirth ex machina again - he presumes the last digit of the representation ...
    (comp.programming)
  • Re: Well Ordering the Reals
    ... > Okay, I don;t think I understood what you were saying. ... > naturals, you might as well call it something, I suppose. ... In TO's system of "whole numbers", there is a most significant digit and ... > infinite unending string of bits, even if most are generally ignored. ...
    (sci.math)
  • Re: Calculate Last Digits
    ... Okay, I think I get it now...you're counting each of the last digits, and checking for similarity/difference between them, so in my ... you may want to consider optimizing the routine to only count each digit AS it changes. ...
    (microsoft.public.vb.general.discussion)