Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Fast Integer Factorial

Name: FrozenVoid !FrOzEn2BUo 2009-01-06 5:16

function ffact(num){switch(num){
case 0: return 0;case 1: return 1;case 2: return 2;case 3: return 6;case 4: return 24;case 5: return 120;case 6: return 720;case 7: return 5040;case 8: return 40320;case 9: return 362880;case 10: return 3628800;case 11: return 39916800;case 12: return 479001600;case 13: return 6227020800;case 14: return 87178291200;case 15: return 1307674368000;case 16: return 20922789888000;case 17: return 355687428096000;case 18: return 6402373705728000;case 19: return 121645100408832000;case 20: return 2432902008176640000;case 21: return 51090942171709440000;case 22: return 1.1240007277776077e+21;case 23: return 2.585201673888498e+22;case 24: return 6.204484017332394e+23;case 25: return 1.5511210043330984e+25;case 26: return 4.032914611266057e+26;case 27: return 1.0888869450418352e+28;case 28: return 3.048883446117138e+29;case 29: return 8.841761993739701e+30;case 30: return 2.652528598121911e+32;case 31: return 8.222838654177924e+33;case 32: return 2.6313083693369355e+35;case 33: return 8.68331761881189e+36;case 34: return 2.952327990396041e+38;case 35: return 1.0333147966386144e+40;case 36: return 3.719933267899013e+41;case 37: return 1.3763753091226346e+43;case 38: return 5.23022617466601e+44;case 39: return 2.0397882081197447e+46;case 40: return 8.15915283247898e+47;case 41: return 3.34525266131638e+49;case 42: return 1.4050061177528801e+51;case 43: return 6.041526306337384e+52;case 44: return 2.6582715747884495e+54;case 45: return 1.196222208654802e+56;case 46: return 5.502622159812089e+57;case 47: return 2.5862324151116827e+59;case 48: return 1.2413915592536068e+61;case 49: return 6.082818640342679e+62;case 50: return 3.0414093201713376e+64;case 51: return 1.5511187532873816e+66;case 52: return 8.06581751709439e+67;case 53: return 4.274883284060024e+69;case 54: return 2.308436973392413e+71;case 55: return 1.2696403353658264e+73;case 56: return 7.109985878048632e+74;case 57: return 4.052691950487723e+76;case 58: return 2.350561331282879e+78;case 59: return 1.386831185456898e+80;case 60: return 8.32098711274139e+81;case 61: return 5.075802138772246e+83;case 62: return 3.146997326038794e+85;case 63: return 1.9826083154044396e+87;case 64: return 1.2688693218588414e+89;case 65: return 8.247650592082472e+90;case 66: return 5.443449390774432e+92;case 67: return 3.6471110918188705e+94;case 68: return 2.48003554243683e+96;case 69: return 1.7112245242814127e+98;case 70: return 1.1978571669969892e+100;case 71: return 8.504785885678624e+101;case 72: return 6.123445837688612e+103;case 73: return 4.470115461512686e+105;case 74: return 3.307885441519387e+107;case 75: return 2.4809140811395404e+109;case 76: return 1.8854947016660506e+111;case 77: return 1.451830920282859e+113;case 78: return 1.1324281178206295e+115;case 79: return 8.94618213078298e+116;case 80: return 7.15694570462638e+118;case 81: return 5.797126020747369e+120;case 82: return 4.7536433370128435e+122;case 83: return 3.94552396972066e+124;case 84: return 3.314240134565354e+126;case 85: return 2.8171041143805494e+128;case 86: return 2.4227095383672744e+130;case 87: return 2.107757298379527e+132;case 88: return 1.854826422573984e+134;case 89: return 1.6507955160908465e+136;case 90: return 1.4857159644817605e+138;case 91: return 1.3520015276784033e+140;case 92: return 1.2438414054641305e+142;case 93: return 1.156772507081641e+144;case 94: return 1.0873661566567426e+146;case 95: return 1.0329978488239061e+148;case 96: return 9.916779348709491e+149;case 97: return 9.619275968248216e+151;case 98: return 9.426890448883248e+153;case 99: return 9.332621544394415e+155;case 100: return 9.332621544394418e+157;case 101: return 9.42594775983836e+159;case 102: return 9.614466715035125e+161;case 103: return 9.902900716486178e+163;case 104: return 1.0299016745145631e+166;case 105: return 1.0813967582402912e+168;case 106: return 1.1462805637347086e+170;case 107: return 1.2265202031961373e+172;case 108: return 1.324641819451829e+174;case 109: return 1.4438595832024942e+176;case 110: return 1.5882455415227423e+178;case 111: return 1.7629525510902457e+180;case 112: return 1.974506857221075e+182;case 113: return 2.2311927486598138e+184;case 114: return 2.543559733472186e+186;case 115: return 2.925093693493014e+188;case 116: return 3.393108684451899e+190;case 117: return 3.96993716080872e+192;case 118: return 4.6845258497542896e+194;case 119: return 5.574585761207606e+196;case 120: return 6.689502913449135e+198;case 121: return 8.094298525273444e+200;case 122: return 9.875044200833601e+202;case 123: return 1.2146304367025332e+205;case 124: return 1.506141741511141e+207;case 125: return 1.882677176888926e+209;case 126: return 2.3721732428800483e+211;case 127: return 3.0126600184576624e+213;case 128: return 3.856204823625808e+215;case 129: return 4.974504222477287e+217;case 130: return 6.466855489220473e+219;case 131: return 8.471580690878813e+221;case 132: return 1.1182486511960037e+224;case 133: return 1.4872707060906847e+226;case 134: return 1.99294274616152e+228;case 135: return 2.690472707318049e+230;case 136: return 3.6590428819525483e+232;case 137: return 5.0128887482749884e+234;case 138: return 6.917786472619482e+236;case 139: return 9.615723196941089e+238;case 140: return 1.3462012475717523e+241;case 141: return 1.8981437590761713e+243;case 142: return 2.6953641378881633e+245;case 143: return 3.8543707171800694e+247;case 144: return 5.550293832739308e+249;case 145: return 8.047926057471989e+251;case 146: return 1.1749972043909107e+254;case 147: return 1.72724589045464e+256;case 148: return 2.5563239178728637e+258;case 149: return 3.8089226376305687e+260;case 150: return 5.7133839564458575e+262;case 151: return 8.627209774233244e+264;case 152: return 1.3113358856834527e+267;case 153: return 2.0063439050956838e+269;case 154: return 3.0897696138473515e+271;case 155: return 4.789142901463393e+273;case 156: return 7.471062926282892e+275;case 157: return 1.1729568794264134e+278;case 158: return 1.8532718694937346e+280;case 159: return 2.946702272495036e+282;case 160: return 4.714723635992061e+284;case 161: return 7.590705053947223e+286;case 162: return 1.2296942187394494e+289;case 163: return 2.0044015765453032e+291;case 164: return 3.287218585534299e+293;case 165: return 5.423910666131583e+295;case 166: return 9.003691705778434e+297;case 167: return 1.5036165148649983e+300;case 168: return 2.5260757449731988e+302;case 169: return 4.2690680090047056e+304;default: return -1;}}

