Apéry's constant: Difference between revisions
Thundergnat (talk | contribs) m (→{{header|Raku}}: typoed the typo fix :-( ...) |
(Added Wren) |
||
Line 72: | Line 72: | ||
1.2020569031595942853997381615114499907649862923404988817922715553418382057863130901864558736093352581 |
1.2020569031595942853997381615114499907649862923404988817922715553418382057863130901864558736093352581 |
||
</div> |
</div> |
||
=={{header|Wren}}== |
|||
{{libheader|Wren-big}} |
|||
<syntaxhighlight lang="ecmascript">import "./big" for BigInt, BigRat |
|||
var apery = Fn.new { |n| |
|||
var sum = BigRat.zero |
|||
for (k in 1..n) sum = sum + BigRat.new(1, k*k*k) |
|||
System.print("First %(n) terms of ζ(3) truncated to 100 decimal places (accurate to 6 decimal places):") |
|||
System.print(sum.toDecimal(100, false)) |
|||
System.print() |
|||
} |
|||
var markov = Fn.new { |n| |
|||
var fact = BigInt.one |
|||
var fact2 = BigInt.one |
|||
var sign = BigInt.minusOne |
|||
var sum = BigRat.zero |
|||
for (k in 1..n) { |
|||
sign = sign * BigInt.minusOne |
|||
fact = fact * k |
|||
var num = fact.square * sign |
|||
var mult = 2 * k * (2*k - 1) |
|||
fact2 = fact2 * mult |
|||
var cube = k * k * k |
|||
var den = fact2 * cube |
|||
sum = sum + BigRat.new(num, den) |
|||
} |
|||
sum = sum * BigRat.new(5, 2) |
|||
System.print("First %(n) terms of Markov / Apéry representation truncated to 100 decimal places:") |
|||
System.print(sum.toDecimal(100, false)) |
|||
System.print() |
|||
} |
|||
var wedeniwski = Fn.new { |n| |
|||
var fact = BigInt.one |
|||
var fact2 = BigInt.one |
|||
var sign = BigInt.minusOne |
|||
var sum = BigRat.zero |
|||
var mult = 1 |
|||
for (k in 0..n-1) { |
|||
sign = sign * BigInt.minusOne |
|||
if (k > 0) { |
|||
fact = fact * k |
|||
mult = 2 * k * (2*k - 1) |
|||
fact2 = fact2 * mult |
|||
} |
|||
var fact3 = fact2 * (2*k + 1) |
|||
var num = sign * fact3.cube * fact2.cube * fact.cube |
|||
var cube = k * k * k |
|||
var quad = cube * k |
|||
var pent = quad * k |
|||
var tmp = 126392*pent + 412708*quad + 531578*cube + 336367*k*k + 104000*k + 12463 |
|||
num = num * tmp |
|||
var den = BigInt.factorial(3*k + 2) * BigInt.factorial(4*k + 3).cube |
|||
sum = sum + BigRat.new(num, den) |
|||
} |
|||
sum = sum / 24 |
|||
System.print("First %(n) terms of Wedeniwski representation truncated to 100 decimal places:") |
|||
System.print(sum.toDecimal(100, false)) |
|||
System.print() |
|||
} |
|||
System.print("Actual value to 100 decimal places:") |
|||
System.print("1.2020569031595942853997381615114499907649862923404988817922715553418382057863130901864558736093352581") |
|||
System.print() |
|||
apery.call(1000) |
|||
markov.call(158) |
|||
wedeniwski.call(20)</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
Actual value to 100 decimal places: |
|||
1.2020569031595942853997381615114499907649862923404988817922715553418382057863130901864558736093352581 |
|||
First 1000 terms of ζ(3) truncated to 100 decimal places (accurate to 6 decimal places): |
|||
1.2020564036593442854830714115115999903483212709031775135036540966118572571921400836130084123260473111 |
|||
First 158 terms of Markov / Apéry representation truncated to 100 decimal places: |
|||
1.2020569031595942853997381615114499907649862923404988817922715553418382057863130901864558736093352581 |
|||
First 20 terms of Wedeniwski representation truncated to 100 decimal places: |
|||
1.2020569031595942853997381615114499907649862923404988817922715553418382057863130901864558736093352581 |
|||
</pre> |
Revision as of 10:31, 24 February 2023
Apéry's constant is the sum of the reciprocals of the positive cubes.
That is, it is defined as the number where ζ is the Riemann zeta function.
Approximately equal to:
- 1.2020569031595942853997381615114499907649862923404988817922715553418382057863130901864558736093352581
This constant was known and studied by many early mathematicians, but was not named until 1978, after Roger Apéry who was first to prove it was an irrational number.
is easy to calculate, but it converges very slowly. The first 1000 terms are only accurate to 6 decimal places.
There have been many fast convergence representations developed / discovered that generate correct digits much more quickly.
One of the earliest, discovered in the early 1800s by A. Markov and later widely published by Apéry is:
Much better than direct calculation of , but still only yielding about .63 correct digits per iteration.
Several even faster converging representions are available. The fastest known to date, yielding about 5.04 correct digits per term, is by Sebastian Wedeniwski.
- Task
- Show the value of Apéry's constant calculated at least three different ways.
- Show the value of at least the first 1000 terms of direct calculation truncated to 100 decimal digits.
- Show the value of the first 158 terms of Markov / Apéry representation truncated to 100 decimal digits.
- Show the value of the first 20 terms of Wedeniwski representation truncated to 100 decimal digits.
- See also
Raku
sub postfix:<!> (Int $n) { (constant f = 1, |[\×] 1..*)[$n] }
say 'Actual value to 100 decimal places:';
say '1.2020569031595942853997381615114499907649862923404988817922715553418382057863130901864558736093352581';
say "\nFirst 1000 terms of ζ(3) truncated to 100 decimal places. (accurate to 6 decimal places):";
say (1..1000).map({FatRat.new: 1, .³}).sum.substr: 0, 102;
say "\nFirst 158 terms of Markov / Apéry representation truncated to 100 decimal places:";
say (5/2 × (1..158).map( -> \k { (-1)**(k-1) × FatRat.new: k!², ((2×k)! × k³) } ).sum).substr: 0, 102;
say "\nFirst 20 terms of Wedeniwski representation truncated to 100 decimal places:";
say (1/24 × ((^20).map: -> \k {
(-1)**k × FatRat.new: (2×k+1)!³ × (2×k)!³ × k!³ × (126392×k⁵ + 412708×k⁴ + 531578×k³ + 336367×k² + 104000×k + 12463), (3×k+2)! × (4×k+3)!³
}).sum).substr: 0, 102;
- Output:
1.2020569031595942853997381615114499907649862923404988817922715553418382057863130901864558736093352581
First 1000 terms of ζ(3) truncated to 100 decimal places. (accurate to 6 decimal places): 1.2020564036593442854830714115115999903483212709031775135036540966118572571921400836130084123260473111
First 158 terms of Markov / Apéry representation truncated to 100 decimal places: 1.2020569031595942853997381615114499907649862923404988817922715553418382057863130901864558736093352581
First 20 terms of Wedeniwski representation truncated to 100 decimal places: 1.2020569031595942853997381615114499907649862923404988817922715553418382057863130901864558736093352581
Wren
import "./big" for BigInt, BigRat
var apery = Fn.new { |n|
var sum = BigRat.zero
for (k in 1..n) sum = sum + BigRat.new(1, k*k*k)
System.print("First %(n) terms of ζ(3) truncated to 100 decimal places (accurate to 6 decimal places):")
System.print(sum.toDecimal(100, false))
System.print()
}
var markov = Fn.new { |n|
var fact = BigInt.one
var fact2 = BigInt.one
var sign = BigInt.minusOne
var sum = BigRat.zero
for (k in 1..n) {
sign = sign * BigInt.minusOne
fact = fact * k
var num = fact.square * sign
var mult = 2 * k * (2*k - 1)
fact2 = fact2 * mult
var cube = k * k * k
var den = fact2 * cube
sum = sum + BigRat.new(num, den)
}
sum = sum * BigRat.new(5, 2)
System.print("First %(n) terms of Markov / Apéry representation truncated to 100 decimal places:")
System.print(sum.toDecimal(100, false))
System.print()
}
var wedeniwski = Fn.new { |n|
var fact = BigInt.one
var fact2 = BigInt.one
var sign = BigInt.minusOne
var sum = BigRat.zero
var mult = 1
for (k in 0..n-1) {
sign = sign * BigInt.minusOne
if (k > 0) {
fact = fact * k
mult = 2 * k * (2*k - 1)
fact2 = fact2 * mult
}
var fact3 = fact2 * (2*k + 1)
var num = sign * fact3.cube * fact2.cube * fact.cube
var cube = k * k * k
var quad = cube * k
var pent = quad * k
var tmp = 126392*pent + 412708*quad + 531578*cube + 336367*k*k + 104000*k + 12463
num = num * tmp
var den = BigInt.factorial(3*k + 2) * BigInt.factorial(4*k + 3).cube
sum = sum + BigRat.new(num, den)
}
sum = sum / 24
System.print("First %(n) terms of Wedeniwski representation truncated to 100 decimal places:")
System.print(sum.toDecimal(100, false))
System.print()
}
System.print("Actual value to 100 decimal places:")
System.print("1.2020569031595942853997381615114499907649862923404988817922715553418382057863130901864558736093352581")
System.print()
apery.call(1000)
markov.call(158)
wedeniwski.call(20)
- Output:
Actual value to 100 decimal places: 1.2020569031595942853997381615114499907649862923404988817922715553418382057863130901864558736093352581 First 1000 terms of ζ(3) truncated to 100 decimal places (accurate to 6 decimal places): 1.2020564036593442854830714115115999903483212709031775135036540966118572571921400836130084123260473111 First 158 terms of Markov / Apéry representation truncated to 100 decimal places: 1.2020569031595942853997381615114499907649862923404988817922715553418382057863130901864558736093352581 First 20 terms of Wedeniwski representation truncated to 100 decimal places: 1.2020569031595942853997381615114499907649862923404988817922715553418382057863130901864558736093352581