# gamma

Gamma function

### Use only in the MuPAD Notebook Interface.

This functionality does not run in MATLAB.

## Syntax

```gamma(`x`)
gamma(`iv`)
```

## Description

`gamma(x)` represents the gamma function .

The gamma function is defined for all complex arguments apart from the singular points 0, - 1, - 2, ….

The gamma function is related to the factorial function: `gamma(x)=fact(x-1)=(x-1)!` for all positive integers x.

If `x` is a floating-point value, then `gamma` returns a floating-point value. If `x` is a floating-point interval, a floating-point interval is returned. If `x` is a positive integer not larger than the value given by `Pref::autoExpansionLimit()`, then an integer is returned. (Use `expand(gamma(x))` to get an integer value for larger integers `x`.) If `x` is a rational number of domain type `DOM_RAT` not larger than the value given by `Pref::autoExpansionLimit()`, then the functional relation Γ(x + 1) = xΓ(x) is applied to "normalize" the result. (Again, use `expand(gamma(x))` to enforce this normalization for larger rational numbers `x`.) The functional relation

is applied if is a rational number of domain type `DOM_RAT` that is an integer multiple of or . The call `gamma(1/2)` yields `sqrt(PI)`; `gamma(infinity)` yields `infinity`.

For all other arguments, a symbolic function call is returned.

The float attribute of `gamma` is a kernel function, i.e., floating-point evaluation is fast.

The `expand` attribute uses the functional equation Γ(x + 1) = xΓ(x), the reflection formula

,

and the Gauß multiplication formula for Γ(kx) when k is a positive integer, to rewrite `gamma(x)`. Cf. Example 3. For numerical `x`, the functional equation is used to shift the argument to the range ```0 < x < 1```.

The functional equations for gamma lead to various identities for lngamma which can be applied via `expand`. Cf. Example 3.

The logarithmic derivative of `gamma` is implemented by the digamma function `psi`.

## Environment Interactions

When called with a floating-point argument, the functions are sensitive to the environment variable `DIGITS` which determines the numerical working precision.

## Examples

### Example 1

We demonstrate some calls with exact and symbolic input data:

```gamma(15), gamma(3/2), gamma(-3/2), gamma(sqrt(2)), gamma(x + 1)```

```lngamma(15), lngamma(3/2), lngamma(-3/2), lngamma(sqrt(2)), lngamma(x + 1)```

Floating point values are computed for floating-point arguments:

```gamma(11.5), gamma(2.0 + 10.0*I)```

```lngamma(11.5), lngamma(2.0 + 10.0*I)```

### Example 2

`gamma` and `lngamma` are singular for nonpositive integers:

`gamma(0)`
```Error: Singularity. [gamma] ```
`lngamma(-2)`
```Error: Singularity. [lngamma] ```

### Example 3

The functions `diff`, `expand`, `float`, `limit`, and `series` handle expressions involving `gamma` and `lngamma`:

```diff(gamma(x^2 + 1), x), diff(lngamma(x^2 + 1), x)```

```float(ln(3 + gamma(sqrt(PI)))), float(ln(3 + lngamma(sqrt(PI))))```

```expand(gamma(x + 2)), expand(lngamma(x + 2))```

```expand(gamma(2*x)), expand(lngamma(2*x))```

```expand(gamma(2*x - 1)), expand(lngamma(2*x - 1))```

```limit(1/gamma(x), x = infinity), limit(1/lngamma(x), x = infinity)```

```limit(gamma(x - 4)/gamma(x - 10), x = 0), limit(lngamma(x - 4) - lngamma(x - 10), x = 0)```

```series(gamma(x), x = 0, 3), series(lngamma(x), x = 0, 3)```

The Stirling formula is obtained as an asymptotic series:

```series(gamma(x), x = infinity, 4), series(lngamma(x), x = infinity, 4)```

### Example 4

The logarithm function `ln` has a branch cut along the negative real semi axis, where the values jump by 2 π i when crossing the cut. In the following plot of the imaginary part of the logarithm of the gamma function the lines in the complex z plane with and are clearly visible as discontinuities:

```plotfunc3d(Im(ln(gamma(x + I*y))), x = -10 .. 10, y = -10 .. 10, Submesh = [2, 2], CameraDirection = [0, -1, 1000]):```

The function `lngamma(z)`, however, adds suitable integer multiples of 2 π i to `ln(gamma(z))` making the function analytic throughout the complex plane with a branch cut along the negative real semi axis:

```plotfunc3d(Im(lngamma(x + I*y)), x = -10 .. 10, y = -10 .. 10, Submesh = [2, 2], CameraDirection = [0, -1, 1000]):```

## Parameters

 `x` `iv`

## Return Values

Arithmetical expression or a floating-point interval.

`x`