Apéry's constant: Difference between revisions

m (Added REXX entry)
Line 630:
 
=={{header|REXX}}==
===version 1, under construction===
Straightforward approach: just apply the formulas. Missing REXX functions Fact (factorial n!) and Whole (is integer?) were added.
Follows
<syntaxhighlight lang="rexx">
parse version version; say version; glob. = ''; numeric digits 101
say 'Apery''s constant = zeta(3) to 100 decimal places'
say
call time('r'); a = TrueValue(); e = format(time('e'),,3)
say 'True value' a '('e 'seconds)'
call time('r'); a = Definition(); e = format(time('e'),,3)
say 'Definition' a '('e 'seconds)'
call time('r'); a = Markov(); e = format(time('e'),,3)
say 'Markov ' a '('e 'seconds)'
call time('r'); a = Wedeniwski(); e = format(time('e'),,3)
say 'Wedeniwski' a '('e 'seconds)'
exit
 
TrueValue:
procedure expose glob.
return 1.2020569031595942853997381615114499907649862923404988817922715553418382057863130901864558736093352581
 
Definition:
procedure expose glob.
numeric digits digits()+2
y = 0
do k = 1 to 1000
y = y + 1/(k**3)
end
numeric digits digits()-2
return y+0
 
Markov:
-- Markov Apery series
procedure expose glob.
numeric digits digits()+2
y = 0
do k = 1 to 158
y = y + (-1)**(k-1) * Fact(k)**2 / (Fact(2*k)*k**3)
end
y = y*2.5
numeric digits digits()-2
return y+0
 
Wedeniwski:
numeric digits Digits()+2
-- Wedeniwski series
y = 0
do k = 0 to 19
y = y + ((-1)**k * Fact(2*k+1)**3 * Fact(2*k)**3 * Fact(k)**3,
* (((((126392*k+412708)*k+531578)*k+336367)*k+104000)*k+12463)),
/ (Fact(3*k+2) * Fact(4*k+3)**3)
end
y = y/24
numeric digits Digits()-2
return y+0
 
Fact:
-- Factorial n!
procedure expose glob.
arg x
-- Validity
if \ Whole(x) then
return 'X'
if x < 0 then
return 'X'
-- Current in memory?
if glob.fact.x <> '' then
return glob.fact.x
w = x-1
-- Previous in memory?
if glob.fact.w = '' then do
-- Loop cf definition
y = 1
do n = 2 to x
y = y*n
end
glob.fact.x = y
end
else
-- Multiply
glob.fact.x = glob.fact.w*x
return glob.fact.x
 
Whole:
-- Is a number integer?
procedure expose glob.
arg x
-- Formula
return Datatype(x,'w')
</syntaxhighlight>
{{out}}
<pre>
REXX-Regina_3.9.6(MT) 5.00 29 Apr 2024
Follows
Apery's constant = zeta(3) to 100 decimal places
 
True value 1.2020569031595942853997381615114499907649862923404988817922715553418382057863130901864558736093352581 (0.000 seconds)
Definition 1.2020564036593442854830714115115999903483212709031775135036540966118572571921400836130084123260473112 (0.020 seconds)
Markov 1.2020569031595942853997381615114499907649862923404988817922715553418382057863130901864558736093352581 (0.071 seconds)
Wedeniwski 1.2020569031595942853997381615114499907649862923404988817922715553418382057863130901864558736093352581 (0.006 seconds)
</pre>
 
43

edits