Evaluation of ζ(2) by the definition (sort of) [HP-42S & HP-71B]
10-27-2021, 05:12 PM (This post was last modified: 11-02-2021 10:49 PM by Albert Chan.)
Post: #11
 Albert Chan Senior Member Posts: 1,897 Joined: Jul 2018
RE: Evaluation of ζ(2) by the definition (sort of) [HP-42S & HP-71B]
(10-25-2021 01:29 PM)Albert Chan Wrote:  Convergence speed very impressive, n=8 converged to float(pi^2/6)

2nd version, by putting some reasonable number to b, before loop start (*)
Now, n=6 already converged to float(pi^2/6)

Code:
function zeta2(n)     local N, c, t = n+0.5, (n%2)*6+2     local N2 = N*N     local a, b = 0, (N2+N) * 0.93/(10-c)     for i = n, 2, -1 do         t = i*i         a = a + 1/t         b = t*t/(b + c*N2)         c, N2 = 10-c, N2-N     end     return 1/(N+1/(b+c*N2)) + a + 1 end

lua> for n=0,8 do print(n, zeta2(n)) end
0﻿ ﻿ ﻿ ﻿ ﻿ ﻿ 1.4539195555018722
1﻿ ﻿ ﻿ ﻿ ﻿ ﻿ 1.6448912932530366
2﻿ ﻿ ﻿ ﻿ ﻿ ﻿ 1.6449340922532778
3﻿ ﻿ ﻿ ﻿ ﻿ ﻿ 1.6449340670471453
4﻿ ﻿ ﻿ ﻿ ﻿ ﻿ 1.6449340668467034
5﻿ ﻿ ﻿ ﻿ ﻿ ﻿ 1.6449340668482317
6﻿ ﻿ ﻿ ﻿ ﻿ ﻿ 1.6449340668482264
7﻿ ﻿ ﻿ ﻿ ﻿ ﻿ 1.6449340668482264
8﻿ ﻿ ﻿ ﻿ ﻿ ﻿ 1.6449340668482264

(*) this is how initial b is estimated, by looking ahead.

XCAS> b2 := (N+3/2)^4 / (c*N*(N+2))
XCAS> b1 := (N+1/2)^4 / ((10-c)*N*(N+1) + b2)

XCAS> simplify(partfrac(b1(c=8))[1]) ﻿ ﻿ ﻿ ﻿ ﻿ ﻿ → (2312*N^2+1904*N+480)/4913
XCAS> simplify(partfrac(b1(c=2))[1]) ﻿ ﻿ ﻿ ﻿ ﻿ ﻿ → (578*N^2+476*N+120)/4913

2312/4913*2 ≈ 0.9412
If N is large, this should be the constant to use instead of 0.93