Help with bigbnum

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

n = (2**32582656) * (2**32582657 - 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

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

···

On 5/4/07, Victor Reyes <victor.reyes@gmail.com> wrote:

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

n = (2**32582656) * (2**32582657 - 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

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

···

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

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

n = (2**32582656) * (2**32582657 - 1)

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: (2**32582656) * (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

···

On 5/4/07, Brian Candler <B.Candler@pobox.com> wrote:

On Sat, May 05, 2007 at 02:10:58AM +0900, Victor Reyes wrote:
> I am trying to use the following computation: 232582656(232582657-1)
>
> n = (2**32582656) * (2**32582657 - 1)

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

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

···

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

Jason

On 5/4/07, Victor Reyes <victor.reyes@gmail.com> wrote:

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

n = (2**32582656) * (2**32582657 - 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

The largest perfect number found to this date, if I believe website
http://amicable.homepage.dk/perfect.htm is: (2**32582656) * (2**32582657 -
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...

···

On Sat, May 05, 2007 at 04:34:01AM +0900, Victor Reyes 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

···

On 5/4/07, Mark Day <mday@mac.com> wrote:

On May 4, 2007, at 10:36 AM, Jason Roelofs 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

> Jason
>
> On 5/4/07, Victor Reyes <victor.reyes@gmail.com> wrote:
>>
>> I am trying to use the following computation: 232582656(232582657-1)
>>
>> n = (2**32582656) * (2**32582657 - 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
>>

p 2048 ** 31819 - 1024 ** 31819

or

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

···

--- Victor Reyes <victor.reyes@gmail.com> 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

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around

I said:

p 2048 ** 31819 - 1024 ** 31819

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

···

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around

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

Victor

···

On 5/4/07, Todd Benson <toddkennethbenson@yahoo.com> wrote:

I said:

> p 2048 ** 31819 - 1024 ** 31819

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

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

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.

2**32582656 == 4**16291328 == 16**8145664 ==
256**4072832 == 65536**2036416 and so on

Broken down, it's:

2**32582656 == 2**(2**10 * 3**2 * 3541) ==
( (2**(2**10))) ** (3**2) ) ** 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.

···

--- Victor Reyes <victor.reyes@gmail.com> wrote:

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

____________________________________________________________________________________
Food fight? Enjoy some healthy debate
in the Yahoo! Answers Food & Drink Q&A.
http://answers.yahoo.com/dir/?link=list&sid=396545367

# 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 }
# a**3541, which equals 2**32582656, 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.

···

--- Todd Benson <toddkennethbenson@yahoo.com> wrote:

--- Victor Reyes <victor.reyes@gmail.com> 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

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around