scipy.special.

factorialk#

scipy.special.factorialk(n, k, exact=None)[source]#

Multifactorial of n of order k, n(!!…!).

This is the multifactorial of n skipping k values. For example,

factorialk(17, 4) = 17!!!! = 17 * 13 * 9 * 5 * 1

In particular, for any integer `n`, we have

factorialk(n, 1) = factorial(n)

factorialk(n, 2) = factorial2(n)

Parameters:
nint or array_like

Calculate multifactorial. If `n < 0`, the return value is 0.

kint

Order of multifactorial.

exactbool, optional

If exact is set to True, calculate the answer exactly using integer arithmetic, otherwise use an approximation (faster, but yields floats instead of integers)

Warning

The default value for `exact` will be changed to `False` in SciPy 1.15.0.

Returns:
valint

Multifactorial of n.

Notes

While less straight-forward than for the double-factorial, it’s possible to calculate a general approximation formula of n!(k) by studying `n` for a given remainder `r < k` (thus `n = m * k + r`, resp. `r = n % k`), which can be put together into something valid for all integer values `n >= 0` & `k > 0`:

```n!(k) = k ** ((n - r)/k) * gamma(n/k + 1) / gamma(r/k + 1) * max(r, 1)
```

This is the basis of the approximation when `exact=False`. Compare also [1].

References

Examples

```>>> from scipy.special import factorialk
>>> factorialk(5, k=1, exact=True)
120
>>> factorialk(5, k=3, exact=True)
10
>>> factorialk([5, 7, 9], k=3, exact=True)
array([ 10,  28, 162])
>>> factorialk([5, 7, 9], k=3, exact=False)
array([ 10.,  28., 162.])
```