From anaaugusto2012 at bol.com.br Wed Sep 25 17:29:03 2019 From: anaaugusto2012 at bol.com.br (anaaugusto2012 at bol.com.br) Date: Wed, 25 Sep 2019 17:29:03 +0000 Subject: [web-devel] haskell memory allocation Message-ID: <5d8ba3dfaa3a7_29493f8e503724e0127291@ip-10-81-5-16.ec2.internal.mail> An HTML attachment was scrubbed... URL: From lemming at henning-thielemann.de Wed Sep 25 23:06:58 2019 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Thu, 26 Sep 2019 01:06:58 +0200 (CEST) Subject: [web-devel] haskell memory allocation In-Reply-To: <5d8ba3dfaa3a7_29493f8e503724e0127291@ip-10-81-5-16.ec2.internal.mail> References: <5d8ba3dfaa3a7_29493f8e503724e0127291@ip-10-81-5-16.ec2.internal.mail> Message-ID: On Wed, 25 Sep 2019, anaaugusto2012 at bol.com.br wrote: > I want to allocate more memory because my teacher challenged me to show > him the first 12 and last 12 digits of the expression 2 ^ 17179869184 Maybe better suited for haskell-cafe? I would be pretty waste of memory to compute the power completely. You can get the first 12 digits using approximate multiplications and you can get the last 12 digits using modulo arithmetic. It holds 17179869184 = 2^34. Prelude> mapM_ print $ take 35 $ iterate (\x -> let y = x*x in if y>=10 then y/10 else y) 2 2.0 4.0 1.6 2.5600000000000005 ... 9.274368853264574 That is, the first 12 digits should be 927436885326. Hopefully, computation was precise enough. If not, you might retry more precise computations using Integer. Prelude> mapM_ print $ take 35 $ iterate (\x -> mod (x*x) (10^12)) (2::Integer) 2 4 16 256 ... 266397474816 The last 12 digits are 266397474816. From lemming at henning-thielemann.de Wed Sep 25 23:14:26 2019 From: lemming at henning-thielemann.de (Henning Thielemann) Date: Thu, 26 Sep 2019 01:14:26 +0200 (CEST) Subject: [web-devel] haskell memory allocation In-Reply-To: References: <5d8ba3dfaa3a7_29493f8e503724e0127291@ip-10-81-5-16.ec2.internal.mail> Message-ID: On Thu, 26 Sep 2019, Henning Thielemann wrote: > On Wed, 25 Sep 2019, anaaugusto2012 at bol.com.br wrote: > >> I want to allocate more memory because my teacher challenged me to show >> him the first 12 and last 12 digits of the expression 2 ^ 17179869184 > > Maybe better suited for haskell-cafe? > > I would be pretty waste of memory to compute the power completely. > > You can get the first 12 digits using approximate multiplications and you > can get the last 12 digits using modulo arithmetic. > > It holds 17179869184 = 2^34. > > Prelude> mapM_ print $ take 35 $ iterate (\x -> let y = x*x in if y>=10 then > y/10 else y) 2 > 2.0 > 4.0 > 1.6 > 2.5600000000000005 > ... > 9.274368853264574 > > That is, the first 12 digits should be 927436885326. Hopefully, > computation was precise enough. If not, you might retry more precise > computations using Integer. Hm, computing with Integer gives a different result. Computing with 25 decimal places gives me: 927436437019 for the first 12 digits and this does not change anymore when I increase precision.