Name: FrozenVoid !FrOzEn2BUo 2009-01-06 5:18

Its twice as fast:
bench(loop,ffact,100000000,200)=2136ms
bench(loop,factorial,100000000,200)=5649ms

Name: FrozenVoid !FrOzEn2BUo 2009-01-06 5:24

http://74.125.77.132/search?q=cache:3RRqXPhAr0cJ:swox.com/list-archives/gmp-devel/2004-April/000406.html+%22mpz_fac_ui%22&hl=en&ct=clnk&cd=1&strip=1

mpz_fac_ui2 took 5340ms on 10 million.Which would be
53400ms on 100 millions. i.e. its 25-27 times slower.

Name: Anonymous 2009-01-06 5:25

Go away.

Name: FrozenVoid !FrOzEn2BUo 2009-01-06 5:29

>>4
truth hurts isn't? Your C++ code is 25 times slower then my Javascript.

Name: Anonymous 2009-01-06 5:32

Go away.

Name: Anonymous 2009-01-06 5:34

>>1
there's already a perfectly usable thread for this shit on the front page of /prog/. why did you start another one?
are you really that stupid?

Name: FrozenVoid !FrOzEn2BUo 2009-01-06 5:34

assembly program with
JMP Address+Factorial number
as single routine would be faster still however.

Name: Anonymous 2009-01-06 5:34

Go away.

Name: FrozenVoid !FrOzEn2BUo 2009-01-06 5:36

>>7
""How do I write the factorial function in point-free?"
This was a thread about notation.
This thread is about computational efficiency regardless of langauge.

