Results 1 to 13 of 13

Thread: Non-Integer Factorials

  1. #1
    Dreamlax
    Guest

    Non-Integer Factorials

    Is there a function in VB which does factorials? Currently I am using a loop which just multiplies itself by the loop counter.

    I am unsure how to calculate a factorial of a non-integer. Can anyone help me?

    Thanks

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    no you are doing it the right way, factorials are only defined for positive integers and 0! which is 1 which is also the aritmetic multiplication identity.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3
    Dreamlax
    Guest
    I thought that's how. But any ideas on non integer factorials? A lot of people say they can't be done, but they can. My friend once told me you have to use the 'gamma' function, whatever that is... And plus the Windows Calculator does it with a bit of struggle.

  4. #4
    Frenzied Member
    Join Date
    Jul 1999
    Location
    Huntingdon Valley, PA 19006
    Posts
    1,151

    Not defined.

    Factorials are only defined for integers.

    The Gamma function of positive integers is a factorial. Actually it is something like Gamma(n) = Factorial(n+1) or maybe Gamma(n) = Factorial(n-1). I forget which. I do remeber that Gamma(n+1) = n*Gamma(n), and that the Gamma function is the integral from zero to infinity of some function involving exponentials. It can be looked up in a good math library and an internet search might turn up an article or two.

    Due to the relation between the Gamma function and factorials, some erroneously say that the Gamma function defines non integer factorials. Making such a statement is not illegal, immoral, or fattening, merely contrary to standard mathematical usage.

    I suppose that some lord high grand guru committee of mathematicians could have defined the Gamma function as the factorial function, but they did not.

    Besides, if they had defined it that way, each formula for combinations, permutations, et cetera would require a footnote stating that the formula was not valid for non integer factorials.
    Live long & prosper.

    The Dinosaur from prehistoric era prior to computers.

    Eschew obfuscation!
    If a billion people believe a foolish idea, it is still a foolish idea!
    VB.net 2010 Express
    64Bit & 32Bit Windows 7 & Windows XP. I run 4 operating systems on a single PC.

  5. #5
    Lively Member
    Join Date
    Jun 2001
    Location
    Banana Republic
    Posts
    115
    Can anyone help me expand

    (x+a)^(1/2)

    using Binomial theorem ?

  6. #6
    Frenzied Member
    Join Date
    Jul 1999
    Location
    Huntingdon Valley, PA 19006
    Posts
    1,151

    Do not think it can be done.

    I think the binomial expansion is only defined for positive integers, with the kth term being the following.
    • C(n, k) * x^k * a^(n-k)
    Where C(n, k) is n! / ( k! * (n -k)! )

    As noted in previous posts to this thread, the factorial function is only defined for integers.

    There is an algorithm for the binomial expansion which does not use factorials, but I suspect that it is not applicable. The first term is (x^n*a^0). Then determine succeeding terms as follows.
    • Decrease the exponent of x by one.
    • Increase the exponent of a by one.
    • Determine coefficient by multiplying preceding coefficient by preceding exponent of x and dividing by the number of preceding terms.
    For positive integers, the above will result in ordinary binomial expansion. Otherwise, it results in an infinite series. Not sure if the infinite series is meaningful.

    If you consider x to be variable and a to be a constant, you could try a Taylor (I think this is the name for it) series expansion. This requires using derivatives and would also be an infinite series.
    Live long & prosper.

    The Dinosaur from prehistoric era prior to computers.

    Eschew obfuscation!
    If a billion people believe a foolish idea, it is still a foolish idea!
    VB.net 2010 Express
    64Bit & 32Bit Windows 7 & Windows XP. I run 4 operating systems on a single PC.

  7. #7
    Junior Member pranavdesai's Avatar
    Join Date
    Feb 2001
    Location
    india
    Posts
    24

    abt gamma functions and factorial

    Well basically a gamma function can be defined a s
    integral having limits from o to infinity and the function inside the integral being e raised to -x multiplied with x raised to n-1 where x is any variable
    here we get the valeu of gamma n
    gamma(n)= (n-1)multiplied with gamma(n-1)
    where n is a natural no it can be written as
    gamma(n) = n-1!
    if at all u had placed ur question in a more clearer manner.like whether u wanted to calculate factorial of -ve integer or a fraction i could have maybe helped u. even so if u need help on factorials or gamma fns u can email me at [email protected]
    or contact me on msn messenger on the same id
    pmd

  8. #8
    Dreamlax
    Guest
    Well, that about wraps things up. I've found everything about the Gamma function that I need to know. THanks to all who contributed to this post.

  9. #9
    Member
    Join Date
    Jul 2000
    Posts
    35

    Wink Non-integer number factorials

    Hi,

    My contribution to the factorials of non-integer numbers.
    Here are 2 recipes.

    First, for large numbers, use this series
    (the larger x is, the better the formula works):

    x! = (x^x) * exp(-x) * sqrt(2*PI*x) * (a0 + a1*(x^-1) + a2*(x^-2) + a3*(x^-3) + a4*(x^-4) + ...)

    where:

    a0 = 1
    a1 = 1/12
    a2 = 1/288
    a3 = 139/51840
    a4 = 571/2488320
    etc

    I can't remember how these coefficients are calculated,
    I'd have to take a look at my math class notes from the happy? old days.

    Also remember that to perform calculations with very large numbers,
    say, exp(-5000) that your handheld calculator probably can't handle
    (overflow!), you can express the result as a power of 10 in the
    following fashion:

    exp(-5000) = 10^(-5000/ln(10)) = 10^(-5000/2.303) =
    10^(-2171.472) = 10^(-2171-.472) = 10^(-2171) * 10^(-.472) =
    0.337 * 10^(-2171)

    ...ln being the neperian (base "e") logarithm.
    For 5000^5000 you'd have to work out something similar.

    Now, for the smaller numbers.
    Assume you want x!
    First calculate y! such that

    x! = x * (x-1) * (x-2) * ... * y
    and
    0 <= y <= 1

    (for example, to compute 7.3! you'd start by calculating 0.3!
    and would then multiply 7.3! = 7.3 * 6.3 * ... * 0.3)

    and to compute y! you can use this polynomial fit:

    y! = a0 + a1*x + a2*x^2 + ... + a8*x^8 =
    a0 + x(a1 + x(a2 + ... x(a7 + x*a8)...)

    and the coefficients are:

    a0 = 1
    a1 = -.577191652
    a2 = .988205891
    a3 = -.897056937
    a4 = .918206857
    a5 = -.756704078
    a6 = .482199394
    a7 = -.193527818
    a8 = .035868343

    I have found it works very nicely.

  10. #10
    Dreamlax
    Guest
    Thanks for that, especially about how to deal with large numbers. Thanks again to all who have contributed, and lluis_escude for that nice big post up there.

  11. #11
    Member
    Join Date
    Jul 2000
    Posts
    35

    Wink A minor correction

    In my previous post, the line

    " ...and would then multiply 7.3! = 7.3 * 6.3 * ... * 0.3) "

    should actually read

    " ...and would then multiply 7.3! = 7.3 * 6.3 * ... * 0.3!) "

    which was probably obvious to everybody.

    Greetings from the warm Mediterranean...

  12. #12
    Dreamlax
    Guest
    I picked that up, but I thought everyone else would too...

  13. #13
    Member
    Join Date
    Jul 2000
    Posts
    35

    Addendum

    Yet another formula, now for negative numbers.

    (-x!)=(PI*x)/[x!*sin(PI*x)]

    In the case of negative integers, the factorial goes to infinity.
    Also, bear in mind the angle expressed by PI*x is in radians, not in degrees.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width