Bernoulli numbers: Difference between revisions
Content added Content deleted
Line 832: | Line 832: | ||
</pre> |
</pre> |
||
=={{header|factor}}== |
=={{header|factor}}== |
||
One could use the "bernoulli" word from the math.extras vocabulary |
One could use the "bernoulli" word from the math.extras vocabulary as follows: |
||
<lang> |
<lang> |
||
IN: scratchpad |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
"%2d : %d / %d\n" printf ] each |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
swap / * |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
0 : 1 / 1 |
0 : 1 / 1 |
||
1 : -1 / 2 |
1 : -1 / 2 |
||
Line 904: | Line 873: | ||
58 : 84483613348880041862046775994036021 / 354 |
58 : 84483613348880041862046775994036021 / 354 |
||
60 : -1215233140483755572040304994079820246041491 / 56786730 |
60 : -1215233140483755572040304994079820246041491 / 56786730 |
||
Running time: 0.00489444 seconds |
|||
</lang> |
|||
Alternatively a method described by Brent and Harvey (2011) in "Fast computation of Bernoulli, Tangent and Secant numbers" https://arxiv.org/pdf/1108.0286.pdf is shown. |
|||
<lang> |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
k 1 - dup |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
] each |
|||
⚫ | |||
1 :> s! |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
0 1 1 "%2d : %d / %d\n" printf |
|||
1 -1 2 "%2d : %d / %d\n" printf |
|||
⚫ | |||
⚫ | |||
[ numerator ] [ denominator ] bi |
|||
⚫ | |||
⚫ | |||
⚫ | |||
</lang> |
|||
It gives the same result as the native implementation, but is slightly faster. |
|||
<lang> |
|||
⚫ | |||
... |
|||
Running time: 0.004331652 seconds |
|||
</lang> |
</lang> |
||