Name: Anonymous 2009-01-06 5:36

Go away.

Name: FrozenVoid !FrOzEn2BUo 2009-01-06 5:37

Name: Anonymous 2009-01-06 5:38

Go away.

Name: FrozenVoid !FrOzEn2BUo 2009-01-06 5:40

>>13
If this thread doesn't suit your taste please don't post in it.

Name: Anonymous 2009-01-06 5:40

Go away.

Name: Anonymous 2009-01-06 5:46

this thread is about how much of a faggot >>1 is.

Name: sage 2009-01-06 6:02

Sage.

Name: Anonymous 2009-01-06 6:11

Don't reply to his threads. He just wants your attention.

Name: Anonymous 2009-01-06 6:52

--funroll-recursion

Name: Anonymous 2009-01-07 5:54

Egas

Name: Anonymous 2009-01-10 3:15

>>18
Why would i need your attention? Is it valuable?

Name: Anonymous 2009-01-10 3:30

>>3
I don't normally reply to trolls, but I am compelled to make an exception for this post. 10/10, truly superb.

Name: Anonymous 2009-01-10 3:45

>>22
What exactly is a troll? Stating that the convoluted and inefficient C++ version is beaten by 25 times faster simple javascript?
 tracemonkey JIT interpreter working with optimized functions  can be faster then bloated C code.

Name: Anonymous 2009-01-10 3:59

What if I want ffact(1337)

Name: Anonymous 2009-01-10 4:14

>>24
This would return floating-point-infinity(in form of -1) thus making it useless for your calculation. My function still does it 25 times faster.

Name: Anonymous 2009-01-10 12:48

>>1
Meh, it could be done much better.
Just use array of functors.

Name: Anonymous 2009-01-10 12:50

>>26
☣ Please try to ignore troll posts! ☣

http://dis.4chan.org/read/prog/1231209853/10

Name: Anonymous 2009-01-10 12:51

WAIT.
I am not an expert, I occasionally just do some LISP, but do people *REALLY* implement functions as lookup tables and search for the argument in keys?

Name: Anonymous 2009-01-10 12:55

>>28
Read SICP

Name: Anonymous 2009-01-10 13:16

>>29
HIBT?

Name: Anonymous 2009-01-10 13:37

>>24
Just add case 1337: return 887466383665767961662410646418133009547720120993472817948825961826558347208242245175653282982022722058669481239871705639657796348418584362497281156669575296750780954758327535524972251479250320725610587166047316052852866030929583178433027418481048030909480696419787417341906457203073082736913850711256327094955836404135512482780295069310682691573995491500623854579601587817849503628789811149766567074045228982210153765358361566631588607877546386029998012175018958929358226830846926910428219007151600093821891756344534626104424595011881712271112632554198258537265323401161989456854987626382016841485520206291409251317581091038442775621830936404993634843379290136110050961155268459667855821130686699111052710448456452303715564784713608991646823736882082535713547777275085122422869551491458340859781864591504272223365288587594617674139500396689715172922635939257814706435261022339348399895624687983784132098598976962661792055125204818207379994825981934498913044756979880016227011919060243351342003850059552276235127922399190788983464032761842853777912565798838492109316240332942284675007008079043598054801132080125898936057330000326959065520734255643693710692487600956072078505707260781540866742465477586689361471938191739558464749996286441377111650677845949962336778095739073822993573741989877580136830168972666156531118978117640058364458283340708940949164163214212205585345343467103936615504309510942658940054307206713898430351276576375740609239382658858733683893105301002529184482151822036869979215613970760639507778333511179470172848100496935972064971661937839645155149990343920418359376780238516182208337827385812062763732239411718292133414801992130032496850207424885052795385536927993340774183524648275187664139429621564258666601136997690893394377729608513211320512270149552612669389229439481776767545946390287889391256930083045149035228972463646339211420412779833636398557716981957238684909142926856443301457223486821725964620996828833653018978436973049396466355275048510896815912978257797414563383520797336669711715714894263687208737164248389314351737875864499884644264365366311576002113698723254479774143984365605140787987439413601308015052341997692402113801272966233644030244020754954191906625911872359150775073571231384460230488431314550873648144770454886784313924836475867124650745911375493207396335749100147604886064560970902257373275335399229457426300052890490827954589255639131546564209385612017928211939373861997928050240751832137286030583261046654199683278650423541998499865477369431515606296081020533403211545135539930030125186619333002398441459913859932886526049733878065932770993200988506056461035534136554876660882938180814459447462508475068055592948149274098835222176639835752140119132661690451806244719475225312994508695604018925535701812269958861020068268742195064165895342608358240243062884552666234158157882968998913543971684369877762370405750049030914920729395907349419216830563653773210805203036149159257276532887915564922718621996437779076967263286886543785617060047962920401506372294854135685960201463507506075174335775483764870274681819425933056233566166111286147971012005610019299941678022428072587797937576139070865042268513678310650790086537966456096139296815388343298217919329189737690902760431566342453027303529691987031522156391306362880000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

