Double factorial function
This functionality does not run in MATLAB.
n !! fact2(n)
fact2(n) represents the double factorial of an integer. The double factorial is defined as for even positive integers and for odd positive integers.
The short hand call n!! is equivalent to fact2(n).
0!! and (-1)!! both return 1.
If n is an integer greater or equal to -1 and smaller than the value given by Pref::autoExpansionLimit(), then an integer is returned. If n is an integer smaller than -1 or a non-integer numerical value then an error occurs. If n is a symbolic expression, then a symbolic call of fact2 is returned.
Use expand(n!!) to compute an explicit result for large integers n equal to or larger than Pref::autoExpansionLimit().
Note that the double factorial n!! does not equal the iterated factorial (n!)!.
Integer numbers are produced if the argument is an integer greater than or equal to - 1:
fact2(-1), fact2(0), fact2(5), fact2(16)
A symbolic call is returned if the argument is a symbolic expression:
The calls fact2(n) and n!! are equivalent:
5!! = fact2(5), fact2(n^2 + 3)
rewrite(fact2(2*n)/fact2(2*n - 1), gamma)
assume(n, Type::Integer): Simplify(%2)
For efficiency, the double factorial should be rewritten in terms of gamma if a floating-point evaluation for large arguments is desired. The following call produces a huge exact integer that is finally converted to a float:
The following call is much faster because no exact intermediate result is computed:
float(subs(rewrite(fact2(n), gamma), n = 2^17))
An arithmetical expression representing an integer greater than or equal to - 1.