Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Re: List operations (Alex Rozenshteyn)
2. Re: List operations (Daniel Fischer)
3. For Euler 25; What is the first term in the Fibonacci
sequence to contain 1000 digits?; the following seems to work. (KC)
4. glfw cabal install mac osX (Britt Anderson)
5. Worth repeating Daniel's comment: Don't benchmark in ghci,
use compiled code. (KC)
6. Re: glfw cabal install mac osX (Daniel Fischer)
7. Re: [Haskell-cafe] For Euler 25; What is the first term in
the Fibonacci sequence to contain 1000 digits?; the following
seems to work. (KC)
8. Re: [Haskell-cafe] For Euler 25; What is the first term in
the Fibonacci sequence to contain 1000 digits?; the following
seems to work. (Felipe Almeida Lessa)
----------------------------------------------------------------------
Message: 1
Date: Thu, 19 May 2011 13:02:58 -0400
From: Alex Rozenshteyn <[email protected]>
Subject: Re: [Haskell-beginners] List operations
To: Ertugrul Soeylemez <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"
Damn it... Forget my last email. I confused iterate with replicate for a
second...
On Thu, May 19, 2011 at 1:01 PM, Alex Rozenshteyn <[email protected]>wrote:
> You're not applying the operation 1000000 times, you're traversing to the
> 1000000th node in the list and applying the operation once. Laziness never
> evaluates the other thunks.
>
>
> On Thu, May 19, 2011 at 12:15 PM, Ertugrul Soeylemez <[email protected]> wrote:
>
>> Daniel Fischer <[email protected]> wrote:
>>
>> > However, since you're asking about cost, which indicates that you care
>> > for performance, the above would be better written as
>> >
>> > [x*x*x | x <- list]
>> >
>> > unless you depend on the small differences in the outcome [I'm not
>> > quite sure how many bits may be affected, not many, typically none or
>> > one]. Functions like (**), exp, log, sin, cos, ... are slow, very
>> > slow. If the exponent is a small (positive) integer, specifically
>> > giving a sequence of multiplication steps is much faster, also using
>> > (^) instead of (**) is faster for small exponents (but slower than an
>> > explicit multiplication sequence).
>>
>> Neither does this really match my intuition, nor can I confirm it with
>> an experiment. Applying (** 3) a million times to a Double takes a
>> second and gives me the expected Infinity. Applying (^3) or (\x ->
>> x*x*x) a million times to the same value, well, I didn't want to wait
>> for it to finish.
>>
>> The experiment was ran with the following codes in GHCi:
>>
>> iterate (** 3) 1.000000001 !! 1000000
>> iterate (^3) 1.000000001 !! 1000000
>> iterate (\x -> x*x*x) 1.000000001 !! 1000000
>>
>> Note that exponentiation is a cheap operation on Double.
>>
>>
>> Greets
>> Ertugrul
>>
>>
>> --
>> nightmare = unsafePerformIO (getWrongWife >>= sex)
>> http://ertes.de/
>>
>>
>>
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>
>
>
> --
> Alex R
>
>
--
Alex R
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20110519/c4188039/attachment-0001.htm>
------------------------------
Message: 2
Date: Thu, 19 May 2011 19:19:57 +0200
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] List operations
To: [email protected]
Cc: Ertugrul Soeylemez <[email protected]>
Message-ID: <[email protected]>
Content-Type: Text/Plain; charset="iso-8859-1"
On Thursday 19 May 2011 18:15:31, Ertugrul Soeylemez wrote:
> Daniel Fischer <[email protected]> wrote:
> > However, since you're asking about cost, which indicates that you care
> > for performance, the above would be better written as
> >
> > [x*x*x | x <- list]
> >
> > unless you depend on the small differences in the outcome [I'm not
> > quite sure how many bits may be affected, not many, typically none or
> > one]. Functions like (**), exp, log, sin, cos, ... are slow, very
> > slow. If the exponent is a small (positive) integer, specifically
> > giving a sequence of multiplication steps is much faster, also using
> > (^) instead of (**) is faster for small exponents (but slower than an
> > explicit multiplication sequence).
>
> Neither does this really match my intuition,
A multiplication takes ~1 clock cycle, calling out to pow takes way more (I
confess, I don't know how many clock cycles a function call takes).
> nor can I confirm it with
> an experiment. Applying (** 3) a million times to a Double takes a
> second and gives me the expected Infinity. Applying (^3) or (\x ->
> x*x*x) a million times to the same value, well, I didn't want to wait
> for it to finish.
>
> The experiment was ran with the following codes in GHCi:
Don't benchmark in ghci, use compiled code.
>
> iterate (** 3) 1.000000001 !! 1000000
> iterate (^3) 1.000000001 !! 1000000
> iterate (\x -> x*x*x) 1.000000001 !! 1000000
>
> Note that exponentiation is a cheap operation on Double.
>
{-# LANGUAGE BangPatterns #-}
module Main (main) where
import Criterion.Main
main :: IO ()
main = defaultMain
[ bench "multiply" (whnf (test (\x -> x*x*x)) 10000)
, bench "power" (whnf (test (\x -> x**3)) 10000)
, bench "intPower" (whnf (test (^ (3 :: Int))) 10000)
]
test :: (Double -> Double) -> Int -> Double
test fun k = go k 0 (fromIntegral k)
where
go :: Int -> Double -> Double -> Double
go 0 !acc !d = acc
go j acc d = go (j-1) (acc + fun d) (d-1)
benchmarking multiply
collecting 100 samples, 20 iterations each, in estimated 727.8770 ms
bootstrapping with 100000 resamples
mean: 367.1096 us, lb 366.0110 us, ub 370.5876 us, ci 0.950
std dev: 11.04278 us, lb 2.089208 us, ub 22.41965 us, ci 0.950
found 5 outliers among 100 samples (5.0%)
4 (4.0%) high severe
variance introduced by outliers: 0.998%
variance is unaffected by outliers
benchmarking power
collecting 100 samples, 3 iterations each, in estimated 767.6125 ms
bootstrapping with 100000 resamples
mean: 2.322663 ms, lb 2.318265 ms, ub NaN s, ci 0.950
std dev: 106.4797 us, lb 52.31957 us, ub NaN s, ci 0.950
found 7 outliers among 100 samples (7.0%)
6 (6.0%) high severe
variance introduced by outliers: 0.999%
variance is unaffected by outliers
benchmarking intPower
collecting 100 samples, 8 iterations each, in estimated 775.3134 ms
bootstrapping with 100000 resamples
mean: 798.4662 us, lb 794.1207 us, ub 806.9849 us, ci 0.950
std dev: 31.24913 us, lb 17.17793 us, ub 59.85220 us, ci 0.950
found 7 outliers among 100 samples (7.0%)
4 (4.0%) high mild
3 (3.0%) high severe
variance introduced by outliers: 0.999%
variance is unaffected by outliers
>
> Greets
> Ertugrul
------------------------------
Message: 3
Date: Thu, 19 May 2011 10:29:27 -0700
From: KC <[email protected]>
Subject: [Haskell-beginners] For Euler 25; What is the first term in
the Fibonacci sequence to contain 1000 digits?; the following seems to
work.
To: haskell-cafe <[email protected]>, [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
For Euler 25; What is the first term in the Fibonacci sequence to
contain 1000 digits?; the following seems to work.
-- For number of digits being 5 or more.
fibNdigits :: Int -> Int
fibNdigits nDigits = floor (((fromIntegral nDigits) - 1.0) / (logBase
10 phi)) + 2
where
sq5 = sqrt 5 :: Double
phi = (1 + sq5) / 2
--
--
Regards,
KC
------------------------------
Message: 4
Date: Thu, 19 May 2011 13:31:11 -0400
From: Britt Anderson <[email protected]>
Subject: [Haskell-beginners] glfw cabal install mac osX
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
I have just installed the haskell platform on a mac running 10.6 OSX. Using
cabal install glfw fails. Who would I write and what data should I include to
try and get some help to fix the problem?
Thank you.
------------------------------
Message: 5
Date: Thu, 19 May 2011 10:35:25 -0700
From: KC <[email protected]>
Subject: [Haskell-beginners] Worth repeating Daniel's comment: Don't
benchmark in ghci, use compiled code.
To: [email protected], [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
Worth repeating Daniel's comment.
Don't benchmark in ghci, use compiled code.
--
--
Regards,
KC
------------------------------
Message: 6
Date: Thu, 19 May 2011 20:06:04 +0200
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] glfw cabal install mac osX
To: [email protected]
Cc: Britt Anderson <[email protected]>
Message-ID: <[email protected]>
Content-Type: Text/Plain; charset="iso-8859-1"
On Thursday 19 May 2011 19:31:11, Britt Anderson wrote:
> I have just installed the haskell platform on a mac running 10.6 OSX.
> Using cabal install glfw fails. Who would I write and what data should
> I include to try and get some help to fix the problem? Thank you.
What error message did cabl give? You may need to tell cabal to be more
verbose if the standard verbosity doesn't give much information.
If you paste the output a hpaste.org and ask in #haskell (IRC channel,
freenode.net), you'll likely find somebody there who knows what's going
wrong.
------------------------------
Message: 7
Date: Thu, 19 May 2011 13:00:16 -0700
From: KC <[email protected]>
Subject: Re: [Haskell-beginners] [Haskell-cafe] For Euler 25; What is
the first term in the Fibonacci sequence to contain 1000 digits?; the
following seems to work.
To: Sebastian Fischer <[email protected]>, [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
Project Euler wants the term number not the actual Fibonacci number.
I wonder what the compiled timings would be. :)
On Thu, May 19, 2011 at 11:34 AM, Sebastian Fischer <[email protected]> wrote:
>
> On Thu, May 19, 2011 at 7:29 PM, KC?<[email protected]>?wrote:
>>
>> For Euler 25; What is the first term in the Fibonacci sequence to
>> contain 1000 digits?; the following seems to work.
>>
>>
>> -- For number of digits being 5 or more.
>> fibNdigits :: Int -> Int
>> fibNdigits nDigits = floor (((fromIntegral nDigits) - 1.0) / (logBase
>> 10 phi)) + 2
>> ?where
>> ? ?sq5 = sqrt 5 :: Double
>> ? ?phi = (1 + sq5) / 2
>
>
> (length . show) is fast enough for me. The following gives the answer in a
> fraction of a second.
> # cabal install fibonacci
> # ghci
> ghci> import Data.Numbers.Fibonacci
> ghci> head . filter ((==1000) . length . show) $ map fib [0..]
> 1070066266382758936764980584457396885083683896632151665013235203375314520604694040621889147582489792657804694888177591957484336466672569959512996030461262748092482186144069433051234774442750273781753087579391666192149259186759553966422837148943113074699503439547001985432609723067290192870526447243726117715821825548491120525013201478612965931381792235559657452039506137551467837543229119602129934048260706175397706847068202895486902666185435124521900369480641357447470911707619766945691070098024393439617474103736912503231365532164773697023167755051595173518460579954919410967778373229665796581646513903488154256310184224190259846088000110186255550245493937113651657039447629584714548523425950428582425306083544435428212611008992863795048006894330309773217834864543113205765659868456288616808718693835297350643986297640660000723562917905207051164077614812491885830945940566688339109350944456576357666151619317753792891661581327159616877487983821820492520348473874384736771934512787029218636250627816
>
--
--
Regards,
KC
------------------------------
Message: 8
Date: Thu, 19 May 2011 17:04:20 -0300
From: Felipe Almeida Lessa <[email protected]>
Subject: Re: [Haskell-beginners] [Haskell-cafe] For Euler 25; What is
the first term in the Fibonacci sequence to contain 1000 digits?; the
following seems to work.
To: KC <[email protected]>
Cc: [email protected], Sebastian Fischer <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8
On Thu, May 19, 2011 at 5:00 PM, KC <[email protected]> wrote:
> Project Euler wants the term number not the actual Fibonacci number.
Just put the mapped function 'fib' inside the filter =).
head . filter ((==1000) . length . show . fib) [0..]
Cheers,
--
Felipe.
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 35, Issue 39
*****************************************