Name: =+=*=F=R=O=Z=E=N==V=O=I=D=*=+= !FrOzEn2BUo 2009-01-10 13:44

>>31
Overflows floating point 1e304 limit.
Infinity should return an invalid code like -1 (which is already implemented)

Name: Anonymous 2009-01-10 14:18

Starting n=22, the algo is already inaccurate.
Go away.

Name: =+=*=F=R=O=Z=E=N==V=O=I=D=*=+= !FrOzEn2BUo 2009-01-10 14:25

>>33
Its called Scientific Notation and its used to represent large numbers extensively.
see http://en.wikipedia.org/wiki/Scientific_Notation#E_notation

Name: Anonymous 2009-01-10 14:25

>>33
☣ Please try to ignore troll posts! ☣

http://dis.4chan.org/read/prog/1231209853/10

Name: Anonymous 2009-01-10 15:18

>>33
This can be solved using infinite precision numbers.

Name: =+=*=F=R=O=Z=E=N==V=O=I=D=*=+= !FrOzEn2BUo 2009-01-10 15:22

>>36
How "infinite" is that precision?

Name: Anonymous 2009-01-10 16:06

>>37
Infinitely.

Name: Anonymous 2009-01-10 16:07

>>38
☣ Please try to ignore troll posts! ☣

http://dis.4chan.org/read/prog/1231209853/10

Name: Anonymous 2009-01-10 16:08

>>36
Could this be possible by lazily evaluation which only calculates the digits required?

Name: =+=*=F=R=O=Z=E=N==V=O=I=D=*=+= !FrOzEn2BUo 2009-01-10 16:10

>>38
 If its "infinitely precise" can you calculate factorial(factorial(factorial(10^304))) ?

Name: Anonymous 2009-01-10 18:12

>>41
Yes, it's 37568637381922326155192356874357617018245750723105201601522276554159961281706357479173509323709355010745693021636327402715161387231123972637860571817191388951323404208389678520113476037502568892060867731456635798400078566275137960160723531379950117277350931696059208085028834758271875544480154414888534275612754477165945102086286380182920151832757532932627334713527572596458769676254040440859255201600829613246123039008000687954288642175462621568886997112978824551471755718559068969431206973826370959915304505233655275315982447674577447090189825236333649599148819681438586533701523498469817220401636622968895675884484841296799889732421693327942215973890030745410335956542641353704310363507776270304064804548122328578162770210344091815924924390879167698845231446786676974092724162133389460672880530331952567494435877079299731588022170837859291721607960396986592739388155682112859608704411591365533730592278764820679184794899208663334584427934362217864924248927885361428137559145392444294687844945891084296761194707488174633448195837574088335248908991986115064776710540063889248417308152535763371059452223818959982127844005994665366393142347879629691042799529400927650769186140413968050166714184540031920787537712083907765651859948801765719885720157928056696165438730441014317282195836402783875047383217789033251243865454607739146808397007736842330281066376349547106449474584280438106881055327899461144965080538665452286540974085147283892216796830893705700088768182400810429884201813886305070530916323743683581807111368411405040978936014117370160865646491130158134496118737162486063689417347216424863500628270923831110491857276772361516328840481086590952936164291691073624546708215156405547545180044366027708051493399885471896242404277257560878206915597014309023051445132569063321472913972774926418662894843271937988017921441364908061742339653199611709985097413559310902905416395158896574921653875826742044496289374287028509159755075814987271230492684345808049652711076850136500411782422710735504577762678884554498639025495102276897090025113194494288771922122374030237221537466092901696085193772684781163170168065024820444065477216035771126752374505880890952598710424115620085753197408084296581790379662458330217095988368966446711499463954300748508639577564520547113066017202852951147599829322300165577377435065147438465246673214846438165157027805314093365537339331095206318821670683268161451239454522671007731020281660267307358909799377335104339524330945648957091878712969910618783453908019780439406403589391318096467697930254838872671113446931693650411622983837882367575495106573234194845679715097752699136232834906372024559786953088755232936105627787835444343197320088128439263245371135261187544642676262936587411309198195837577396809280113341434824590415285193443914280467289838112908985076652592728421535504125283718435336118809499531575981549961987978434399213875110338791268818939766200979336835527152062144991979844878249578221578210688955515395055119787063009459040392164186868046988703841361218928709513408359782619971862893292541672809225930894059170421635395205189863808350879901877728590623876836678175933408247276345354131884593260094685431850344292834219149002425100457257933500426404906610038398731171380116988629954308966951011138732055479128095602897239947357517324689842973528037582331959692267418040384373471476796402382904806727383693148272467625893702619551795042939853717703085349893745140040777504994831076018772852661971830742486708734487701214190369203516188641307776661550899422228715348026740895851961362797643960221617762636668698068732865914442189052081032644848873803068852249441582479702520869083468889732376712190949417255548558932374867581019423117969971800671470351755318804011420435737321511276089114663186029383962416786406245392521327544382278185190289289093282562704851594422919477399878571089212535656042535456682956647540623705162227406241282854705525483439609744153855421621447104243135558741284079677

