Talk:Bernoulli numbers

From Rosetta Code

Bernoulli numbers, the   why   and the   why for[edit]

I added the Bernoulli numbers task for several reasons:

  • they're an important sequence
  • forces utilization of gihugic integers
  • displaying the numbers can utilize some creative coding

The numerator can get quite large.   Here is a list of the non-zero Bernoulli numbers from   B0   to   B200:

(Shown at four-fifth size.)

B(n)                                                                                               Bernoulli number expressed as a fraction    (right justified and aligned on the solidi)
──── ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   0                                                                                                                                                                                                                                                1/1
   1                                                                                                                                                                                                                                               -1/2
   2                                                                                                                                                                                                                                                1/6
   4                                                                                                                                                                                                                                               -1/30
   6                                                                                                                                                                                                                                                1/42
   8                                                                                                                                                                                                                                               -1/30
  10                                                                                                                                                                                                                                                5/66
  12                                                                                                                                                                                                                                             -691/2730
  14                                                                                                                                                                                                                                                7/6
  16                                                                                                                                                                                                                                            -3617/510
  18                                                                                                                                                                                                                                            43867/798
  20                                                                                                                                                                                                                                          -174611/330
  22                                                                                                                                                                                                                                           854513/138
  24                                                                                                                                                                                                                                       -236364091/2730
  26                                                                                                                                                                                                                                          8553103/6
  28                                                                                                                                                                                                                                     -23749461029/870
  30                                                                                                                                                                                                                                    8615841276005/14322
  32                                                                                                                                                                                                                                   -7709321041217/510
  34                                                                                                                                                                                                                                    2577687858367/6
  36                                                                                                                                                                                                                            -26315271553053477373/1919190
  38                                                                                                                                                                                                                                 2929993913841559/6
  40                                                                                                                                                                                                                           -261082718496449122051/13530
  42                                                                                                                                                                                                                           1520097643918070802691/1806
  44                                                                                                                                                                                                                         -27833269579301024235023/690
  46                                                                                                                                                                                                                         596451111593912163277961/282
  48                                                                                                                                                                                                                    -5609403368997817686249127547/46410
  50                                                                                                                                                                                                                      495057205241079648212477525/66
  52                                                                                                                                                                                                                  -801165718135489957347924991853/1590
  54                                                                                                                                                                                                                 29149963634884862421418123812691/798
  56                                                                                                                                                                                                              -2479392929313226753685415739663229/870
  58                                                                                                                                                                                                              84483613348880041862046775994036021/354
  60                                                                                                                                                                                                     -1215233140483755572040304994079820246041491/56786730
  62                                                                                                                                                                                                           12300585434086858541953039857403386151/6
  64                                                                                                                                                                                                      -106783830147866529886385444979142647942017/510
  66                                                                                                                                                                                                   1472600022126335654051619428551932342241899101/64722
  68                                                                                                                                                                                                    -78773130858718728141909149208474606244347001/30
  70                                                                                                                                                                                                1505381347333367003803076567377857208511438160235/4686
  72                                                                                                                                                                                         -5827954961669944110438277244641067365282488301844260429/140100870
  74                                                                                                                                                                                               34152417289221168014330073731472635186688307783087/6
  76                                                                                                                                                                                           -24655088825935372707687196040585199904365267828865801/30
  78                                                                                                                                                                                        414846365575400828295179035549542073492199375372400483487/3318
  80                                                                                                                                                                                   -4603784299479457646935574969019046849794257872751288919656867/230010
  82                                                                                                                                                                                    1677014149185145836823154509786269900207736027570253414881613/498
  84                                                                                                                                                                             -2024576195935290360231131160111731009989917391198090877281083932477/3404310
  86                                                                                                                                                                                  660714619417678653573847847426261496277830686653388931761996983/6
  88                                                                                                                                                                          -1311426488674017507995511424019311843345750275572028644296919890574047/61410
  90                                                                                                                                                                        1179057279021082799884123351249215083775254949669647116231545215727922535/272118
  92                                                                                                                                                                       -1295585948207537527989427828538576749659341483719435143023316326829946247/1410
  94                                                                                                                                                                        1220813806579744469607301679413201203958508415202696621436215105284649447/6
  96                                                                                                                                                               -211600449597266513097597728109824233673043954389060234150638733420050668349987259/4501770
  98                                                                                                                                                                    67908260672905495624051117546403605607342195728504487509073961249992947058239/6
 100                                                                                                                                                             -94598037819122125295227433069493721872702841533066936133385696204311395415197247711/33330
 102                                                                                                                                                            3204019410860907078243020782116241775491817197152717450679002501086861530836678158791/4326
 104                                                                                                                                                         -319533631363830011287103352796174274671189606078272738327103470162849568365549721224053/1590
 106                                                                                                                                                        36373903172617414408151820151593427169231298640581690038930816378281879873386202346572901/642
 108                                                                                                                                               -3469342247847828789552088659323852541399766785760491146870005891371501266319724897592306597338057/209191710
 110                                                                                                                                                   7645992940484742892248134246724347500528752413412307906683593870759797606269585779977930217515/1518
 112                                                                                                                                            -2650879602155099713352597214685162014443151499192509896451788427680966756514875515366781203552600109/1671270
 114                                                                                                                                               21737832319369163333310761086652991475721156679090831360806110114933605484234593650904188618562649/42
 116                                                                                                                                          -309553916571842976912513458033841416869004128064329844245504045721008957524571968271388199595754752259/1770
 118                                                                                                                                           366963119969713111534947151585585006684606361080699204301059440676414485045806461889371776354517095799/6
 120                                                                                                                               -51507486535079109061843996857849983274095170353262675213092869167199297474922985358811329367077682677803282070131/2328255930
 122                                                                                                                                      49633666079262581912532637475990757438722790311060139770309311793150683214100431329033113678098037968564431/6
 124                                                                                                                                  -95876775334247128750774903107542444620578830013297336819553512729358593354435944413631943610268472689094609001/30
 126                                                                                                                           5556330281949274850616324408918951380525567307126747246796782304333594286400508981287241419934529638692081513802696639/4357878
 128                                                                                                                           -267754707742548082886954405585282394779291459592551740629978686063357792734863530145362663093519862048495908453718017/510
 130                                                                                                                        1928215175136130915645299522271596435307611010164728458783733020528548622403504078595174411693893882739334735142562418015/8646
 132                                                                                                                  -410951945846993378209020486523571938123258077870477502433469747962650070754704863812646392801863686694106805747335370312946831/4206930
 134                                                                                                                      264590171870717725633635737248879015151254525593168688411918554840667765591690540727987316391252434348664694639349484190167/6
 136                                                                                                                -84290226343367405131287578060366193649336612397547435767189206912230442242628212786558235455817749737691517685781164837036649737/4110
 138                                                                                                            2694866548990880936043851683724113040849078494664282483862150893060478501559546243423633375693325757795709438325907154973590288136429/274386
 140                                                                                                        -3289490986435898803930699548851884006880537476931130981307467085162504802973618096693859598125274741604181467826651144393874696601946049/679470
 142                                                                                                           14731853280888589565870080442453214239804217023990642676194878997407546061581643106569966189211748270209483494554402556608073385149191/6
 144                                                                                               -3050244698373607565035155836901726357405007104256566761884191852434851033744761276392695669329626855965183503295793517411526056244431024612640493/2381714790
 146                                                                                                      4120570026280114871526113315907864026165545608808541153973817680034790262683524284855810008621905238290240143481403022987037271683989824863/6
 148                                                                                               -1691737145614018979865561095112166189607682852147301400816480675916957871178648433284821493606361235973346584667336181793937950344828557898347149/4470
 150                                                                                           463365579389162741443284425811806264982233725425295799852299807325379315501572305760030594769688296308375193913787703707693010224101613904227979066275/2162622
 152                                                                                            -3737018141155108502105892888491282165837489531488932951768507127182409731328472084456653639812530140212355374618917309552824925858430886313795805601/30
 154                                                                                         10259718682038021051027794238379184461025738652460569233992776489750881337506863808448685054322627708245455888249006715516690124228801409697850408284121/138
 156                                                                               -81718086083262628510756459753673452313595710396116467582152090596092548699138346942995509488284650803976836337164670494733866559829768848363506624334818961419869/1794590070
 158                                                                                     171672676901153210072183083506103395137513922274029564150500135265308148197358551999205867870374013289728260984269623579880772408522396975250682773558018919/6
 160                                                                             -4240860794203310376065563492361156949989398087086373214710625778458441940477839981850928830420029285687066701804645453159767402961229305942765784122421197736180867/230010
 162                                                                           1584451495144416428390934243279426140836596476080786316960222380784239380974799880364363647978168634590418215854419793716549388865905348534375629928732008786233507729/130074
 164                                                                         -20538064609143216265571979586692646837805331023148645068133372383930344948316600591203926388540940814833173322793804325084945094828524860626092013547281335356200073083/2490
 166                                                                        5734032969370860921631095311392645731505222358555208498573088911303001784652122964703205752709194193095246308611264121678834250704468082648313788124754168671815815821441/1002
 168                                                                -13844828515176396081238346585063517228531109156984345249260453934317772754836791258987516540324983611569758649525983347408589045734176589270143058509026392246407576578281097477/3404310
 170                                                                   195334207626637530414976779238462234481410337350988427215139995707346979124686918267688171536352650572535330369818176979951931477427594872783018749894699157917782460035894085/66
 172                                                             -11443702211333328447187179942991846613008046506032421731755258148665287832264931024781365962633301701773088470841621804328201008020129996955549467573217659587609679405537739509973/5190
 174                                                            4166161554662042831884959593250717297395614318182561412048180684077407803317591270831194619293832107482426945655143357909807251852859279483176373435697607639883085093246499347128331/2478
 176                                                     -1369347910486705707645621362512824332220360774476594348356938715366608044588614657557436131706543948464159947970464346070253278291989696390096800799614617317655510118710460076077638883999/1043970
 178                                                      1124251816617941290026484851206299982774720467712867275292043701618829826708395745459654170718363182143418314514085426692857018428614935412736063946853033094328968069656979232446257101741/1074
 180                                         -6173136454016248924640522272263470960199559328290655337530202055853397791747341312347030141906500993752700612233695954532816018207721731818225290076670213481102834647254685911917265818955932383093313/7225713885390
 182                                                   4277269279349192541137304400628629348327468135828402291661683018622451659989595510712915810436238721139546963558655260384328988773219688091443529626531335687951612545946030357929306651006711/6
 184                                             -857321333523056180131194437347933216431403305730705359015465649285681432317514010686029079324479659634642384809061711319481020030715989009140595170556956196762318625529645723516532076273012244047/1410
 186                                            22258646098436968050639602221816385181596567918515338169946670500599612225742487595012775838387331550474751212260636163500086787417640903770807353228157478339547041472679880890292167353534100797481/42
 188                                        -14158277750623758793309386870401397333112823632717478051426522029712001260747920789473711562165031101665618225654329210473605281619696918061316240634857984019071572591940586875558943580878119388321001/30
 190                                    5411555842544259796131885546196787277987837486638756184149141588783989774511509608733429067517383750706299486822702171672522203106730993581242777825864203487238429479957280273093904025319950569633979493395/12606
 192                           -346465752997582699690191405750952366871923192340955593486485715370392154894102000406980162521728492501917598012711402163530166516991115122131398542029056286959857727373568402417020319761912636411646719477318166587/868841610
 194                                 2269186825161532962833665086968359967389321429297588337232986752409765414223476696863199759981611817660735753831323900456495253961837175924312108872915089534970310604331636484174526399721365966337809334021247/6
 196                         -62753135110461193672553106699893713603153054153311895305590639107017824640241378480484625554578576142115835788960865534532214560982925549798683762705231316611716668749347221458005671217067357943416524984438771831113/171390
 198                    88527914861348004968400581010530565220544526400339548429439843908721196349579494069282285662653465989920237253162555666526385826449862863083834096823053048072002986184254693991336699593468906111158296442729034119206322233/244713882
 200                  -498384049428333414764928632140399662108495887457206674968055822617263669621523687568865802302210999132601412697613279391058654527145340515840099290478026350382802884371712359337984274122861159800280019110197888555893671151/1366530

-- Gerard Schildberger (talk) 09:04, 11 March 2014 (UTC)


Algorithm?[edit]

How about adding info on how to generate the numbers to the task description? --Paddy3118 (talk) 13:47, 11 March 2014 (UTC)

I didn't want to suggest or demand any particular method on how to generate Bernoulli numbers.   People are free to use any method they want.   The link to the Wolfram MathWorld (TM) has some examples, the REXX example uses formula 33. -- Gerard Schildberger (talk) 16:11, 11 March 2014 (UTC)
I just copied the Wikipedia algo. (with atribution attribution). People don't have to use it, but they don't have to search for at least one algo. --Paddy3118 (talk) 01:20, 12 March 2014 (UTC)
Yes, it sure looks simple.   The programming solutions that used it also looks simple and clean. -- Gerard Schildberger (talk) 01:56, 12 March 2014 (UTC)

The double sum formula used by the REXX example is #33 from the entry Bernoulli number on The Eric Weisstein's World of Mathematics (TM).


where                 is a binomial coefficient.


-- Gerard Schildberger (talk) 01:00, 18 March 2014 (UTC)

use of memoization[edit]

In the REXX programming solution, I added memoization for the COMB and PERM functions (combinations and permutations).

For computing the Bernoulli numbers up to (and including):
 
  50  values, memoization was  17% faster.
 100    "          "       "   38%    "
 200    "          "       "   42%    "