RosettaCodeData/Task/Eulers-constant-0.5772.../Sidef/eulers-constant-0.5772...-2.sidef
2023-07-01 13:44:08 -04:00

51 lines
1.4 KiB
Text
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const n = (ARGV ? Num(ARGV[0]) : 50) # number of iterations
define = Num.e
define π = Num.pi
define γ = Num.EulerGamma
func display(r, t) {
say "#{r}\terror: #{ '%.0g' % abs(r - t) }"
}
# Original definition of the Euler-Mascheroni constant, due to Euler (1731)
display(sum(1..n, {|n| 1/n }) - log(n), γ)
# Formula due to Euler (best convergence)
display(harmfrac(n) - log(n) - 1/(2*n) - sum(1..n, {|k|
-bernoulli(2*k) / (2*k) / n**(2*k)
}), γ)
# Formula derived from the above formula of Euler,
# using approximations of Bernoulli numbers.
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)
}), γ)
# 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
}), γ)
# 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
}), γ)