Apéry's constant: Difference between revisions
m
→{{header|Phix}}: use pygments
(→{{header|Mathematica}}/{{header|Wolfram Language}}: add red color to inaccurate digits for Apéry's constant via reciprocal cubes) |
m (→{{header|Phix}}: use pygments) |
||
Line 430:
Ugh. If you ran this on the James Webb, you might just be able to pick out a faint small print outline of the word "elegant".<br>
Still, at least it is not like you do this sort of thing every day... and I got to fix a couple of bugs in my mpfr.js code.
<!--
<syntaxhighlight lang="phix">
with javascript_semantics
requires("1.0.2") -- (missing mpfr_ui_pow_ui() and bug in mpfr_mul_d(), both in mpfr.js)
include mpfr.e
mpfr_set_default_precision(-100)
mpfr {d,a,w,t} = mpfr_inits(4)
mpz {z,pk} = mpz_inits(2)
for k=1 to 1000 do
mpfr_ui_pow_ui(t,k,3)
mpfr_si_div(t,1,t)
mpfr_add(d,d,t)
end for
for k=1 to 158 do
mpz_fac_ui(z,k)
mpz_mul(z,z,z)
mpfr_set_z(t,z)
mpz_fac_ui(z,2*k)
mpfr_div_z(t,t,z)
mpz_ui_pow_ui(z,k,3)
mpfr_div_z(t,t,z)
if even(k) then
mpfr_sub(a,a,t)
else
mpfr_add(a,a,t)
end if
end for
mpfr_mul_d(a,a,5/2)
for k=0 to 19 do
mpz_ui_pow_ui(z,k,5)
mpz_mul_si(z,z,126392)
mpz_ui_pow_ui(pk,k,4)
mpz_mul_si(pk,pk,412708)
mpz_add(z,z,pk)
mpz_ui_pow_ui(pk,k,3)
mpz_mul_si(pk,pk,531578)
mpz_add(z,z,pk)
mpz_add_si(z,z,k*k*336367)
mpz_add_si(z,z,k*104000)
mpz_add_si(z,z,12463)
mpfr_set_z(t,z)
mpz_fac_ui(z,2*k+1)
mpz_pow_ui(z,z,3)
mpfr_mul_z(t,t,z)
mpz_fac_ui(z,2*k)
mpz_pow_ui(z,z,3)
mpfr_mul_z(t,t,z)
mpz_fac_ui(z,k)
mpz_pow_ui(z,z,3)
mpfr_mul_z(t,t,z)
mpz_fac_ui(z,3*k+2)
mpfr_div_z(t,t,z)
mpz_fac_ui(z,4*k+3)
mpz_pow_ui(z,z,3)
mpfr_div_z(t,t,z)
if odd(k) then
mpfr_sub(w,w,t)
else
mpfr_add(w,w,t)
end if
end for
mpfr_div_si(w,w,24)
constant fmt = """
Actual value to 100 decimal places:
1.2020569031595942853997381615114499907649862923404988817922715553418382057863130901864558736093352581
First 1000 terms of zeta(3) truncated to 100 decimal places. (accurate to 6 decimal places):
%s
First 158 terms of Markov / Apery representation truncated to 100 decimal places:
%s
First 20 terms of Wedeniwski representation truncated to 100 decimal places:
%s
"""
string direct = mpfr_get_fixed(d,100),
mapery = mpfr_get_fixed(a,100),
wdnski = mpfr_get_fixed(w,100)
printf(1,fmt,{direct,mapery,wdnski})
</syntaxhighlight>
{{out}}
<pre>
|