To date, my favorite Haskell finger for pi comes from Jeremy Gibbons:
pi = g(1,0,1,1,3,3) where g(q,r,t,k,n,l) = if 4*q+rt<n*t then n : g(10*q,10*(rn*t),t,k,div(10*(3*q+r))t-10*n,l) else g(q*k,(2*q+r)*l,t*l,k+1,div(q*(7*k+2)+r*l)(t*l),l+2)
The mathematical background that justifies this implementation can be found in:
Spigot Algorithm for Pi Digits
Edward KMETT
source share