# !, fact

Factorial function

### Use only in the MuPAD Notebook Interface.

This functionality does not run in MATLAB.

## Syntax

````n !`
fact(`n`)
```

## Description

`fact(n)` represents the factorial of an integer.

The short hand call `n!` is equivalent to `fact(n)`.

If `n` is a nonnegative integer smaller than the value returned by `Pref::autoExpansionLimit`(), then an integer is returned. If `n` is a numerical value that is not an integer, then an error occurs. If `n` is a symbolic expression, then a symbolic call of `fact` is returned.

Use `expand(n!)` to compute an explicit result for large integers `n` equal to or larger than `Pref::autoExpansionLimit`().

The `gamma` function generalizes the factorial function to arbitrary complex arguments. It satisfies `gamma(n+1) = n!` for nonnegative integers `n`. Expressions involving symbolic `fact` calls can be rewritten by `rewrite(expression, gamma)`. Cf. Example 3.

The operator `!` can also be used in prefix notation with an entirely different meaning: `!command` is equivalent to `system("command")`.

## Examples

### Example 1

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

`fact(0), fact(5), fact(2^5)`

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

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

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

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

### 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))`

### Example 3

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

`expand(fact(n^2 + 4))`

`limit(fact(n)/exp(n), n = infinity)`

`rewrite(fact(2*n^2 + 1)/fact(n - 1), gamma)`

The Stirling formula is obtained as an asymptotic series:

`series(fact(n), n = infinity, 3)`

## Parameters

 `n` An arithmetical expression representing a nonnegative integer

## Return Values

Arithmetical expression.

`n`