Bailey–Borwein–Plouffe Iterations

05AB1E, 63 52 50 bytes

Specialization formula

΃0NU62201122vy͹̰*8X*N>+÷+}16Xm÷+DX>£X__iÀ'.ìÁ},

Try it online!

BBP formula

ƒ4¹>°UX*8N*©>÷YX*®4+÷-1X*®5+÷-1X*®6+÷-1X*16Nm÷*ODN>£N__iÀ'.ìÁ},

Try it online!


Python 2, 109 108 bytes

def f(n):k=1;s=0;t=100**n;exec-~n*'s+=4*t/k-2*t/(k+3)-t/(k+4)-t/(k+5)>>k/2;print"3."[:k]+`s`[1:k/8+1];k+=8;'

Test it on Ideone.


Python 2, 174 Bytes

Man, this is a time when I wish that Python had some easier way of keeping infinite precision for decimals.. Possibly implementing your own infite accuracy type for this challenge is shorter but I can't imagine how. The formula is written verbatim.

from decimal import*
n=input();d=Decimal;getcontext().prec=n+2;p=d(0)
for i in range(n+1):f=8.*i;p+=d(16**(-i))*(4/d(f+1)-2/d(f+4)-1/d(f+5)-1/d(f+6));print str(p)[:-~i+(i>0)]

Example output for n=100 (with some added line numbers):

3
3.1
3.14
3.141
3.1415
3.14159
3.141592
3.1415926
3.14159265
3.141592653
3.1415926535
3.14159265358
3.141592653589
3.1415926535897
3.14159265358979
3.141592653589793
3.1415926535897932
3.14159265358979323
3.141592653589793238
3.1415926535897932384
3.14159265358979323846
3.141592653589793238462
3.1415926535897932384626
3.14159265358979323846264
3.141592653589793238462643
3.1415926535897932384626433
3.14159265358979323846264338
3.141592653589793238462643383
3.1415926535897932384626433832
3.14159265358979323846264338327
3.141592653589793238462643383279
3.1415926535897932384626433832795
3.14159265358979323846264338327950
3.141592653589793238462643383279502
3.1415926535897932384626433832795028
3.14159265358979323846264338327950288
3.141592653589793238462643383279502884
3.1415926535897932384626433832795028841
3.14159265358979323846264338327950288419
3.141592653589793238462643383279502884197
3.1415926535897932384626433832795028841971
3.14159265358979323846264338327950288419716
3.141592653589793238462643383279502884197169
3.1415926535897932384626433832795028841971693
3.14159265358979323846264338327950288419716939
3.141592653589793238462643383279502884197169399
3.1415926535897932384626433832795028841971693993
3.14159265358979323846264338327950288419716939937
3.141592653589793238462643383279502884197169399375
3.1415926535897932384626433832795028841971693993751
3.14159265358979323846264338327950288419716939937510
3.141592653589793238462643383279502884197169399375105
3.1415926535897932384626433832795028841971693993751058
3.14159265358979323846264338327950288419716939937510582
3.141592653589793238462643383279502884197169399375105820
3.1415926535897932384626433832795028841971693993751058209
3.14159265358979323846264338327950288419716939937510582097
3.141592653589793238462643383279502884197169399375105820974
3.1415926535897932384626433832795028841971693993751058209749
3.14159265358979323846264338327950288419716939937510582097494
3.141592653589793238462643383279502884197169399375105820974944
3.1415926535897932384626433832795028841971693993751058209749445
3.14159265358979323846264338327950288419716939937510582097494459
3.141592653589793238462643383279502884197169399375105820974944592
3.1415926535897932384626433832795028841971693993751058209749445923
3.14159265358979323846264338327950288419716939937510582097494459230
3.141592653589793238462643383279502884197169399375105820974944592307
3.1415926535897932384626433832795028841971693993751058209749445923078
3.14159265358979323846264338327950288419716939937510582097494459230781
3.141592653589793238462643383279502884197169399375105820974944592307816
3.1415926535897932384626433832795028841971693993751058209749445923078164
3.14159265358979323846264338327950288419716939937510582097494459230781640
3.141592653589793238462643383279502884197169399375105820974944592307816406
3.1415926535897932384626433832795028841971693993751058209749445923078164062
3.14159265358979323846264338327950288419716939937510582097494459230781640628
3.141592653589793238462643383279502884197169399375105820974944592307816406286
3.1415926535897932384626433832795028841971693993751058209749445923078164062862
3.14159265358979323846264338327950288419716939937510582097494459230781640628620
3.141592653589793238462643383279502884197169399375105820974944592307816406286208
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089
3.14159265358979323846264338327950288419716939937510582097494459230781640628620899
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986
3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280
3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348
3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253
3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421
3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170
3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679

This does seem to work for larger numbers, n=1000 runs in a couple seconds and n=10000 doesn't seem to have given me any errors yet!

Tags:

Pi

Math

Code Golf