PHPSL Function:  bcDouble_Fact( )

  • bcDouble_Fact ($IntN)

    Dependencies: NONE


    This function computes the double factorial value for a positive integer argument using arbitrary-precision. The double factorial of N is defined as the product of every positive integer greater than of equal to 1 with the same parity as N in the range from 1 up to and including N.  The parity simply refers to whether an integer is an odd number or an even number.

    If (N) is even, then the double factorial is the product of 2 and all the other even integers up to (N).  If (N) is odd, then the double factorial is the product of 1 and all the other odd integers up to (N).  See the examples below.

    The double factorial values of 0 and −1 are equated to 1 by definition, but double factorial values for integers that are less than −1 are not defined.

    The function returns FALSE on ERROR if (N) is non-numeric or (N  <  −1).

    N   ! !   =   n   =   0 N 2 1 ( N 2 n )   =   N ( N 2 ) ( N 4 ) ( N 6 )   . . .  

    Below is the PHP source code for a function to compute the arbitrary-precision double factorial.

    Double-Click to select ALL code

    Double-Click to select ALL code


    The above equation is really two equations in one.

    For even numbers:

    N   ! !   =   n   =   1 N 2 ( 2 n )   =   N ( N 2 ) ( N 4 ) ( N 6 )   . . .   ( 6 ) ( 4 ) ( 2 )

    12   ! !   =   2 4 6 8 10 12   =   46080



    For odd numbers:

    N   ! !   =   n   =   1 N + 1 2 ( 2 n 1 )   =   N ( N 2 ) ( N 4 ) ( N 6 )   . . .   ( 5 ) ( 3 ) ( 1 )

    15   ! !   =   1 3 5 7 9 11 13 15   =   2027025



    Combined equation that will handle both even and odd numbers:

    N   ! !   =   n   =   0 N 2 1 ( N 2 n )   =   N ( N 2 ) ( N 4 ) ( N 6 )   . . .  

    This is the equation implemented by the function.

    Below is a table of double factorials for N = −1 to N = 100, followed by the PHP source code used to compute it.  The table was computed using the above double factorial function.


    Double Factorial Table for N = −1 to 100
    
      N     N!!
     -1!! = 1
      0!! = 1
      1!! = 2
      2!! = 3
      3!! = 8
      4!! = 15
      5!! = 48
      6!! = 105
      7!! = 384
      8!! = 945
      9!! = 3840
     10!! = 10395
     11!! = 46080
     12!! = 135135
     13!! = 645120
     14!! = 2027025
     15!! = 10321920
     16!! = 34459425
     17!! = 185794560
     18!! = 654729075
     19!! = 3715891200
     20!! = 13749310575
     21!! = 81749606400
     22!! = 316234143225
     23!! = 1961990553600
     24!! = 7905853580625
     25!! = 51011754393600
     26!! = 213458046676875
     27!! = 1428329123020800
     28!! = 6190283353629375
     29!! = 42849873690624000
     30!! = 191898783962510625
     31!! = 1371195958099968000
     32!! = 6332659870762850625
     33!! = 46620662575398912000
     34!! = 221643095476699771875
     35!! = 1678343852714360832000
     36!! = 8200794532637891559375
     37!! = 63777066403145711616000
     38!! = 319830986772877770815625
     39!! = 2551082656125828464640000
     40!! = 13113070457687988603440625
     41!! = 107145471557284795514880000
     42!! = 563862029680583509947946875
     43!! = 4714400748520531002654720000
     44!! = 25373791335626257947657609375
     45!! = 216862434431944426122117120000
     46!! = 1192568192774434123539907640625
     47!! = 10409396852733332453861621760000
     48!! = 58435841445947272053455474390625
     49!! = 520469842636666622693081088000000
     50!! = 2980227913743310874726229193921875
     51!! = 27064431817106664380040216576000000
     52!! = 157952079428395476360490147277859375
     53!! = 1461479318123759876522171695104000000
     54!! = 8687364368561751199826958100282265625
     55!! = 81842841814930553085241614925824000000
     56!! = 495179769008019818390136611716089140625
     57!! = 4746884825265972078944013665697792000000
     58!! = 29215606371473169285018060091249259296875
     59!! = 284813089515958324736640819941867520000000
     60!! = 1782151988659863326386101665566204817109375
     61!! = 17658411549989416133671730836395786240000000
     62!! = 112275575285571389562324404930670903477890625
     63!! = 1130138339199322632554990773529330319360000000
     64!! = 7297912393562140321551086320493608726062890625
     65!! = 74589130387155293748629391052935801077760000000
     66!! = 488960130368663401543922783473071784646213671875
     67!! = 5072060866326559974906798591599634473287680000000
     68!! = 33738248995437774706530672059641953140588743359375
     69!! = 355044260642859198243475901411974413130137600000000
     70!! = 2395415678676082004163677716234578672981800778515625
     71!! = 25563186766285862273530264901662157745369907200000000
     72!! = 174865344543353986303948473285124243127671456831640625
     73!! = 1891675820705153808241239602722999673157373132800000000
     74!! = 13114900840751548972796135496384318234575359262373046875
     75!! = 143767362373591689426334209806947975159960358092800000000
     76!! = 1009847364737869270905302433221592504062302663202724609375
     77!! = 11213854265140151775254068364941942062476907931238400000000
     78!! = 79777941814291672401518892224505807820921910393015244140625
     79!! = 897108341211212142020325469195355364998152634499072000000000
     80!! = 6462013286957625464523030270184970433494674741834234775390625
     81!! = 73562883979319395645666688474019139929848516028923904000000000
     82!! = 536347102817482913555411512425352545980058003572241486357421875
     83!! = 6179282254262829234236001831817607754107275346429607936000000000
     84!! = 45589503739486047652209978556154966408304930303640526340380859375
     85!! = 531418273866603314144296157536314266853225679792946282496000000000
     86!! = 3966286825335286145742268134385482077522528936416725791613134765625
     87!! = 46764808100261091644698061863195655483083859821779272859648000000000
     88!! = 352999527454840466971061863960307904899505075341088595453568994140625
     89!! = 4208832729023498248022825567687608993477547383960134557368320000000000
     90!! = 32122956998390482494366629620388019345854961856039062186274778466796875
     91!! = 387212611070161838818099952227260027399934359324332379277885440000000000
     92!! = 2987435000850314871976096554696085799164511452611632783323554397412109375
     93!! = 36397985440595212848901395509362442575593829776487243652121231360000000000
     94!! = 283806325080779912837729172696128150920628587998105114415737667754150390625
     95!! = 3494206602297140433494533968898794487257007658542775390603638210560000000000
     96!! = 27529213532835651545259729751524430639300973035816196098326553772152587890625
     97!! = 342432247025119762482464328952081859751186750537191988279156544634880000000000
     98!! = 2725392139750729502980713245400918633290796330545803413734328823443106201171875
     99!! = 34243224702511976248246432895208185975118675053719198827915654463488000000000000
    100!! = 275264606114823679801052037785492781962370429385126144787167211167753726318359375
    

    Here is the complete PHP program source code used to generate the above table.

    Double-Click to select ALL code
    Double-Click to select ALL code


    Ref:

    http://mathworld.wolfram.com/DoubleFactorial.html
Jay Tanner - 2024