Phil Carmody on Thu, 19 May 2005 09:22:25 +0200 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: fordiv() memory hungry |
--- Igor Schein <igor@txc.com> wrote: > On Thu, May 19, 2005 at 12:44:03AM +0200, Bill Allombert wrote: > > On Wed, May 18, 2005 at 06:01:09PM -0400, Igor Schein wrote: > > > Hi, > > > > > > (17:51:45) gp> fordiv(32!,x,0) > > > *** fordiv: the PARI stack overflows ! > > > current stack size: 256000000 (244.141 Mbytes) > > > [hint] you can increase GP stack with allocatemem() > > > > > > Looks like fordiv() is no improvement over divisors() by virtue of > > > having to create the whole static array first. Is it possible to make > > > fordiv() more memory-effcient without sacrificing the speed? > > > > Depends if you insist about having the divisors in increasing order. > > If you don't, you can use forvec() instead. > > I can't figure out how to use forvec() to obtain an unsorted list of > divisors. Is it possible? The fine manual says all you need: ? ?forvec forvec(x=v,seq,{flag=0}): v being a vector of two-component vectors of length n, the sequence is evaluated with x[i] going from v[i][1] to v[i][2] for i=n,..,1 if flag is zero or omitted. If flag = 1 (resp. flag = 2), restrict to increasing (resp. strictly increasing) sequences. Therefore x[i] would be the powers of the prime factors... ? factor(123456) %8 = [2 6] [3 1] [643 1] ? forvec(x=[[0,6],[0,1],[0,1]],print1(2^x[1]*3^x[2]*643^x[3]," ")) 1 643 3 1929 2 1286 6 3858 4 2572 12 7716 8 5144 24 15432 16 10288 48 30864 32 2 0576 96 61728 64 41152 192 123456 ? divisors(123456) %9 = [1, 2, 3, 4, 6, 8, 12, 16, 24, 32, 48, 64, 96, 192, 643, 1286, 1929, 2572, 3858, 5144, 7716, 10288, 15432, 20576, 30864, 41152, 61728, 123456] Phil () ASCII ribbon campaign () Hopeless ribbon campaign /\ against HTML mail /\ against gratuitous bloodshed [stolen with permission from Daniel B. Cristofani] __________________________________ Yahoo! Mail Mobile Take Yahoo! Mail with you! Check email on your mobile phone. http://mobile.yahoo.com/learn/mail