the need for 64 bits
Mensanator
mensanator at aol.com
Mon Dec 28 01:50:11 EST 2009
I routinely use large numbers in my Collatz Conjecture work.
Really large. As in a quarter million bits. You wouldn't think
that the processor would make all that much difference. But
using the number is a doddle. The real trick is getting there.
There is a limitation that few encounter. In an exponential, the
exponent is limited to 32 bits, else you get an "outrageous
exponent" error. But I assume that was due to integer size,
that if you have 64 bit integers, the limit of the exponent
ought to also be 64 bits.
With my new MacBook replacing my old Windows laptop,
I can try this.
Using this function (which grows really large, really quick)...
def Type12MH(k,i):
"""Find ith, kth Generation Type [1,2] Mersenne Hailstone
using the closed form equation
Type12MH(k,i)
k: generation
i: member of generation
returns Hailstone (a)
"""
ONE = gmpy.mpz(1)
TWO = gmpy.mpz(2)
SIX = gmpy.mpz(6)
NIN = gmpy.mpz(9)
if (k<1) or (i<1): return 0
i = gmpy.mpz(i)
k = gmpy.mpz(k)
# a = (i-1)*9**(k-1) + (9**(k-1) - 1)//2 + 1
# return 2**(6*a - 1) - 1
a = (i-ONE)*NIN**(k-ONE) + (NIN**(k-ONE) - ONE)//TWO + ONE
return TWO**(SIX*a - ONE) - ONE
i: 1 bits: 5 decimals: 2
i: 2 bits: 29 decimals: 9
i: 3 bits: 245 decimals: 74
i: 4 bits: 2,189 decimals: 659
i: 5 bits: 19,685 decimals: 5,926
i: 6 bits: 177,149 decimals: 53,328
i: 7 bits: 1,594,325 decimals: 479,940
i: 8 bits: 14,348,909 decimals: 4,319,453
i: 9 bits: 129,140,165 decimals: 38,875,064
i: 10 bits: 1,162,261,469 decimals: 349,875,565
… my Windows/32-bit machine can't get past generation 10 without
getting "outrageous exponent".
But with a 64-bit processor, that limitation no longer stops me.
i: 11 bits: 10,460,353,205 decimals: 3,148,880,080
i: 12 bits: 94,143,178,829 decimals: 28,339,920,715
Wow! 94 billion bits! 28 billion decimal digits!
Of course, once one wall falls, you get to go up against the next
one.
For generation 13, I get:
gmp: overflow in mpz type
Abort trap
Hmm, not sure what "overflow" means in this context, but I suspect
it ran out of memory, I probably should have gotten the MacBook Pro
with 8 GB of ram. But then, maybe it wouldn't help.
Regardless, my window of research has gotten slightly larger.
More information about the Python-list
mailing list