Skip to content

Instantly share code, notes, and snippets.

@murven
Created April 5, 2011 03:07
Show Gist options
  • Save murven/902954 to your computer and use it in GitHub Desktop.
Save murven/902954 to your computer and use it in GitHub Desktop.
Leibniz formula for PI
let inverse x = 1.0/x
let inverseNext x = 1.0/(x+2.0)
let substractNextInverse x = inverse x - inverseNext x
let skip4List accuracy = [1.0 .. 4.0 .. accuracy]
let add a b = a + b
let inverses accuracy = (List.map substractNextInverse (skip4List accuracy))
let PI accuracy = (List.reduce add (inverses accuracy)) * 4.0
let pi10000000 = PI 10000000.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment