This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

!!, fact2

Double factorial function

MuPAD® notebooks are not recommended. Use MATLAB® live scripts instead.

MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.


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().

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!)!.


Example 1

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)

Example 2

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)

Example 3

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.

Return Values

Arithmetical expression.

Overloaded By


See Also

MuPAD Functions

Was this topic helpful?