Bernoulli numbers: Difference between revisions

m
 
(7 intermediate revisions by 4 users not shown)
Line 2,818:
58 84483613348880041862046775994036021/354
60 -(1215233140483755572040304994079820246041491/56786730)</pre>
 
=={{header|Maxima}}==
Using built-in function bern
<syntaxhighlight lang="maxima">
block(makelist([sconcat("B","(",i,")","="),bern(i)],i,0,60),
sublist(%%,lambda([x],x[2]#0)),
table_form(%%))
</syntaxhighlight>
{{inout}}
<pre>
matrix(
["B(0)=", 1],
["B(1)=", -1/2],
["B(2)=", 1/6],
["B(4)=", -1/30],
["B(6)=", 1/42],
["B(8)=", -1/30],
["B(10)=", 5/66],
["B(12)=", -691/2730],
["B(14)=", 7/6],
["B(16)=", -3617/510],
["B(18)=", 43867/798],
["B(20)=", -174611/330],
["B(22)=", 854513/138],
["B(24)=", -236364091/2730],
["B(26)=", 8553103/6],
["B(28)=", -23749461029/870],
["B(30)=", 8615841276005/14322],
["B(32)=", -7709321041217/510],
["B(34)=", 2577687858367/6],
["B(36)=", -26315271553053477373/1919190],
["B(38)=", 2929993913841559/6],
["B(40)=", -261082718496449122051/13530],
["B(42)=", 1520097643918070802691/1806],
["B(44)=", -27833269579301024235023/690],
["B(46)=", 596451111593912163277961/282],
["B(48)=", -5609403368997817686249127547/46410],
["B(50)=", 495057205241079648212477525/66],
["B(52)=", -801165718135489957347924991853/1590],
["B(54)=", 29149963634884862421418123812691/798],
["B(56)=", -2479392929313226753685415739663229/870],
["B(58)=", 84483613348880041862046775994036021/354],
["B(60)=", -1215233140483755572040304994079820246041491/56786730]
)
</pre>
 
=={{header|Nim}}==
<syntaxhighlight lang="nim">import bignum
Line 3,932 ⟶ 3,978:
|
≪ DUP2 IM * ROT IM ROT RE * -
≫ ''''<span style="color:blue">FracSub'''</span>' STO
≪ DUP C→R ABS SWAP ABS DUP2 < ≪ SWAP ≫ IFT
'''WHILE''' DUP '''REPEAT''' SWAP OVER MOD '''END'''
DROP /
≫ ''''<span style="color:blue">FracSimp'''</span>' STO
Line 3,943 ⟶ 3,989:
1 m R→C +
'''IF''' m 2 ≥ '''THEN''' m 2 '''FOR''' j
DUP j 1 - GET OVER j GET '''<span style="color:blue">FracSub'''</span>
C→R SWAP j 1 - * SWAP R→C
'''<span style="color:blue">FracSimp'''</span> j 1 - SWAP PUT
-1 '''STEP END'''
'''NEXT''' 1 GET DUP RE SWAP 0 '''IFTE'''
≫ ''''<span style="color:blue">BRNOU'''</span>' STO
|
''( (a,b) (c,d) -- (e,f) )'' with e/f = a/b - c/d
Line 3,969 ⟶ 4,015:
|}
5 <span style="color:blue">BRNOU</span>
{{in}}
22 <span style="color:blue">BRNOU</span>
<pre>
5 BRNOU
22 BRNOU
</pre>
{{out}}
<pre>
Line 3,979 ⟶ 4,022:
1: (854513,138)
</pre>
 
===HP-49+ version===
Latest RPL implementations can natively handle long fractions and generate Bernoulli numbers.
{{works with|HP|49}}
≪ { }
0 ROT '''FOR''' n
'''IF''' n 2 > LASTARG MOD AND NOT '''THEN''' n IBERNOULLI + '''END'''
'''NEXT'''
≫ '<span style="color:blue">TASK</span>' STO
 
60 <span style="color:blue">TASK</span>
{{out}}
<pre>
1: {1 -1/2 1/6 -1/30 1/42 -1/30 5/66 -691/2730 7/6 -3617/510 43867/798 -174611/330 854513/138 -236364091/2730 8553103/6 -23749461029/870 8615841276005/14322 -7709321041217/510 2577687858367/6 -26315271553053477373/1919190 2929993913841559/6 -261082718496449122051/13530 1520097643918070802691/1806 -27833269579301024235023/690 596451111593912163277961/282 -5609403368997817686249127547/46410 495057205241079648212477525/66 -801165718135489957347924991853/1590 9149963634884862421418123812691/798 -2479392929313226753685415739663229/870 84483613348880041862046775994036021/354 -1215233140483755572040304994079820246041491/56786730}
</pre>
Runs in 3 minutes 40 on a HP-50g, against 1 hour and 30 minutes if calculating Bernoulli numbers with the above function.
 
=={{header|Ruby}}==
Line 4,902 ⟶ 4,961:
{{libheader|Wren-fmt}}
{{libheader|Wren-big}}
<syntaxhighlight lang="ecmascriptwren">import "./fmt" for Fmt
import "./big" for BigRat
 
var bernoulli = Fn.new { |n|
Line 4,959 ⟶ 5,018:
B(60) = -1215233140483755572040304994079820246041491 / 56786730
</pre>
 
=={{header|zkl}}==
{{trans|EchoLisp}}
2,120

edits