Last active
December 21, 2015 14:39
-
-
Save qoelet/6321060 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
-- leibniz's pi formula | |
-- a very elementary take i guess :P | |
odd_ds :: Int -> [Double] | |
odd_ds n = [x | x <- take n [1.0,3.0..]] | |
y_eq :: Double -> Double -> Double | |
y_eq d s = s * (1.0 / d) | |
leibs_series :: [Double] -> Double -> Double | |
leibs_series [] _ = 0 | |
leibs_series (d:ds) s = ((y_eq d s) + leibs_series ds (s * (-1.0))) | |
leibs_pi :: Int -> Double | |
leibs_pi 0 = 0.0 | |
leibs_pi n = 4.0 * (leibs_series (odd_ds n) (1.0)) | |
-- *Main> lebs_pi 1000 | |
-- 3.140592653839793 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment