| Bytes | Lang | Time | Link |
|---|---|---|---|
| 059 | TIBASIC TI84 Plus CE Python | 250819T141121Z | madeforl |
| 044 | Desmos | 250801T235020Z | ErikDaPa |
| 052 | Python 3 + sympy | 250706T045352Z | Lucenapo |
| 045 | Actually | 160826T070338Z | Sherlock |
| 022 | Pyth | 190821T075726Z | ar4093 |
| 166 | APLNARS | 190812T201112Z | user5898 |
| 147 | Axiom | 170518T143935Z | user5898 |
| 057 | Axiom | 170423T215528Z | user5898 |
| 118 | Python 2 | 151201T031303Z | primo |
| 168 | Javascript | 161118T144219Z | Marquis |
| 010 | J | 160928T043743Z | miles |
| 093 | R | 160826T210558Z | Rudier |
| 083 | Perl 6 | 160826T074603Z | bb94 |
| 095 | Haskell | 160423T123541Z | Sherlock |
| 061 | Ruby | 160107T090809Z | Sherlock |
| 112 | Python 3 | 151130T214056Z | Sherlock |
| 033 | CJam | 151202T130214Z | Peter Ta |
| 079 | gawk4 | 151203T175959Z | Cabbie40 |
| 101 | Perl | 151203T125515Z | primo |
| 063 | GolfScript | 151203T104535Z | primo |
| 020 | Julia | 151201T094910Z | alephalp |
| 130 | Python 2 | 151202T202315Z | Dennis |
| 023 | PARI/GP | 151201T033440Z | alephalp |
| 022 | Mathematica | 151201T025515Z | alephalp |
| 042 | Mathematica | 151130T220533Z | LegionMa |
| 045 | PARI/GP | 151201T091220Z | primo |
| 097 | Minkolang 0.14 | 151130T232314Z | El'e |
| 058 | Julia | 151130T211614Z | Alex A. |
TI-BASIC (TI-84 Plus CE Python), 59 bytes
Input F
{1→L₁
For(M,1,F
1-Σ((M nCr K)L₁(K+1)/(M-K+1),K,0,M-1→L₁(M+1
End
Ans
Pretty much the exact equation, except the list is changed to be 1-indexed.
Outputs in decimal representation.
outputs:
Input -> Output
1 -> 0.5
6 -> 0.0238095238
9 -> -3.4ᴇ-12
15 -> 1.255ᴇ-10
30 -> 601580873.9
40 -> -1.92965793ᴇ16
58 -> 2.38654275ᴇ32
Actually, 46 45 bytes
I've been meaning to do a Seriously/Actually answer for months and now I can. Golfing suggestions welcome. Try it online!
Edit: In February of 2017, there was an update to Actually that changed which function literals are which. Enjoy.
This uses the explicit definition of the Bernoulli numbers on Wikipedia.
;╖ur⌠;╝ur⌠;;0~ⁿ(╛█*╜(uⁿ*⌡MΣ╛uk⌡M┬i@;π;)♀\*@k▼
Ungolfing
;╖ Duplicate and save m in register 0.
ur Range [0..m]
⌠ Start first for loop
;╝ Duplicate and save k in register 1.
ur Range [0..k]
⌠ Start second for loop (as string).
;; Duplicate v twice.
0~ⁿ Push -1, and pow() to get (-1)**v.
(╛█ Rotate a duplicate v to TOS, push k, and binom(k, v).
* Multiply (-1)**v by binom(k, v).
╜(uⁿ Push m, rotate last duplicate v to TOS, increment, and pow() to get (v+1)**m.
* (-1)**v * binom(k, v) * (v+1)**m
⌡ End second for loop (string turned to function).
MΣ Map over range [0..v] and sum
╛u Push k and increment (the denominator)
(Note: second for loop does numerators only as denominator only depends on k)
k Push fraction in list form [numerator, denominator]
⌡ End first for loop
M Map over range [0..k]
┬i@ Transpose all of the fractions, flatten and swap.
Stack: [denominators] [numerators]
;π Duplicate and take product of denominators.
;) Duplicate product and move to bottom of stack.
Stack: product [denominators] [numerators] product
♀\ For all items in denominators, integer divide product by item.
Return a list of these scaled-up denominators.
* Dot product of numerators and the scaled-up denominators as new numerator.
(In effect, getting the fractions to the same denominator and summing them)
@k Swap new numerator and product (new denominator) and turn into a list (fraction).
▼ Divide fraction by gcd(numerator, denominator) (Simplify fraction).
Pyth, 22 bytes
L?b-1sm*.cbdcyd-btdUb1
Defines a function that is called as y<number>, e.g. yQ.
L # y=lambda b:
?b 1 # ... if b else 1
-1 # 1 -
s # sum(
m Ub # map(lambda d: ... , range(b))
*.cbd # combinations(b, d) *
cyd # y(d) / (float division)
-btd # b - (d - 1)
APL(NARS), 83 chars, 166 bytes
r←B w;i
r←,1⋄i←0x⋄w+←1
→3×⍳w≤i+←1⋄r←r,1-+/{(1+i-⍵)÷⍨(⍵!i)×r[⍵+1]}¨0..i-1⋄→2
r←r[i]
Input as integer output as big rational
B 0
1
B 1
1r2
B 2
1r6
B 3
0
B 4
¯1r30
B 10
5r66
B 100
¯94598037819122125295227433069493721872702841533066936133385696204311395415197247711r33330
B 1000
¯1824310473866188725457264025685778887933833686704290605219715815764112625726249111586574725773210697096154899246
27495522908087488299539455188791856758224155166849269724418491401224257983095561709862992465225174097919156
37226361428342780548971002281045465308441161372350696920220116244179176068026260201962026025579005841653927
13328528060009666284676390683434226380702951226108116666172815817157023611889303668166839919156379768387784
56901148431227534274268805917998837802553382786645786602185045895962670442011443630321460259486764674312436
99485605430176555742513711502134010510584086798747663529527491787349736768598347076238816346251471489942512
87819057432353129907040693030947738925173870541768065311836481894518927257264459495897596007053347675853897
69924857630972963997636483244264351262207385878011073153983309981755577513600811117079762505973229513088849
00670113339167641953793994512377610306198429310933121463214168354260774664123208985481506462912959653699738
06082564288019784909897301658268809203555030692846151917069465607257641149187197651090551596684031241184554
36505930214028492216913418528197912335893019941012291773441794027493574651881059432274494354092231954894280
74206847271461929421334360546114754048678863132501143996815327532364292906259093411000391368336312138915621
70153595481408420879424166549229427077334760558784157659275820142147265848222364436913143660975700854733545
84000998591519058404733793433129733940339271957909399584231274683687116967497864609134118725271669900471262
22109345933847358924230951718379883743256346548760417031607741875424271006526981819059127169069544663383612
03745255515267088218383996330164203403732365333352120338272021319718003599422045899487646001835027038563411
78077687451616229338340631455056219106004731529642292049578901r342999030
Axiom, 134 147 bytes
b(n:NNI):FRAC INT==(v:=[1/1];k:=1;repeat(k>n=>break;r:=1-reduce(+,[binomial(k,j)*v.(j+1)/(k-j+1)for j in 0..k-1]);v:=append(v,[r]);k:=k+1);v.(n+1))
ungolf and test
(23) -> b
(23)
b n ==
1
v := [-]
1
k := 1
repeat
if n < k
then break
else
binomial(k,j)v(j + 1)
r := 1 - reduce(+,[[--------------------- for j in 0..(k - 1)]])
k - j + 1
v := append(v,[r])
k := k + 1
v(n + 1)
Type: FunctionCalled b
(50) -> [[i,b(i)] for i in [0,1,2,3,4,5,6,7,8,9,10]]
(50)
1 1 1 1 1 5
[[0,1],[1,-],[2,-],[3,0],[4,- --],[5,0],[6,--],[7,0],[8,- --],[9,0],[10,--]]
2 6 30 42 30 66
Type: List List Fraction Integer
(51) -> b 1000
(51)
-
18243104738661887254572640256857788879338336867042906052197158157641126_
2572624911158657472577321069709615489924627495522908087488299539455188_
7918567582241551668492697244184914012242579830955617098629924652251740_
9791915637226361428342780548971002281045465308441161372350696920220116_
2441791760680262602019620260255790058416539271332852806000966628467639_
0683434226380702951226108116666172815817157023611889303668166839919156_
3797683877845690114843122753427426880591799883780255338278664578660218_
5045895962670442011443630321460259486764674312436994856054301765557425_
1371150213401051058408679874766352952749178734973676859834707623881634_
6251471489942512878190574323531299070406930309477389251738705417680653_
1183648189451892725726445949589759600705334767585389769924857630972963_
9976364832442643512622073858780110731539833099817555775136008111170797_
6250597322951308884900670113339167641953793994512377610306198429310933_
1214632141683542607746641232089854815064629129596536997380608256428801_
9784909897301658268809203555030692846151917069465607257641149187197651_
0905515966840312411845543650593021402849221691341852819791233589301994_
1012291773441794027493574651881059432274494354092231954894280742068472_
7146192942133436054611475404867886313250114399681532753236429290625909_
3411000391368336312138915621701535954814084208794241665492294270773347_
6055878415765927582014214726584822236443691314366097570085473354584000_
9985915190584047337934331297339403392719579093995842312746836871169674_
9786460913411872527166990047126222109345933847358924230951718379883743_
2563465487604170316077418754242710065269818190591271690695446633836120_
3745255515267088218383996330164203403732365333352120338272021319718003_
5994220458994876460018350270385634117807768745161622933834063145505621_
9106004731529642292049578901
/
342999030
Type: Fraction Integer
(52) -> b 60
1215233140483755572040304994079820246041491
(52) - -------------------------------------------
56786730
Type: Fraction Integer
Axiom, 57 bytes
g(n)==factorial(n)*coefficient(taylor(t*%e^t/(%e^t-1)),n)
code for test and results
(18) -> [[i, g(i)] for i in 0..29]
(18)
1 1 1 1 1
[[0,1], [1,-], [2,-], [3,0], [4,- --], [5,0], [6,--], [7,0], [8,- --],
2 6 30 42 30
5 691 7 3617
[9,0], [10,--], [11,0], [12,- ----], [13,0], [14,-], [15,0], [16,- ----],
66 2730 6 510
43867 174611 854513
[17,0], [18,-----], [19,0], [20,- ------], [21,0], [22,------], [23,0],
798 330 138
236364091 8553103 23749461029
[24,- ---------], [25,0], [26,-------], [27,0], [28,- -----------], [29,0]]
2730 6 870
Type: List List Expression Integer
(19) -> g 60
1215233140483755572040304994079820246041491
(19) - -------------------------------------------
56786730
Type: Expression Integer
one has to note that the function is not the one someone wrote above
but t*%e^t/(%e^t-1)) with %e Euler costant
Python 2, 118 bytes
Saved 6 bytes due to xsot.
Saved 6 10 more due to Peter Taylor.
n=input()
a=[n%4-1,n<2]*n;exec"a=[(a[j-1]+a[j+1])*j/2for j in range(len(a)-2)];"*~-n
print+(n<1)or-n/(2.**n-4**n)*a[1]
Uses the following identity:
where An is the nth Alternating Number, which can be formally defined as the number of alternating permutations on a set of size n, halved (see also: A000111).
The algorithm used was originally given by Knuth and Buckholtz (1967):
Let T1,k = 1 for all k = 1..n
Subsequent values of T are given by the recurrence relation:
Tn+1,k = 1/2 [ (k - 1) Tn,k-1 + (k + 1) Tn,k+1 ]
An is then given by Tn,1
(see also: A185414)
Python 2, 152 bytes
from fractions import*
n=input()
a=[n%4-1,n<2]*n
for k in range(n-1):a=[(a[j-1]+a[j+1])*j/2for j in range(n-k)]
print+(n<1)or Fraction(n*a[1],4**n-2**n)
Prints the exact fractional representation, necessary for values greater than 200 or so.
Javascript, 168 bytes
function h(b,a){return a?h(a,b%a):b}for(var c=[],a=[],e=0,b,d,f,g;e<=k;)for(c[b=d=e]=1,a[e]=++e;d;)f=c[--d]*a[b]-(c[b]*=g=a[d]),r=h(f*=b,g=a[b]*=g),c[d]=f/r,a[--b]=g/r;
Set the 'k' variable to the Bernoulli number you want, and the result is c[0] over a[0]. (numerator & denominator)
Sample Usage
k = 2;
console.log(c[0] + "/" + a[0]);
Not as small as the others, but the only one I've written that comes close. See https://marquisdegeek.com/code_ada99 for my other (non-golf) attempts.
J, 10 bytes
(%1-^@-)t:
Computes the nth Bernoulli number by finding the nth coefficient of the exponential generating function of x/(1 - e-x).
Usage
If the input is given integer or floats as an argument, it will output a float. If given an extended integer, marked with a suffix x, it will output either an extended integer or a rational, two extended integers separated by r.
f =: (%1-^@-)t:
f 1
0.5
f 1x
1r2
(,.f"0) i. 10x
0 1
1 1r2
2 1r6
3 0
4 _1r30
5 0
6 1r42
7 0
8 _1r30
9 0
Explanation
(%1-^@-)t: Input: n
( )t: Takes a monad and creates a new monad that
computes the coefficients of its egf
( ) A monad that operates on x
- Negate x
^@ Computes its exponential, e^-x
1- Subtract it from 1
% Divide x by it, x/(1 - e^-x)
R, 93 bytes
function(m){if(m==0){1}else{v=c();for(k in 0:(m-1))v=c(v,choose(m,k)*f(k)/(m-k+1));1-sum(v)}}
Not really original as a solution. If any comment, please feel free !
Ungolfed :
function(m)
if(m==0){1}
else
v=c()
for(k in 0:(m-1))
v=c(v,choose(m,k)*f(k)/(m-k+1))
1-sum(v)
Perl 6, 83 bytes
my &B={$^m??1-[+] (^$m).map: {combinations($m,$_)*B($_)/($m+1-$_)}!!1};say B slurp;
A faster, 114-byte solution:
my @b=1;for 1..+slurp() {@b.push: 1-[+] (^$^m).map: {([*] $m+1-$_..$m)*@b[$_]/($m+1-$_)/([*] 1..$_)}};say @b[*-1];
Haskell, 95 bytes
import Data.Ratio
p=product
b m=sum[p[k-v+1..k]*(v+1)^m%(p[-v..0-1]*(k+1))|k<-[0..m],v<-[0..k]]
This implements the explicit definition of Bernoulli numbers outlined on the Wikipedia page.
Ruby, 66 61 bytes
This is a Ruby version of my Python answer.
b=->m{s,p=0r,1;m.times{|k|a=m-k;s+=p*b[k]/-~a;p=p*a/-~k};1-s}
Since this uses Rational in its answers, I'm fairly sure this works up to 60, but I had trouble running even b[24], so I implemented the lookup table again for 86 81 80 bytes.
t=->m{s,p,r=0r,1,m>0?t[m-1]:[];m.times{|k|a=m-k;s+=p*r[k]/-~a;p=p*a/-~k};r<<1-s}
Python 3, 112 bytes
Edit: I cleaned up this answer. If you want to see all the other ways I thought of to answer this question in Python 2 and 3, look in the revisions.
If I don't use the lookup table (and I use memoization instead), I manage to get the recursive definition to 112 bytes! WOO! Note that b(m) returns a Fraction. As usual, the byte count and a link for testing.
from fractions import*
def b(m):
s=k=0;p=1
while k<m:a=m-k;s+=Fraction(p*b(k))/-~a;p=p*a//-~k;k+=1
return 1-s
And a function that does use a lookup table, and returns the whole table of fractions from b(0) to b(m), inclusive.
from fractions import*
def b(m,r=[]):
s=k=0;p=1
while k<m:
if k>=len(r):r=b(k,r)
a=m-k;s+=Fraction(p*r[k])/-~a;p=p*a//-~k;k+=1
return r+[1-s]
CJam, 69 49 34 33 bytes
{_),:):R_:*_@f/@{_(;.-R.*}*0=\d/}
Thanks to Cabbie407, whose answer made me aware of the Akiyama–Tanigawa algorithm.
Dissection
{ e# Function: takes n on the stack
_),:) e# Stack: n [1 2 3 ... n+1]
:R e# Store that array in R
_:* e# Stack: n [1 2 3 ... n+1] (n+1)!
_@f/ e# Stack: n (n+1)! [(n+1)!/1 (n+1)!/2 (n+1)!/3 ... (n+1)!/(n+1)]
e# representing [1/1 1/2 ... 1/(n+1)] but avoiding floating point
@{ e# Repeat n times:
_(;.- e# Take pairwise differences
R.* e# Pointwise multiply by 1-based indices
}* e# Note that the tail of the array accumulates junk, but we don't care
0=\d/ e# Take the first element and divide by (n+1)!
}
gawk4, 79 bytes
77 bytes code + 2 bytes for -M flag
PREC^=2{for(n=$0;m++<=n;)for($(j=m)=1/m;j>1;)$j=(-$j+$--j)*j;printf"%.6f",$1}
It's an implementation of the Akiyama–Tanigawa algorithm from the Wikipedia page.
Had some trouble with the "6-decimal-digits-rule", because this prints the whole number and then 6 digits, but there is no list here to compare the results.
A flaw is that this prints a minus sign in front of the 0.000000 al lot of times, but I don't think that's wrong.
Usage example
echo 58 | awk -M 'PREC^=2{for(n=$0;m++<=n;)for($(j=m)=1/m;j>1;)$j=(-$j+$--j)*j;printf"%.6f",$1}'
Output from 0 to 60
0 -> 1.000000 1 -> 0.500000 2 -> 0.166667 3 -> -0.000000 4 -> -0.033333 5 -> 0.000000 6 -> 0.023810 7 -> 0.000000 8 -> -0.033333 9 -> 0.000000 10 -> 0.075758 11 -> -0.000000 12 -> -0.253114 13 -> -0.000000 14 -> 1.166667 15 -> -0.000000 16 -> -7.092157 17 -> -0.000000 18 -> 54.971178 19 -> -0.000000 20 -> -529.124242 21 -> -0.000000 22 -> 6192.123188 23 -> 0.000000 24 -> -86580.253114 25 -> 0.000000 26 -> 1425517.166667 27 -> 0.000000 28 -> -27298231.067816 29 -> 0.000000 30 -> 601580873.900642 31 -> 0.000000 32 -> -15116315767.092157 33 -> 0.000000 34 -> 429614643061.166667 35 -> 0.000000 36 -> -13711655205088.332772 37 -> 0.000000 38 -> 488332318973593.166667 39 -> -0.000000 40 -> -19296579341940068.148633 41 -> -0.000000 42 -> 841693047573682615.000554 43 -> -0.000000 44 -> -40338071854059455413.076812 45 -> -0.000000 46 -> 2115074863808199160560.145390 47 -> -0.000000 48 -> -120866265222965259346027.311937 49 -> -0.000000 50 -> 7500866746076964366855720.075758 51 -> -0.000000 52 -> -503877810148106891413789303.052201 53 -> -0.000000 54 -> 36528776484818123335110430842.971178 55 -> -0.000000 56 -> -2849876930245088222626914643291.067816 57 -> -0.000000 58 -> 238654274996836276446459819192192.149718 59 -> -0.000000 60 -> -21399949257225333665810744765191097.392674
Perl, 101 bytes
#!perl -p
@a=($_%4-1,$_<2)x$_;
@a=map$_*($a[$_-1]+$a[$_+1])/2,0..@a-3for 2..$_;
$_=!$_||$_/(4**$_-2**$_)*$a[1]
Counting the shebang as three, input is taken from stdin.
Using the same formula as my Python answer.
Sample Usage
$ echo 60 | perl bernoulli.pl
-2.13999492572253e+034
GolfScript, 63 bytes
~:i.!+.[3i&(2i>]*i(,{i\-,{1$1$(=2$2$)=+*2/}%\;}/~\2i?.(*\--1?**
Using the same formula as my Python answer.
Test Script
61,{[.`
~:i.!+.[3i&(2i>]*i(,{i\-,{1$1$(=2$2$)=+*2/}%\;}/~\2i?.(*\--1?**
]p}/
The apphb link will time out on this. If you don't have GolfScript installed locally, I recommend using the anarchy golf interpreter (use form, select GolfScript, paste, submit).
Julia, 23 20 bytes
Saved 3 bytes thanks to Alex A.
It uses the same formula as my Mathematica solution and PARI/GP solution.
n->n>0?-zeta(1-n)n:1
Python 2, 132 130 bytes
import math,fractions
f=math.factorial
B=lambda m:~-m*m%2or 1+sum(B(k)*f(m)/f(k)/f(m-k)/fractions.Fraction(k+~m)for k in range(m))
This is just a golfed version of the reference implementation.
This is a little slow in practice, but can be sped up significantly with memoization:
import math,fractions
f=math.factorial
def memoize(f):
memo = {}
def helper(x):
if x not in memo:
memo[x] = f(x)
return memo[x]
return helper
@memoize
def B(m):
return~-m*m%2or 1+sum(B(k)*f(m)/f(k)/f(m-k)/fractions.Fraction(k+~m)for k in range(m))
for m in range(61):
print(B(m))
You can try this version online on Ideone.
PARI/GP, 52 23 bytes
Using the famous formula n*ζ(1−n)=−Bn, where ζ is the Riemann Zeta function.
n->if(n,-n*zeta(1-n),1)
Original solution, 52 bytes, using the generating function of Bernoulli numbers.
n->n!*polcoeff(-x/sum(i=1,n+1,(-x)^i/i!)+O(x^n*x),n)
Mathematica, 40 28 23 22 bytes
Using the famous formula n*ζ(1−n)=−Bn, where ζ is the Riemann Zeta function.
If[#>0,-Zeta[1-#]#,1]&
The same length:
B@0=1;B@n_=-Zeta[1-n]n
Original solution, 40 bytes, using the generating function of Bernoulli numbers.
#!SeriesCoefficient[t/(1-E^-t),{t,0,#}]&
Mathematica, 52 48 42 bytes
1-Sum[#~Binomial~k#0@k/(#-k+1),{k,0,#-1}]&
Unnamed function that uses the literal definition.
PARI/GP, 45 bytes
n->if(n,2*n/(2^n-4^n)*real(polylog(1-n,I)),1)
Using the same formula as my Python answer, with An generated via polylog.
Test Script
Run gp, at the prompt paste the following:
n->if(n,2*n/(2^n-4^n)*real(polylog(1-n,I)),1)
for(i=0, 60, print(i, ": ", %(i)))
Minkolang 0.14, 97 bytes
I actually tried doing it recursively first, but my interpreter, as currently designed, actually can't do it. If you try to recurse from within a for loop, it starts a new recursion. So I went for the tabulating approach...which had precision problems. So I did the whole thing with fractions. With no built-in support for fractions. [sigh]
n1+[xxi$z0z2%1+F0c0=$1&$d4Mdm:1R:r$dz1Az0A]$:N.
11z[i0azi6M*i1azi-1+*d0c*1c2c*-1c3c*4$X]f
z1=d1+f
Try it here. Bonus: the array has all fractions for every previous Bernoulli number!
Explanation (in a bit)
n1+ Take number from input (N) and add 1
[ Open for loop that runs N+1 times (starts at zero)
xx Dump the top two values of the stack
i$z Store the loop counter in the register (m)
0 Push 0
z2%1+ Push 1 if N is even, 2 if odd
F Gosub; pops y,x then goes to codebox(x,y), to be returned to
0c Copy the first item on the stack
, 1 if equal to 0, 0 otherwise
$1& Jump 11 spaces if top of stack is not 0
(If top of stack is not 0, then...)
$d Duplicate whole stack
4M Pop b,a and push GCD(a,b)
dm Duplicate and merge (a,b,c,c -> a,c,b,c)
: Divide
1R Rotate 1 item to the right (0G works too)
: Divide
r Reverse stack
(In both cases...)
$d Duplicate whole stack
z1A Store denominator of B_m in array
z0A Store numerator of B_m in array
] Close for loop
$: Divide (float division)
N. Output as number and stop.
11 Push two 1s (a, b)
z[ Open a for loop that repeats m times
i0a Retrieve numerator of B_k (p)
zi Push m, k
6M Pop k,m and push mCk (binomial) (x)
* p*x (c)
i1a Retrieve denominator of B_k (q)
zi-1+ m-k+1 (y)
* q*y (d)
d Duplicate top of stack
0c* a*d
1c2c* b*c
- a*d-b*c
1c3c* b*d
4$X Dump the bottom four items of stack
]f Jump back to F
z m
1= 0 (if m is 1) or 1 (otherwise)
d1+ Duplicate and add 1 (1 or 2)
f Jump back to F
The third line is responsible for 1/2 if m is 1 and 0/1 if m is an odd number greater than 1. The second line calculates B_m with the summation formula given in the question, and does so entirely with numerators and denominators. Otherwise it'd be a lot shorter. The first half of the first line does some bookkeeping and chooses whether to execute the second or third line, and the second half divides the numerator and denominator by their GCD (if applicable) and stores those values. And outputs the answer at the end.
Julia, 58 bytes
B(m)=m<1?1:1-sum(k->big(binomial(m,k))*B(k)/(m-k+1),0:m-1)
This creates a recursive function B that accepts an integer and returns a BigFloat (i.e. high precision floating point).
Ungolfed:
function B(m::Integer)
m == 0 && return 1
return 1 - sum(k -> big(binomial(m, k)) * B(k) / (m-k+1), 0:m-1)
end