Previous Page Next Page Contents

fact -- the factorial function

Introduction

fact(n) represents the factorial n!=1*2*3*..*n of an integer.

Call(s)

fact(n)

n!

Parameters

n - an arithmetical expression representing a nonnegative integer

Returns

an arithmetical expression.

Overloadable:

n

Related Functions

gamma, igamma, psi

Details

Example 1

Integer numbers are produced if the argument is a nonnegative integer:

>> fact(0), fact(5), fact(2^5)
               1, 120, 263130836933693530167218012160000000

A symbolic call is returned if the argument is a symbolic expression:

>> fact(n), fact(n - sin(x)), fact(3.0*n + I)
                fact(n), fact(n - sin(x)), fact(3.0 n + I)

The calls fact(n) and n! are equivalent:

>> 5! = fact(5), (n^2 + 3)!
                                           2
                          120 = 120, fact(n  + 3)

A numerical argument produces an error if it is not a positive integer:

>> fact(3/2 + I)
      Error: Non-negative integer expected [specfunc::fact];
      during evaluation of 'fact'

Example 2

Use gamma(float(n+1)) rather than float(fact(n)) for floating point approximations of large factorials. This avoids the costs of computing large integer numbers:

>> float(fact(2^13)) = gamma(float(2^13 + 1))
                   1.275885799e28503 = 1.275885799e28503

Example 3

The functions expand, limit, rewrite and series handle expressions involving fact:

>> expand(fact(n^2 + 4))
                     2    2        2        2        2
               fact(n ) (n  + 1) (n  + 2) (n  + 3) (n  + 4)
>> limit(fact(n)/exp(n), n = infinity)
                                 infinity
>> rewrite(fact(2*n^2 + 1)/fact(n - 1), gamma)
                                       2
                              gamma(2 n  + 2)
                              ---------------
                                 gamma(n)

The Stirling formula is obtained as an asymptotic series:

>> series(fact(n), n = infinity, 2)
             n + 1              / 2 PI  \1/2
      (n + 1)      exp(- n - 1) | ----- |    +
                                \ n + 1 /
      
                n + 1              / 2 PI  \1/2
         (n + 1)      exp(- n - 1) | ----- |
                                   \ n + 1 /
         -------------------------------------- +
                          12 n
      
          /        n + 1              / 2 PI  \1/2 \
          | (n + 1)      exp(- n - 1) | ----- |    |
          |                           \ n + 1 /    |
         O| -------------------------------------- |
          |                    2                   |
          \                   n                    /

Changes




Do you have questions or comments?


Copyright © SciFace Software GmbH & Co. KG 2000