[Haskell-beginners] Why is it so slow to solve "10^(10^10)"?
Bob Ippolito
bob at redivi.com
Sun Sep 22 01:11:39 CEST 2013
Why wouldn't it be slow? Integers in Haskell are implemented with GMP, and
the representation is simply a sign, a magnitude (number of bits) and then
all of the bits. http://gmplib.org/manual/Integer-Internals.html
10^(10^10) is a very large number. With the representation that GMP uses,
it will take at least 3.86 GB of RAM to represent the bits required by the
result! Of course it takes ages to work with numbers of that magnitude.
h> ((10^10) * logBase 256 10) * (2**(-30))
3.8672332825224878
It is possible to encode values like this, but there's nothing that ships
with Haskell Platform that'll do it efficiently. You might look at the
numbers package though.
h> import Data.Number.BigFloat
h> ((10 :: BigFloat Eps1)^10)^10
1.e100
Note that the above example is trivial, only one digit of precision, but
that's all that's needed to represent this result since BigFloat is base 10.
-bob
On Sat, Sep 21, 2013 at 3:32 PM, yi lu <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
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20130921/514a27f9/attachment.htm>
More information about the Beginners
mailing list