Name: Anonymous 2009-01-10 18:20

Name: Anonymous 2009-01-10 21:34

>>40
Firefox getur ekki tengst við þjón á www.haskell.org.

Name: =+=*=F=R=O=Z=E=N==V=O=I=D=*=+= !FrOzEn2BUo 2009-01-11 3:22

>>42
This number is much lower then even factorial of 10^304.
Its 3x10^3941 which is less then (10^300)^20

Name: Anonymous 2009-01-11 4:37

>>45
When?

Name: =+=*=F=R=O=Z=E=N==V=O=I=D=*=+= !FrOzEn2BUo 2009-01-11 4:57

>>46
Simply 3x10^3941 is less then (10^300)^20 because its equal:
 10^(300*20)=10^6000

Name: Anonymous 2009-01-11 5:06

>>46
Don't reply to him.

Name: Anonymous 2009-01-11 5:11

factorials? that's easy. how about you faggots try to come up with a faster implementation of the ackermann function than this?
ack4list :: (Integral a) => [a]
acklist :: (Integral a) => a -> [a]
ackermann :: (Integral a) => a -> a -> a

ack4list = 2 : (zipWith (^) [2,2..] ack4list)
acklist m = 1 : (zipWith (ackermann) [m-1,m-1..] (acklist m))

ackermann 0 n = n+1
ackermann 1 n = n+2
ackermann 2 n = 2*n+3
ackermann 3 n = 2^(n+3)-3
ackermann 4 n = (ack4list !! fromIntegral (n+2))-3
ackermann m n = (acklist m) !! fromIntegral (n+1)

Name: Anonymous 2009-01-11 5:20

>>47
When its equal what?

Name: =+=*=F=R=O=Z=E=N==V=O=I=D=*=+= !FrOzEn2BUo 2009-01-11 5:26

>>50

The poster at >>42 claimed the result of >>41 is ~3*10^3941
I provided example that even twenty multiplications of 10^300
are larger then this number >>47 and therefore this number is not a valid result.

Name: Anonymous 2009-01-11 5:40

>>51
And you neither read nor understood the message you replied to.

Name: Anonymous 2009-01-11 5:41

a^b^c = a^b*c now? Cool.

Name: =+=*=F=R=O=Z=E=N==V=O=I=D=*=+= !FrOzEn2BUo 2009-01-11 5:45

>>53
example:
3^2^3=3^(2^3)=3^6=729

Name: =+=*=F=R=O=Z=E=N==V=O=I=D=*=+= !FrOzEn2BUo 2009-01-11 5:46

>>54
err, meant (2*3)

Name: =+=*=F=R=O=Z=E=N==V=O=I=D=*=+= !FrOzEn2BUo 2009-01-11 5:47

>>53
"a^b^c = a^b*c now? Cool. "
Would be 3^2^3=3^(2*3)=3^6=729
which is also (3^2=9)^3

Name: =+=*=F=R=O=Z=E=N==V=O=I=D=*=+= !FrOzEn2BUo 2009-01-11 5:58


Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List