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 noninteger 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
().
Expressions involving symbolic calls of fact2
can
be rewritten in terms of the gamma
function
by rewrite(expression, gamma)
. Cf. Example 2.
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:
fact2(n), fact2(4.7*I*n)
The calls fact2(n)
and n!!
are
equivalent:
5!! = fact2(5), fact2(n^2 + 3)
The function rewrite
can
be used to rewrite expressions involving fact2
in
terms of the gamma
function.
In most cases, Simplify
has to be used to obtain a simple
result:
rewrite(n!!, gamma)
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 floatingpoint evaluation for large arguments is desired. The following
call produces a huge exact integer that is finally converted to a
float:
float(fact2(2^17))
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. 
Arithmetical expression.
n