123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533 |
- #!/usr/bin/ruby
- # Daniel "Trizen" Șuteu
- # Date: 10 July 2017
- # https://github.com/trizen
- # A collection of formulas for common mathematical constants.
- const n = (ARGV ? Num(ARGV[0]) : 30) # number of iterations
- define ℯ = Num.e
- define π = Num.pi
- define γ = Num.EulerGamma
- define C = Num.C
- func display(r, t) {
- say "#{r}\terror: #{ '%.0g' % abs(r - t) }"
- }
- #
- ## zeta(3)
- #
- say "=> zeta(3)"
- # Accelerating series for zeta(3), due to Apery.
- display(5/2 * sum(1..n, {|n|
- (-1)**(n-1) / n**3 / binomial(2*n, n)
- }), zeta(3))
- # Accelerating series for zeta(3), due to Gosper (1976)
- display(sum(1..n, {|n|
- (30*n - 11) / 16 / (2*n - 1) / n**3 / binomial(2*n - 1, n)**2
- }), zeta(3))
- # Accelerating series for zeta(3), due to Gosper (1976).
- display(π * sum(1..n, {|n|
- (30*n - 11) * Γ(n)**2 / n / (2*n - 1)**3 / Γ(n - 1/2)**2 / 16**n
- }), zeta(3))
- # A formula due to Ewell for zeta(3)
- display(-(π**2 / 3) * sum(0..^n, {|n|
- (2*n + 5) * zeta(2*n) / (2*n + 1) / (2*n + 2) / (2*n + 3) / 2**(2*n)
- }), zeta(3))
- # A formula related to one found by Ewell for zeta(3)
- display(sum(0..^n, {|n|
- zeta(2*n) / (2*n + 1) / (2*n + 2) / 2**(2*n)
- }) * -(4 * π**2)/7, zeta(3))
- # A formula related to one found by Ewell for zeta(3), with convergence improved by the author.
- display((log(27/16) + sum(0..^n, {|n|
- (zeta(2*n) - 1) / (2*n + 1) / (2*n + 2) / 2**(2*n)
- })) * -(4 * π**2)/7, zeta(3))
- # Formula due to Cezar Lupu and Derek Orr for zeta(3) (with good convergence)
- display((4 * π**2 / 35) * (3/2 - log(π/2) + sum(1..n, {|n|
- zeta(2*n) / n / (n + 1) / (2*n + 1) / 16**n
- })), zeta(3))
- # Formula due to Cezar Lupu and Derek Orr for zeta(3) (with very good convergence)
- display((2 * π**2 / 35) * (9 + 138*log(2) - 18*log(3) - 50*log(5) - 2*log(π) + 2*sum(1..n, {|n|
- (zeta(2*n) - 1) / n / (2*n + 1) / (n + 1) / 16**n
- })), zeta(3))
- # Formula involving the Catalan constant
- display((4 * π**2 / 35) * (1/2 + (2*C / π) - sum(1..n, {|n|
- zeta(2*n) / (n + 1) / (2*n + 1) / 16**n
- })), zeta(3))
- # Formula due to Strivastava, Glasser and Adamchik
- display((2 * π**2 / 9) * (log(2) + 2*sum(0..^n, {|n|
- zeta(2*n) / (2*n + 3) / 4**n
- })), zeta(3))
- # Formula due to Euler
- display(prod(1..n, {|n|
- 1/(1 - prime(n)**(-3))
- }), zeta(3))
- # Formula due to Doron Zeilberger
- display(1/2 * sum(1..n, {|n|
- (-1)**(n-1) * (205 * n**2 - 160*n + 32) / n**5 / binomial(2*n, n)**5
- }), zeta(3))
- #
- ## Pi
- #
- say "\n=> Pi"
- # Famous series of Srinivasa Ramanujan for 1/Pi
- display(1/(2 * sqrt(2) / 9801 * sum(0..^n, {|n|
- (4*n)! * (1103 + 26390*n) / (n!)**4 / 396**(4*n)
- })), π)
- # Formula due to Srinivasa Ramanujan for 1/Pi
- display(1/sum(0..^n, {|n|
- binomial(2*n, n)**3 * (42*n + 5) / 2**(12*n + 4)
- }), π)
- # The Ramanujan series for 1/π, improved by David and Gregory Chudnovsky
- display(1/(12/(640320**(3/2)) * sum(0..^n, {|n|
- (-1)**n * (6*n)! * (13591409 + n*545140134) / ((3*n)!) / (n!)**3 / 640320**(3*n)
- })), π)
- # Formula due to Cezar Lupu and Derek Orr, involving zeta(2n)
- display(exp(1 + sum(1..n, {|n|
- zeta(2*n) / n / (2*n + 1) / 4**n
- })), π)
- # Formula due to Cezar Lupu and Derek Orr, involving zeta(2n)
- display(sqrt(8 * (1/2 + sum(1..n, {|n|
- zeta(2*n) * (2*n - 1) / 4**n
- }))), π)
- # Formula due to Cezar Lupu and Derek Orr, involving zeta(2n)
- display(sqrt(16 * sum(1..n, {|n|
- zeta(2*n) * n / 4**n
- })), π)
- # Formula due to Cezar Lupu and Derek Orr, involving zeta(2n)
- display(sqrt(32/3 * sum(1..n, {|n|
- zeta(2*n) * n**2 / 4**n
- })), π)
- # Formula due to Cezar Lupu and Derek Orr, involving zeta(2n)
- display(2*sqrt(2)*exp(sum(1..n, {|n|
- zeta(2*n) / n / 16**n
- })), π)
- # Formula due to Cezar Lupu and Derek Orr, involving zeta(2n)
- display(sqrt(16 * (1/2 + sum(1..n, {|n|
- zeta(2*n) * (2*n - 1) / 16**n
- }))), π)
- # Formula due to Cezar Lupu and Derek Orr, involving zeta(2n) (corrected by the author)
- display(cbrt(32 * (1 - sum(1..n, {|n|
- zeta(2*n) * (2*n - 1) * (2*n - 2) / 16**n
- }))), π)
- # Formula due to Cezar Lupu and Derek Orr, involving zeta(2n)
- display(4 - (8 * sum(1..n, {|n|
- zeta(2*n) / 16**n
- })), π)
- # Formula for Pi^2, independently discovered by Oyama Shokei and Yamaji Nushizumi (~1765).
- display(sqrt(8*(1 + sum(1..n, {|n|
- 2**(n+1) * (n!)**2 / (2*n + 2)!
- }))), π)
- # Formula due to Ajima Naonobu (1795) (rediscovered by the author).
- display(2 * sum(0..^n, {|n|
- (n!) / (2*n + 1)!!
- }), π)
- # Formula due to Euler (?)
- display(sqrt(8 * sum(0..^n, {|n|
- 1 / (2*n + 1)**2
- })), π)
- # Wallis' product (1)
- display(2 * prod(1..n, {|n|
- (4 * n**2) / (4 * n**2 - 1)
- }), π)
- # Wallis'product (2)
- display(4*prod(1..n, {|n|
- ((2*n + 1)**2 - 1) / (2*n + 1)**2
- }), π)
- # Wallis'product (3)
- display((2*prod(1..n, {|n|
- (4 * n**2) / (4 * n**2 - 1)
- }) + 4*prod(1..n, {|n|
- ((2*n + 1)**2 - 1) / (2*n + 1)**2
- })) / 2, π)
- # Formula (re?)discovered by the author.
- display(prod(1..n, {|n|
- (4 * n**3) / ((4 * n**3) - 3*n + 1)
- }), π)
- # Formula (re?)discovered by the author.
- display(3/2 * sqrt(3) * sum(0..^n, {|n|
- (n!)**2 / (2*n + 1)!
- }), π)
- # Formula (re?)discovered by the author.
- display(sqrt(6 * (2 - sum(1..n, {|n|
- 1/(n * (n+1)**2)
- }))), π)
- # Formula (re?)discovered by the author.
- display(6 * (-log(2) + sum(0..^n, {|n|
- 1/(n + (2*n + 1)**2)
- })), π)
- # Spigot algorithm for Pi
- display(sum(0..^n, {|n|
- (-1/4)**n * (1/(2*n + 1) + 2/(4*n + 1) + 1/(4*n + 3))
- }), π)
- # beta(3)
- display(cbrt(32 * sum(0..^n, {|n|
- (-1)**n / (2*n + 1)**3
- })), π)
- # Based on Stirling's asymptotic formula for n!
- display((n!)**2 * exp(2*n) / n**(2*n + 1) / 2, π)
- # Based on Stirling's asymptotic formula for n!, with (1 + 1/n)^n for e
- display((ℯ * ((-n - 1)**(-n) * (-n)**n * n)**(-2*n) * (n!)**2)/(2*n), π)
- # Based on Stirling's asymptotic formula for n!, with ((n+1)/(n-1))^(n/2) for e
- display(((n * ((n + 1)/(n - 1))**(-n/2))**(-2*n) * (n!)**2)/(2*n), π)
- # Limit derived by the author from gamma(1/2).
- display(4 * 16**n * n * (n!)**4 / ((2*n + 1)!)**2, π)
- # Limit derived by the author from gamma(1/2).
- display(4 * 2**(4*n - 1) * (n!)**4 / (2*n + 1) / ((2*n)!)**2, π)
- # Limit derived by the author from gamma(1/2).
- display(2 * 4**n * (n!)**2 / ((2*n - 1)!!) / ((2*n + 1)!!), π)
- # Limit derived by the author from gamma(1/2).
- display(4 * 16**n * (n!)**3 * ((n+1)!) / ((2*n + 1)!)**2, π)
- # Limit derived by the author from gamma(1/2).
- display(16**n * (n!)**3 * ((n-1)!) / ((2*n)!)**2, π)
- # Limit derived by the author from gamma(1/2).
- display(sqrt(16 * 256**n * n * ((n+1)!) * (n!)**7 / ((2*n + 1)!)**4), π)
- # Limit derived by the author from gamma(1/2).
- display(sqrt(128 * 256**n * (n + 1)**4 * ((2 * n**2) + 2*n + 1) * (n!)**8 / ((2*n + 2)!)**4), π)
- # Formula due to S. M. Abrarov and B. M. Quine.
- # Described in their paper: "A reformulated series expansion of the arctangent function"
- display(-8 * sum(1..n, {|n|
- sum(1..(2*n - 1), {|k|
- (-1)**k / (2*n - 1) / (1 + (1**2 / 4))**(2*n - 1) * (1/2)**(4*n - 2*k - 1) * binomial(2*n - 1, 2*k - 1)
- })
- }), π)
- # Formula (re?)discovered by the author.
- display(sqrt(12 * (sum(1..n, {|n|
- 1 / n**2 / 2**n
- }) + (log(2)**2 / 2))), π)
- # Formula (re?)discovered by the author (equivalent with the above formula).
- display(sqrt(6 * (sum(1..n, {|n|
- 1 / n**2 / 2**(n-1)
- }) + log(2)**2)), π)
- # The gamma function at 1/2, which is sqrt(π).
- display((exp(γ/2)/2 * prod(1..n, {|n|
- (1 + 1/(2*n)) * exp(-1/(2*n))
- }))**(-2), π)
- # Formula due to Abraham Sharp (1699)
- display(sum(0..^n, {|n|
- (-1)**n / 3**n / (2*n + 1)
- }) / sqrt(3) * 6, π)
- # Formula due to John Machin (1706)
- display(4*(4*sum(0..^n, {|n|
- (-1)**n / (2*n + 1) / 5**(2*n + 1)
- }) - sum(0..^n, {|n|
- (-1)**n / (2*n + 1) / 239**(2*n + 1)
- })), π)
- # Formula due to Matsunaga Yoshisuke (1739)
- display(sqrt(18*sum(0..^n, {|n|
- n!**2 / (2*n + 2)!
- })), π)
- # Formula due to Euler
- display(sqrt(18*sum(1..n, {|n|
- n**(-2) / binomial(2*n, n)
- })), π)
- # Formula due to Newton, based on arcsin(1/2) = π/6
- display(6 * (1/2 + sum(1..n, {|n|
- ((2*n - 1)!!) / (2*n + 1) / ((2*n)!!) / 2**(2*n + 1)
- })), π)
- # Formula due to N. J. Wildberger (2012)
- display(do {
- sqrt(2 - func (n) {
- n > 0 ? sqrt(2 + __FUNC__(n-1)) : 0
- }(n)) * 2**(n+1)
- }, π)
- # Formula due to Karl Heinrich Schellbach (1832)
- display(4 * sum(0..^n, {|n|
- (-1)**n * (1/(2**(2*n + 1)) + 1/(3**(2*n + 1))) / (2*n + 1)
- }), π)
- # Formula due to Louis Comtet (1974)
- display((3240/17 * sum(1..n, {|n|
- 1 / n**4 / binomial(2*n, n)
- }))**(1/4), π)
- # Formula due to Jonathan Borwein and Peter Borwein (1988)
- display(1/(12*sum(0..^n, {|n|
- (-1)**n * (6*n)! * ((212175710912*sqrt(61) + 1657145277365) + (13773980892672*sqrt(61) + 107578229802750)*n) / n!**3 / ((3*n)!) / (5280 * (236674 + 30303*sqrt(61)))**(3*n + 3/2)
- })), π)
- # Formula due to David Bailey, Peter Borwein and Simon Plouffe (1995)
- display(sum(0..^n, {|n|
- (4/(8*n + 1) - 2/(8*n + 4) - 1/(8*n + 5) - 1/(8*n + 6)) / 16**n
- }), π)
- # Formula due to Fabrice Bellard (1997)
- display(sum(0..^n, {|n|
- (-1)**n / 2**(10*n) * (-32/(4*n + 1) - 1/(4*n + 3) + 256/(10*n + 1) - 64/(10*n + 3) - 4/(10*n + 5) - 4/(10*n + 7) + 1/(10*n + 9))
- }) / 64, π)
- # Formula due to Fabrice Bellard (1997)
- display((sum(1..n, {|n|
- 3 * (-(885673181 * n**5) + (3125347237 * n**4) - (2942969225 * n**3) + (1031962795 * n**2) - (196882274 * n) + 10996648) / binomial(7*n, 2*n) / 2**(n-1)
- }) - 20379280)/ 740025, π)
- # Formula due to Cetin Hakimoglu-Brown (2009)
- display(sqrt(3) / 7776 * sum(0..^n, {|n|
- ((4*n)!)**2 * ((6*n)!) / 9**(n+1) / ((12*n)!) / ((2*n)!) * (127169/(12*n + 1) - 1070/(12*n + 5) - 131/(12*n + 7) + 2/(2*n + 11))
- }), π)
- # Formula due to Cetin Hakimoglu-Brown (2009)
- display(sum(0..^n, {|n|
- 1 / binomial(8*n, 4*n) / 9**n * (5717/(8*n + 1) - 413/(8*n + 3) - 45/(8*n + 5) + 5/(8*n + 7))
- }) / 1024 / sqrt(3), π)
- # Formula (re?)discovered by the author.
- display((16*sum(0..^n, {|n|
- (-1)**n / (2*n + 2) / (3*n - 1) / (3*n + 1)
- }) + 3) / -sqrt(3), π)
- #
- ## exp(1)
- #
- say "\n=> exp(1)"
- # Formula (re?)discovered by the author.
- display(sqr(sum(0..^n, {|n|
- ((2*n + 1)!!) / (2*n + 1)!
- })), ℯ)
- # Basic formula for `e`, due to Euler
- display(sum(0..^n, {|n|
- 1/n!
- }), ℯ)
- # Definition of e
- display((1 + 1/n)**n, ℯ)
- # Binomial expansion (1 + 1/n)^n
- display(sum(0..n, {|k|
- n! * n**(k-n) / (k!) / (n-k)!
- }), ℯ)
- # Limit_{n->Infinity} (n-1)^(-n) * (n+1)^n = exp(2)
- display(sqrt((n - 1)**(-n) * (n+1)**n), ℯ)
- #
- ## Euler-Mascheroni constant
- #
- say "\n=> Euler-Mascheroni"
- # Euler-Mascheroni constant, involving zeta(n)
- display(1 - sum(2..(n+1), {|n|
- (zeta(n) - 1) / n
- }), γ)
- # Limit_{n->Infinity} zeta((n+1)/n) - n} = gamma
- display(zeta((n+1)/n) - n, γ)
- # Series due to Euler (1731).
- display(sum(2..(n+1), {|n|
- (-1)**n * zeta(n) / n
- }), γ)
- # Original definition of the Euler-Mascheroni constant, due to Euler (1731)
- display(sum(1..n, {|n|
- 1/n
- }) - log(n), γ)
- # Original definition of the Euler-Mascheroni constant,
- # with an additional correction term (re)discovered by the author.
- display(sum(1..n, {|n|
- 1/n
- }) - log(n) - 3/(6*n + 1), γ)
- # Original definition of the Euler-Mascheroni constant, with additional correction terms.
- display(sum(1..n, {|n|
- 1/n
- }) - log(n) - 1/(2*n) + 1/(12 * n**2) - 1/(120 * n**4) + 1/(252 * n**6) - 1/(240 * n**8) + 1/(132 * n**10) - 1/(47 * n**12), γ)
- # Formula due to Euler
- display(harmfrac(n) - log(n) - 1/(2*n) - sum(1..n, {|k|
- -bernfrac(2*k) / (2*k) / n**(2*k)
- }), γ)
- # Formula derived by the author from the above formula of Euler
- display(harmfrac(n) - log(n) - 1/(2*n) - sum(1..n, {|k|
- (-1)**k * 4 * sqrt(π*k) * (π * ℯ)**(-2*k) * k**(2*k) / (2*k) / n**(2*k)
- }), γ)
- # Formula derived by the author from the above formula of Euler
- display(harmfrac(n) - log(n) - 1/(2*n) - sum(1..n, {|k|
- (-1)**k * 2 / (2*π)**(2*k) * ((2*k)!) / (2*k) / n**(2*k)
- }), γ)
- # Formula due to Euler in terms of log(2) and the odd zeta values
- display(3/4 - log(2)/2 + sum(1..n, {|n|
- (1 - 1/(2*n + 1)) * (zeta(2*n + 1) - 1)
- }), γ)
- # Formula due to Euler in terms of log(2) and the odd zeta values (VII)
- display(log(2) - sum(1..n, {|n|
- zeta(2*n + 1) / (2*n + 1) / 2**(2*n)
- }), γ)
- # Formula due to Vacca (1910)
- display(sum(1..n, {|n|
- (-1)**n * floor(log2(n)) / n
- }), γ)
- #
- ## Catalan constant
- #
- say "\n=> Catalan constant"
- display(π/2 * (sum(1..n, {|n|
- zeta(2*n) / n / (2*n + 1) / 16**n
- }) - log(π/2) + 1), C)
- # Formula from the paper "Fast multiprecision evaluation of series of rational numbers"
- display(3/8 * (sum(0..^n, {|n|
- 1 / binomial(2*n, n) / (2*n + 1)**2
- })) + (π/8 * log(2 + sqrt(3))), C)
- #
- ## log(2)
- #
- say "\n=> log(2)"
- # The log(2) constant involving zeta(2n)
- display(sum(1..n, {|n|
- (zeta(2*n) - 1) / n
- }), log(2))
- # A geometric series for log(2)
- display(sum(1..n, {|n|
- 1 / n / 2**n
- }), log(2))
- # Formula reformulated by the author based on the above formula.
- display(sum(0..^n, {|n|
- (n!) / (2*n + 2)!!
- }), log(2))
- # Formula reformulated by the author (equivalent with the above one)
- display(sum(0..^n, {|n|
- 1 / (2*n + 2) / 2**n
- }), log(2))
- # Formula (re?)discovered by the author.
- display(sum(0..^n, {|n|
- 1 / ((2*n + 1) * (2*n + 2))
- }), log(2))
- # Formula based on: log(x) = 2*Sum_{n>=0} ((x-1)/(x+1))^(2n+1)/(2n+1)
- display(2 * sum(0..^n, {|n|
- (1 / 3)**(2*n + 1) / (2*n + 1)
- }), log(2))
- # Formula used by the MPFR library
- display(3/4 * sum(0..^n, {|n|
- (-1)**n * n!**2 / 2**n / (2*n + 1)!
- }), log(2))
- # Formula from Wikipedia
- display((sum(0..^n, {|n|
- (-1)**n / (n+1) / (n+2)
- }) + 1)/2, log(2))
- # Formula from Wikipedia
- display(sum(1..n, {|n|
- 1 / n / (8 * n**2 - 2)
- }) + 1/2, log(2))
- # Formula from Wikipedia
- display(sum(1..n, {|n|
- (-1)**n / n / (4 * n**2 - 1)
- }) + 1, log(2))
- # Formula from Wikipedia
- display(sum(1..n, {|n|
- (-1)**n / (2*n) / (3*n - 1) / (3*n + 1)
- }) + 3/4, log(2))
- # Formula from Wikipedia
- display(sum(2..(n+1), {|n|
- (zeta(n) - 1) / 2**n
- }) + 1/2, log(2))
- # Formula from Wikipedia
- display(1 - sum(1..n, {|n|
- zeta(2*n) / 2**(2*n - 1) / (2*n + 1)
- }), log(2))
- # Formula from Wikipedia
- display(sum(1..n, {|n|
- (3**(-n) + 4**(-n)) / n
- }), log(2))
- # Formula from Wikipedia
- display(sum(1..n, {|n|
- (1/(2*n) + 1/(4*n + 1) + 1/(8*n + 4) + 1/(16*n + 12)) / 16**n
- }) / 2 + 2/3, log(2))
- # Formula from Wikipedia
- display(sum(0..^n, {|n|
- 14/(31**(2*n + 1) * (2*n + 1)) + 6/(161**(2*n + 1) * (2*n + 1)) + 10/(49**(2*n + 1) * (2*n + 1))
- }), log(2))
|