Created
November 1, 2016 13:53
-
-
Save timjb/309052550d04371b24de9332575acc94 to your computer and use it in GitHub Desktop.
Approximate pi using Archimedes' method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main (main) where | |
import Control.Monad (forM_) | |
-- | Given the length l of a cord from points A to B on the unit circle, compute | |
-- the length of the cords A-C and C-B, where C is the point on the unit circle | |
-- exactly in between A and B. | |
iterArchimedes :: Double -> Double | |
iterArchimedes l = l / sqrt (2 + sqrt (4 - l*l)) | |
main :: IO () | |
main = | |
forM_ (zip [0..1000] (iterate iterArchimedes 2)) $ \(n, b_twotothen) -> | |
let bb_twotothen = 2^n * b_twotothen | |
in putStrLn ("n=" ++ show n ++ ", b_{2^n} = " ++ show b_twotothen ++ ", B_{2^n} = " ++ show bb_twotothen) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment