[Haskell-beginners] Why is it so slow to solve "10^(10^10)"?

Graham Gill math.simplex at gmail.com
Sun Sep 22 06:50:18 CEST 2013


10^(10^10) is a 1 followed by ten billion zeros. Naively evaluating that 
to an integer is going to cause time and memory problems in any software 
that supports arbitrary size integers - as Bob Ippolito said, it's going 
to take about 3.86gb just to store such a number in binary. Even math 
software (Maple) rejects an attempt to evaluate it directly - sensibly, 
the "arbitrary size" integers in Maple do have a maximum.

>     h> import Data.Number.BigFloat
>     h> ((10 :: BigFloat Eps1)^10)^10
>     1.e100
and
> If you are only solving 10^(10^10) why not construct a string with "1" 
> followed by a 100 zeroes?

10^(10^10) isn't the same as (10^10)^10, which is a 1 followed by 100 
zeros, easy to evaluate to an integer in Haskell.

Evaluating (10 :: BigFloat Eps1)^(10^10) runs into the same problems as 
10^(10^10):

Prelude> 10^(10^10)
<interactive>: out of memory
[restart]

Prelude> 10.0^(10^10)
Infinity
Prelude> 10.0**(10.0^10)
Infinity
Prelude> import Data.Number.BigFloat
Prelude Data.Number.BigFloat> (10 :: BigFloat Eps1)^(10^10)
<interactive>: out of memory

Maple> 10.0^(10^10);

Maple> 10^(10^10);
Error, operation failed. Integer exponent too large.

Graham

On 21/09/2013 10:02 PM, yi lu wrote:
> I am checking whether a number equals 10^(10^10).
>
> Yi
>
>
> On Sun, Sep 22, 2013 at 7:11 AM, KC <kc1956 at gmail.com 
> <mailto:kc1956 at gmail.com>> wrote:
>
>     Have you compared the solution to other languages?
>
>     If you are only solving 10^(10^10) why not construct a string with
>     "1" followed by a 100 zeroes?
>
>     In other words, what is this being used for?
>
>
>
>     On Sat, Sep 21, 2013 at 3:32 PM, yi lu
>     <zhiwudazhanjiangshi at gmail.com
>     <mailto:zhiwudazhanjiangshi at gmail.com>> wrote:
>
>         Why is it so slow to solve "10^(10^10)" in Haskell?
>
>         Yi
>
>         _______________________________________________
>         Beginners mailing list
>         Beginners at haskell.org <mailto:Beginners at haskell.org>
>         http://www.haskell.org/mailman/listinfo/beginners
>
>
>
>
>     -- 
>     --
>     Regards,
>     KC
>
>     _______________________________________________
>     Beginners mailing list
>     Beginners at haskell.org <mailto:Beginners at haskell.org>
>     http://www.haskell.org/mailman/listinfo/beginners
>
>
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20130922/2a7ee705/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: hegaeiid.png
Type: image/png
Size: 408 bytes
Desc: not available
URL: <http://www.haskell.org/pipermail/beginners/attachments/20130922/2a7ee705/attachment.png>


More information about the Beginners mailing list