Skip to content

Instantly share code, notes, and snippets.

@Mizzlr
Created June 14, 2016 12:48
Show Gist options
  • Select an option

  • Save Mizzlr/6945bd6d447e35e7e0a0dd96b006aee2 to your computer and use it in GitHub Desktop.

Select an option

Save Mizzlr/6945bd6d447e35e7e0a0dd96b006aee2 to your computer and use it in GitHub Desktop.
module Main where
-- recursive square root function
rsqrt x n = if n == 1 then sqrt x else sqrt (x + rsqrt x (n-1))
-- product expansion of pi upto n terms
productPi n = 2 * product [ 2 / (rsqrt 2 i) | i <-[1..n]]
main = do
putStr "Actual value of pi: "
print pi
putStrLn "Product expansion upto n terms:"
putStrLn $ show 1 ++ " --> " ++ show (productPi 1)
putStrLn $ show 2 ++ " --> " ++ show (productPi 2)
putStrLn $ show 3 ++ " --> " ++ show (productPi 3)
putStrLn $ show 4 ++ " --> " ++ show (productPi 4)
putStrLn $ show 5 ++ " --> " ++ show (productPi 5)
putStrLn $ show 10 ++ " --> " ++ show (productPi 10)
putStrLn $ show 100 ++ " --> " ++ show (productPi 100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment