Factorial2¶
Status: Stable
documented, exercised by the test suite and/or worked examples, with no known limitations recorded.
Description¶
Factorial2[n] (also typeset n!!) gives the double factorial of n.
Notes
For non-negative integer n: n!! = n \* (n-2) \* (n-4) \* ... down to 2 (n even) or 1 (n odd). Special values: 0!! = 1, (-1)!! = 1. Negative even integers and negative odd integers below -1 give ComplexInfinity. A non-integer numeric argument (under N) evaluates via 2^(n/2) (Pi/2)^((Cos\[n Pi\]-1)/4) Gamma\[n/2+1\] (real, complex, arbitrary precision). Factorial2 stays unevaluated on symbolic arguments.Examples (5)¶
Every input below was run against the current Mathilda build and its output recorded.
Applications (5)¶
In[1]:= Factorial2[7]
Out[1]= 105
In[2]:= Factorial2[8]
Out[2]= 384
In[3]:= 0!!
Out[3]= 1
In[4]:= Factorial2[19] Factorial2[20]
Out[4]= 2432902008176640000
In[5]:= Factorial2[19] Factorial2[20] == 20!
Out[5]= True
Implementation notes¶
builtin_factorial2 computes the double factorial n!! = n(n-2)(n-4)… by an explicit step-2 product loop. For small non-negative EXPR_INTEGER (n ≤ 30) it accumulates in an int64_t; for larger integers and EXPR_BIGINT it accumulates in a GMP mpz_t and returns an EXPR_BIGINT. Special cases: (-1)!! = 0!! = 1; negative integers return ComplexInfinity (poles of the analytic continuation). A BigInt argument too large for mpz_fits_ulong_p returns NULL (left symbolic) rather than attempting an unbounded loop. Non-integer arguments return NULL so Factorial2[x] stays symbolic. The function does not use the Gamma-based continuation for non-integers.
Attributes: Listable, NumericFunction, Protected.
References¶
- Source:
src/info.c - Specification:
docs/spec/builtins/arithmetic.md - Tests:
tests/test_compile_coverage.c - Tests:
tests/test_factorial_simplify.c - Tests:
tests/test_integer_assume_simplify.c - Tests:
tests/test_numeric_domain.c
Notes & additional examples¶
Notes¶
Factorial2[n] (also typeset n!!) is the double factorial: it multiplies down in steps of 2, so 7!! = 7*5*3*1 = 105 and 8!! = 8*6*4*2 = 384. By convention 0!! = (-1)!! = 1. The interleaving identity (n-1)!! · n!! = n! is exact here: the product of the odd double factorial 19!! and the even double factorial 20!! reproduces 20! term for term.