Help with bigbnum


#1

I am trying to use the following computation: 232582656(232582657-1)

n = (232582656) * (232582657 - 1)

I am getting the msg:

perf.rb:5: warning: in a**b, b may be too big Infinity

Any help will be appreciated.

Thank you

Victor


#2

You do realize the magnitude of number you’re trying to calculate? There
IS
a limit to how big even BigNum can go before deciding to crap out. I’d
like
to see someone try this in Lisp. If that interpreter can’t handle it,
then
no language can.

Jason


#3

On Sat, May 05, 2007 at 02:10:58AM +0900, Victor R. wrote:

I am trying to use the following computation: 232582656(232582657-1)

n = (232582656) * (232582657 - 1)

Homework question? Brute force probably isn’t the way :slight_smile:


#4

Brian,

Actually, NO. This is not a homework questions. It is, however and
unfortunately, an issue of my deficiency and lack of knowledge of the
language.
For pure and simple intellectual curiosity, I am attempting to write a
ruby
pgm to find perfect numbers.
The largest perfect number found to this date, if I believe website
http://amicable.homepage.dk/perfect.htm is: (232582656) *
(2
32582657 -
1).
Been the neophyte that I am, I thought about picking it up from there
and
play with it, since I have at my disposal a very large IBM
multiprocessor
environment.
I know that Brute force is not the way, but I don’t have a nice
algorithm to
use.

Thank you

Victor


#5

On May 4, 2007, at 10:36 AM, Jason R. wrote:

You do realize the magnitude of number you’re trying to calculate?
There IS
a limit to how big even BigNum can go before deciding to crap out.
I’d like
to see someone try this in Lisp. If that interpreter can’t handle
it, then
no language can.

Python 2.5 appears to have handled the expression easily enough (3-4
seconds on my iMac Intel Core Duo). Converting it to a string for
display seems to be taking quite a long time, which isn’t too
surprising since it should have nearly 2 million decimal digits
(according to log10(n)).

-Mark


#6

For the record, I am running ruby 1.86 under AIX 5.3.
If the answer is that it can be done on Ruby, that’s an OK answer also.
If
this is the case, I start playing with Python, at least for this
problem.

Thanks

Victor


#7

On Sat, May 05, 2007 at 04:34:01AM +0900, Victor R. wrote:

The largest perfect number found to this date, if I believe website
http://amicable.homepage.dk/perfect.htm is: (232582656) * (232582657 -
1).

Then that’s the number, represented in a compact form.

I know that Brute force is not the way, but I don’t have a nice algorithm to
use.

But what are you trying to achieve? Simply to display this number in its
direct decimal form?

If my rusty maths is correct, that number is a little under
2**(32582656 + 32582657)

which is roughly 10 ** ( (32582656 + 32582657) * log(2)/log(10) )
~= 10 ** 19616713

So there are nearly 20 million digits in the answer…


#8

— Victor R. removed_email_address@domain.invalid wrote:

For the record, I am running ruby 1.86 under AIX
5.3.
If the answer is that it can be done on Ruby, that’s
an OK answer also. If
this is the case, I start playing with Python, at
least for this problem.

Thanks

Victor

p 2048 ** 31819 - 1024 ** 31819

or

a = 1
32582656.times { a *= 2 }
b = a
32582656.times { b *= 2 }
p b - a


#9

Todd, thank you for the example. I truly appreciate it. I’ll give it a
try.

Victor


#10

I said:

p 2048 ** 31819 - 1024 ** 31819

Oops. Ignore this one. I don’t know what I was
thinking :slight_smile:


#11

— Todd B. removed_email_address@domain.invalid wrote:

— Victor R. removed_email_address@domain.invalid wrote:

Todd, thank you for the example. I truly
appreciate
it. I’ll give it a try.

Don’t get too excited. On my system (2.4GHz Intel),
it looks like it would take about 2.5 hours to
compute

The next 3 lines compute 2**32582656 in less than a

minute on my system:

a = 2 ** (2**10 * 9)
b = 1
3541.times { b*=a }

a3541, which equals 232582656, will fail to

execute in ruby, but the 3541.times works

this next line, however,

s = b.to_s

takes a very long time

similar (but much longer, I think) to Python’s

rendering of b into a string.


#12

— Victor R. removed_email_address@domain.invalid wrote:

Todd, thank you for the example. I truly appreciate
it. I’ll give it a try.

Don’t get too excited. On my system (2.4GHz Intel),
it looks like it would take about 2.5 hours to compute
(I didn’t test it to see if it would even work).
Also, it is most likely faster to multiply by larger
numbers than 2.

232582656 == 416291328 == 168145664 ==
256
4072832 == 65536**2036416 and so on

Broken down, it’s:

232582656 == 2(210 * 32 * 3541) ==
( (2**(210))) ** (32) ) ** 3541

I’m guessing now matter how you cut it up, you will
get the same error, though :frowning: Maybe ruby chokes at
around a million digits.