factorialk#
- scipy.special.factorialk(n, k, exact=False, extend='zero')[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 havefactorialk(n, 1) = factorial(n)
factorialk(n, 2) = factorial2(n)
- Parameters:
- nint or float or complex (or array_like thereof)
Input values for multifactorial. Non-integer values require
extend='complex'
. By default, the return value forn < 0
is 0.- nint or float or complex (or array_like thereof)
Order of multifactorial. Non-integer values require
extend='complex'
.- 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) Default is False.- extendstring, optional
One of
'zero'
or'complex'
; this determines how valuesn<0
are 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 ton
but also tok
.Warning
Using the
'complex'
extension also changes the values of the multifactorial at integersn != 1 (mod k)
by a factor depending on bothk
andn % k
, see below or [1].
- Returns:
- nfint or float or complex or ndarray
Multifactorial (order
k
) ofn
, as integer, float or complex (depending onexact
andextend
). 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 remainderr < k
(thusn = m * k + r
, resp.r = n % k
), which can be put together into something valid for all integer valuesn >= 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 relationr = n%k
ton
) would provide a suitable analytic continuation from integern
to complexz
(not only satisfying the functional equation but also being logarithmically convex, c.f. Bohr-Mollerup theorem) – in fact, the choice ofr
above only changes the function by a constant factor. The final constraint that determines the canonical continuation isf(1) = 1
, which forcesr = 1
(see also [1]).:z!(k) = k ** ((z - 1)/k) * gamma(z/k + 1) / gamma(1/k + 1)
References
[1]Complex extension to multifactorial https://en.wikipedia.org/wiki/Double_factorial#Alternative_extension_of_the_multifactorial
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.])