-- 1ª definición de aproximacionPi
aproximacionPi :: Int -> Double
aproximacionPi n = product [2 / aux x | x <- [0..n]]
where
aux 0 = 1
aux 1 = sqrt 2
aux n = sqrt (2 + aux (n-1))
-- 2ª definición de aproximacionPi
aproximacionPi2 :: Int -> Double
aproximacionPi2 n = product [2/x | x <- 1 : xs]
where xs = take n $ iterate (\x -> sqrt (2+x)) (sqrt 2)
-- 3ª definición de aproximaxionPi
aproximacionPi3 :: Int -> Double
aproximacionPi3 n = product (2 : take n (map (2/) xs))
where xs = sqrt 2 : [sqrt (2 + x) | x <- xs]
-- 1ª definición de errorPi
errorPi :: Double -> Int
errorPi x = head [n | n <- [1..]
, abs (pi - aproximacionPi n) < x]
-- 2ª definición de errorPi
errorPi2 :: Double -> Int
errorPi2 x = until aceptable (+1) 1
where aceptable n = abs (pi - aproximacionPi n) < x