Re: nth root

2009-02-02 Thread Mensanator
On Feb 2, 1:01 am, casevh wrote: > On Feb 1, 10:02 pm, Mensanator wrote: > > > > > > > On Feb 1, 8:20 pm, casevh wrote: > > > > On Feb 1, 1:04 pm, Mensanator wrote: > > > > > On Feb 1, 2:27 am, casevh wrote: > > > > > > On Jan 31, 9:36 pm, "Tim Roberts" wrote: > > > > > > > Actually, all I'm

Re: nth root

2009-02-01 Thread casevh
On Feb 1, 10:02 pm, Mensanator wrote: > On Feb 1, 8:20 pm, casevh wrote: > > > > > On Feb 1, 1:04 pm, Mensanator wrote: > > > > On Feb 1, 2:27 am, casevh wrote: > > > > > On Jan 31, 9:36 pm, "Tim Roberts" wrote: > > > > > > Actually, all I'm interested in is whether the 100 digit numbers have

Re: nth root

2009-02-01 Thread Mensanator
On Feb 1, 8:20�pm, casevh wrote: > On Feb 1, 1:04�pm, Mensanator wrote: > > > > > On Feb 1, 2:27�am, casevh wrote: > > > > On Jan 31, 9:36�pm, "Tim Roberts" wrote: > > > > > Actually, all I'm interested in is whether the 100 digit numbers have > > > > an exact integral root, or not. �At the mo

Re: nth root

2009-02-01 Thread casevh
On Feb 1, 1:04 pm, Mensanator wrote: > On Feb 1, 2:27 am, casevh wrote: > > > On Jan 31, 9:36 pm, "Tim Roberts" wrote: > > > > Actually, all I'm interested in is whether the 100 digit numbers have an > > > exact integral root, or not.  At the moment, because of accuracy > > > concerns, I'm doi

Re: nth root

2009-02-01 Thread Mensanator
On Feb 1, 2:27 am, casevh wrote: > On Jan 31, 9:36 pm, "Tim Roberts" wrote: > > > Actually, all I'm interested in is whether the 100 digit numbers have an > > exact integral root, or not.  At the moment, because of accuracy concerns, > > I'm doing something like > > >                     for ro

Re: nth root

2009-02-01 Thread Peter Pearson
On Sun, 1 Feb 2009 15:36:43 +1000, Tim Roberts wrote: > > Actually, all I'm interested in is whether the 100 digit > numbers have an exact integral root, or not. At the > moment, because of accuracy concerns, I'm doing something > like > > for root in powersp: >

Re: nth root

2009-02-01 Thread casevh
On Jan 31, 9:36 pm, "Tim Roberts" wrote: > Actually, all I'm interested in is whether the 100 digit numbers have an > exact integral root, or not.  At the moment, because of accuracy concerns, > I'm doing something like > >                     for root in powersp: >                             n

Re: nth root

2009-01-31 Thread Paul Rubin
"Tim Roberts" writes: > for root in powersp: > nroot = round(bignum**(1.0/root)) > if bignum==long(nroot)**root: > . > which is probably very inefficient

RE: nth root

2009-01-31 Thread Tim Roberts
Paul, Yes, very good, on all counts. Many thanks. Tim From: Paul Rubin [mailto:"http://phr.cx"@NOSPAM.invalid] Sent: Sun 01-Feb-09 3:53 PM To: python-list@python.org Subject: Re: nth root "Tim Roberts" writes: > Actually, a

Re: nth root

2009-01-31 Thread Paul Rubin
"Tim Roberts" writes: > Actually, all I'm interested in is whether the 100 digit numbers > have an exact integral root, or not. At the moment, because of > accuracy concerns, I'm doing something like > > for root in powersp: > nroot = round(bignum

RE: nth root

2009-01-31 Thread Tim Roberts
Actually, all I'm interested in is whether the 100 digit numbers have an exact integral root, or not. At the moment, because of accuracy concerns, I'm doing something like for root in powersp: nroot = round(bignum**(1.0/root))

Re: nth root

2009-01-31 Thread Tim Roberts
"Tim Roberts" wrote: > >Thanks - you're probably right - just my intuition said to me that rather than >calculating that the 13th root of >4021503534212915433093809093996098953996019232 >is 3221.2904208350265 >there must be a quicker way of finding out its between 3221 and 3222 > >

Re: nth root

2009-01-31 Thread Robert Kern
On 2009-01-30 22:00, Tim Roberts wrote: Unfortunately, unless I'm doing something wrong, this appears to take 20 times as long... :-) What on earth are numpy and psyco? Do I need to watch the Lord of the Rings? No, but Google would help. -- Robert Kern "I have come to believe that the whol

Re: nth root

2009-01-31 Thread Mark Dickinson
On Jan 31, 7:04 pm, ajaksu wrote: > also a great way make some innocent bystander waste his eyesight > trying to figure out the magic trick :D Oh, come on! At least I put the two lines next to each other! :-) Mark -- http://mail.python.org/mailman/listinfo/python-list

Re: nth root

2009-01-31 Thread ajaksu
On Jan 31, 12:03 pm, Mark Dickinson wrote: [...] > t1 = timeit.Timer("x = n**power", "n = > 4021503534212915433093809093996098953996019232; power = 1./13") > t2 = timeit.Timer("x = n**power", "n = > 4021503534212915433093809093996098953996019232.; power = 1./13") And by using a float literal in

Re: nth root

2009-01-31 Thread Dan Goodman
Mark Dickinson wrote: Well, random numbers is one thing. But how about the following: n = 12345**13 n 154662214940914131102165197707101295849230845947265625L int(n ** (1./13)) # should be 12345; okay 12345 int((n-1) ** (1./13)) # should be 12344; oops! 12345 Good point! Oops indeed. :

Re: nth root

2009-01-31 Thread Mark Dickinson
On Jan 31, 4:48 pm, Dan Goodman wrote: > 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. Well, random numbers is one thing. But how about the following:

Re: nth root

2009-01-31 Thread Mensanator
On Jan 31, 10:53 am, Mensanator wrote: > On Jan 31, 8:05 am, Mark Dickinson wrote: > > > On Jan 31, 1:23 pm, Steve Holden wrote: > > > > Much more significant points, given the limited precision of the doubles > > > Python will be using. Could gmpy do this better, I wonder? > > > Almost certainl

Re: nth root

2009-01-31 Thread Mensanator
On Jan 31, 8:05 am, Mark Dickinson wrote: > On Jan 31, 1:23 pm, Steve Holden wrote: > > > Much more significant points, given the limited precision of the doubles > > Python will be using. Could gmpy do this better, I wonder? > > Almost certainly, if exact results are wanted!  At least, GMP has >

Re: nth root

2009-01-31 Thread Dan Goodman
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 accura

Re: nth root

2009-01-31 Thread Mark Dickinson
On Jan 31, 1:23 pm, Steve Holden wrote: > Much more significant points, given the limited precision of the doubles > Python will be using. Could gmpy do this better, I wonder? Almost certainly, if exact results are wanted! At least, GMP has an mpz_root function; I don't know offhand whether gmpy

Re: nth root

2009-01-31 Thread Mark Dickinson
On Jan 31, 1:23 pm, Steve Holden wrote: > [Mark] > > power operation.  The integer -> float conversion is probably quite > > significant, timewise. > > I bow to your superior intuition! Here's another timing that shows the significance of the int -> float conversion: (non-debug build of the trunk

Re: nth root

2009-01-31 Thread Steve Holden
Mark Dickinson wrote: > On Jan 31, 5:43 am, "Tim Roberts" wrote: >> Dan, >> >> Thanks - you're probably right - just my intuition said to me that rather >> than calculating that the 13th root of >> 4021503534212915433093809093996098953996019232 >> is 3221.2904208350265 >> there must be a qui

Re: nth root

2009-01-31 Thread Mark Dickinson
On Jan 31, 5:43 am, "Tim Roberts" wrote: > Dan, > > Thanks - you're probably right - just my intuition said to me that rather > than calculating that the 13th root of > 4021503534212915433093809093996098953996019232 > is 3221.2904208350265 > there must be a quicker way of finding out its bet

RE: nth root

2009-01-30 Thread Tim Roberts
Tim From: Dan Goodman [mailto:dg.gm...@thesamovar.net] Sent: Sat 31-Jan-09 3:11 PM To: python-list@python.org Subject: Re: nth root Takes less than 1 sec here to do (10**100)**(1./13) a million times, and only about half as long to do (1e100)**(1./13), or abo

Re: nth root

2009-01-30 Thread Dan Goodman
Takes less than 1 sec here to do (10**100)**(1./13) a million times, and only about half as long to do (1e100)**(1./13), or about 14 times as long as to do .2**2. Doesn't look like one could hope for it to be that much quicker as you need 9 sig figs of accuracy to get the integer part of (10**1

RE: nth root

2009-01-30 Thread Tim Roberts
Unfortunately, unless I'm doing something wrong, this appears to take 20 times as long... :-) What on earth are numpy and psyco? Do I need to watch the Lord of the Rings? Tim Tim wrote: > In PythonWin I'm running a program to find the 13th root (say) of > millions of hundred-digit numbers

Re: nth root

2009-01-30 Thread MRAB
Tim wrote: In PythonWin I'm running a program to find the 13th root (say) of millions of hundred-digit numbers. I'm using n = 13 root = base**(1.0/n) which correctly computes the root to a large number of decimal places, but therefore takes a long time. All I need is the integer comp

nth root

2009-01-30 Thread Tim
In PythonWin I'm running a program to find the 13th root (say) of millions of hundred-digit numbers. I'm using n = 13 root = base**(1.0/n) which correctly computes the root to a large number of decimal places, but therefore takes a long time. All I need is the integer component. Is there