Anonymous user
Bernoulli numbers: Difference between revisions
→{{header|factor}}
Line 832:
</pre>
=={{header|factor}}==
{{improve|factor|<br> The Bernoulli numbers are to be expressed as (reduced) fractions, <br> not as a sum of an integer and a fraction. <br><br> The Bernoulli numbers are to be indexed (so as to be able to understand which Bernoulli numbers are being displayed. <br><br>}}
{{incorrect|factor|<br> '''B<sub>0</sub>''' is not shown, nor is '''B<sub>1</sub>''' <br><br> All Bernoulli numbers that are equal to zero are to be suppressed. <br><br>}}
<lang factor>
SYMBOL: j
SYMBOL: k
SYMBOL: n
SYMBOL: s
SYMBOL: tab
: bernoulli-numbers ( n -- seq )
n get 1 + 0 <array> tab set
1 1 tab get set-nth
2 n get [a,b] [
k set
k get 1 - dup
tab get nth *
k get tab get set-nth
] each
2 n get [a,b] [
k
k get
j
j
j get k get -
j
j get k get - * +
j get tab get set-nth
] each
] each
1
1 n get [a,b] [
k set
s get * k get tab get set-nth
s get -1 * s set
] each
tab get
;
</lang>
This uses a method described by Brent and Harvey in https://arxiv.org/pdf/1108.0286.pdf to calculate the tangent numbers, and then from those the Bernoulli numbers.
<lang>
30 bernoulli-numbers .
{
0
1/6
-1/30
1/42
-1/30
5/66
-691/2730
1+1/6
-7-47/510
54+775/798
-529-41/330
6192+17/138
-86580-691/2730
1425517+1/6
-27298231-59/870
601580873+12899/14322
-15116315767-47/510
429614643061+1/6
-13711655205088-638653/1919190
488332318973593+1/6
-19296579341940068-2011/13530
841693047573682615+1/1806
-40338071854059455413-53/690
2115074863808199160560+41/282
-120866265222965259346027-14477/46410
7500866746076964366855720+5/66
-503877810148106891413789303-83/1590
36528776484818123335110430842+775/798
-2849876930245088222626914643291-59/870
238654274996836276446459819192192+53/354
-21399949257225333665810744765191097-22298681/56786730
}
</lang>
Alternatively one could of course use the "bernoulli" word from the math.extras vocabulary.
=={{header|FreeBASIC}}==
|