bundles / scipy latest / scipy / special / _basic / factorialk
function
scipy.special._basic:factorialk
source: /scipy/special/_basic.py :3052
Signature
def factorialk ( n , k , exact = False , extend = zero ) Summary
Multifactorial of n of order k, n(!!...!).
Extended Summary
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
n: int or float or complex (or array_like thereof)Input values for multifactorial. Non-integer values require
extend='complex'. By default, the return value forn < 0is 0.k: int or float or complex (or array_like thereof)Order of multifactorial. Non-integer values require
extend='complex'.exact: bool, optionalIf
exactis set to True, calculate the answer exactly using integer arithmetic, otherwise use an approximation (faster, but yields floats instead of integers) Default is False.extend: string, optionalOne of
'zero'or'complex'; this determines how valuesn<0are handled - by default they are 0, but it is possible to opt into the complex extension of the multifactorial. This enables passing complex values, not only tonbut also tok.
Returns
nf: int or float or complex or ndarrayMultifactorial (order
k) ofn, as integer, float or complex (depending onexactandextend). Array inputs are returned as arrays.
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.
In principle, any fixed choice of r (ignoring its relation r = n%k to n) would provide a suitable analytic continuation from integer n to complex z (not only satisfying the functional equation but also being logarithmically convex, c.f. Bohr-Mollerup theorem) -- in fact, the choice of r above only changes the function by a constant factor. The final constraint that determines the canonical continuation is f(1) = 1, which forces r = 1 (see also [1]).
z!(k) = k ** ((z - 1)/k) * gamma(z/k + 1) / gamma(1/k + 1)Examples
from scipy.special import factorialk factorialk(5, k=1, exact=True) factorialk(5, k=3, exact=True) factorialk([5, 7, 9], k=3, exact=True) factorialk([5, 7, 9], k=3, exact=False)✓
Aliases
-
scipy.special.factorialk