Function Repository Resource:

MultiFactorial

Source Notebook

Evaluate the multifactorial function

Contributed by: Jan Mangaldan

ResourceFunction["MultiFactorial"][n,k]

gives the kth multifactorial of n.

Details

Mathematical function, suitable for both symbolic and numerical manipulation.
For integer n, the kth multifactorial of nn!(k) is equal to n if 0<nk, and n ((n-k)!(k)) if k<n.
For certain special arguments, ResourceFunction["MultiFactorial"] automatically evaluates to exact values.
ResourceFunction["MultiFactorial"] can be evaluated to arbitrary numerical precision.
ResourceFunction["MultiFactorial"] automatically threads over lists.

Examples

Basic Examples (2) 

Integer values:

In[1]:=
Table[ResourceFunction["MultiFactorial"][n, 3], {n, 10}]
Out[1]=
In[2]:=
ResourceFunction["MultiFactorial"][50, 4]
Out[2]=

Evaluate numerically:

In[3]:=
ResourceFunction["MultiFactorial"][5.5, 4]
Out[3]=

Scope (4) 

Evaluate for large arguments:

In[4]:=
ResourceFunction["MultiFactorial"][10000, 3] // Short
Out[4]=
In[5]:=
N[%]
Out[5]=

Evaluate at negative integers:

In[6]:=
Table[ResourceFunction["MultiFactorial"][-n, 5], {n, 7}]
Out[6]=

Evaluate for complex arguments:

In[7]:=
ResourceFunction["MultiFactorial"][-0.1 + 0.2 I, 3]
Out[7]=

MultiFactorial threads elementwise over lists:

In[8]:=
ResourceFunction["MultiFactorial"][{2, 3, 5, 7}, 4]
Out[8]=

Properties and Relations (2) 

MultiFactorial[n,1] is equivalent to Factorial[n] (n!):

In[9]:=
Table[ResourceFunction["MultiFactorial"][n, 1] == n!, {n, 7}]
Out[9]=

MultiFactorial[n,2] is equivalent to Factorial2[n] (n!!):

In[10]:=
Table[ResourceFunction["MultiFactorial"][n, 2] == n!!, {n, 7}]
Out[10]=

Possible Issues (2) 

Large arguments can give results too large to be computed explicitly, even approximately:

In[11]:=
ResourceFunction["MultiFactorial"][10.^13, 4]
Out[11]=

Machine-number inputs can give arbitrary‐precision results:

In[12]:=
ResourceFunction["MultiFactorial"][10.^6, 5]
Out[12]=
In[13]:=
MachineNumberQ[%]
Out[13]=

Neat Examples (1) 

Evaluate various reciprocal multifactorial constants:

In[14]:=
Table[\!\(
\*UnderoverscriptBox[\(\[Sum]\), \(n = 0\), \(\[Infinity]\)]\*
FractionBox["1", 
RowBox[{
InterpretationBox[
TagBox[
DynamicModuleBox[{Typeset`open = False}, 
FrameBox[
PaneSelectorBox[{False->GridBox[{
{
PaneBox[GridBox[{
{
StyleBox[
StyleBox[
AdjustmentBox["\<\"[\[FilledSmallSquare]]\"\>",
BoxBaselineShift->-0.25,
BoxMargins->{{0, 0}, {-1, -1}}], "ResourceFunctionIcon",
FontColor->RGBColor[
                   0.8745098039215686, 0.2784313725490196, 0.03137254901960784]],
ShowStringCharacters->False,
FontFamily->"Source Sans Pro Black",
FontSize->0.6538461538461539 Inherited,
FontWeight->"Heavy",
PrivateFontOptions->{"OperatorSubstitution"->False}], 
StyleBox[
RowBox[{
StyleBox["MultiFactorial", "ResourceFunctionLabel",
FontFamily->"Source Sans Pro"], " "}],
ShowAutoStyles->False,
ShowStringCharacters->False,
FontSize->Rational[12, 13] Inherited,
FontColor->GrayLevel[0.1]]}
},
GridBoxSpacings->{"Columns" -> {{0.25}}}],
Alignment->Left,
BaseStyle->{LineSpacing -> {0, 0}, LineBreakWithin -> False},
BaselinePosition->Baseline,
FrameMargins->{{3, 0}, {0, 0}}], 
ItemBox[
PaneBox[
TogglerBox[Dynamic[Typeset`open], {True-> DynamicBox[FEPrivate`FrontEndResource[
                "FEBitmaps", "IconizeCloser"],
ImageSizeCache->{11., {1., 10.}}], False-> DynamicBox[FEPrivate`FrontEndResource[
                "FEBitmaps", "IconizeOpener"],
ImageSizeCache->{11., {1., 10.}}]},
Appearance->None,
BaselinePosition->Baseline,
ContentPadding->False,
FrameMargins->0],
Alignment->Left,
BaselinePosition->Baseline,
FrameMargins->{{1, 1}, {0, 0}}],
Frame->{{
RGBColor[
                0.8313725490196079, 0.8470588235294118, 0.8509803921568627, 0.5], False}, {False, False}}]}
},
BaselinePosition->{1, 1},
GridBoxAlignment->{"Columns" -> {{Left}}, "Rows" -> {{Baseline}}},
GridBoxItemSize->{"Columns" -> {{Automatic}}, "Rows" -> {{Automatic}}},
          
GridBoxSpacings->{"Columns" -> {{0}}, "Rows" -> {{0}}}], True->GridBox[{
{GridBox[{
{
PaneBox[GridBox[{
{
StyleBox[
StyleBox[
AdjustmentBox["\<\"[\[FilledSmallSquare]]\"\>",
BoxBaselineShift->-0.25,
BoxMargins->{{0, 0}, {-1, -1}}], "ResourceFunctionIcon",
FontColor->RGBColor[
                    0.8745098039215686, 0.2784313725490196, 0.03137254901960784]],
ShowStringCharacters->False,
FontFamily->"Source Sans Pro Black",
FontSize->0.6538461538461539 Inherited,
FontWeight->"Heavy",
PrivateFontOptions->{"OperatorSubstitution"->False}], 
StyleBox[
RowBox[{
StyleBox["MultiFactorial", "ResourceFunctionLabel",
FontFamily->"Source Sans Pro"], " "}],
ShowAutoStyles->False,
ShowStringCharacters->False,
FontSize->Rational[12, 13] Inherited,
FontColor->GrayLevel[0.1]]}
},
GridBoxSpacings->{"Columns" -> {{0.25}}}],
Alignment->Left,
BaseStyle->{LineSpacing -> {0, 0}, LineBreakWithin -> False},
BaselinePosition->Baseline,
FrameMargins->{{3, 0}, {0, 0}}], 
ItemBox[
PaneBox[
TogglerBox[Dynamic[Typeset`open], {True-> DynamicBox[FEPrivate`FrontEndResource[
                   "FEBitmaps", "IconizeCloser"]], False-> DynamicBox[FEPrivate`FrontEndResource[
                   "FEBitmaps", "IconizeOpener"]]},
Appearance->None,
BaselinePosition->Baseline,
ContentPadding->False,
FrameMargins->0],
Alignment->Left,
BaselinePosition->Baseline,
FrameMargins->{{1, 1}, {0, 0}}],
Frame->{{
RGBColor[
                   0.8313725490196079, 0.8470588235294118, 0.8509803921568627, 0.5], False}, {False, False}}]}
},
BaselinePosition->{1, 1},
GridBoxAlignment->{"Columns" -> {{Left}}, "Rows" -> {{Baseline}}},
GridBoxItemSize->{"Columns" -> {{Automatic}}, "Rows" -> {{Automatic}}},
             
GridBoxSpacings->{"Columns" -> {{0}}, "Rows" -> {{0}}}]},
{
StyleBox[
PaneBox[GridBox[{
{
RowBox[{
TagBox["\<\"Version (latest): \"\>",
"IconizedLabel"], " ", 
TagBox["\<\"1.0.1\"\>",
"IconizedItem"]}]},
{
TagBox[
TemplateBox[{"\"Documentation »\"", "https://resources.wolframcloud.com/FunctionRepository/resources/MultiFactorial"},
"HyperlinkURL"],
"IconizedItem"]}
},
DefaultBaseStyle->"Column",
GridBoxAlignment->{"Columns" -> {{Left}}},
GridBoxItemSize->{"Columns" -> {{Automatic}}, "Rows" -> {{Automatic}}}],
Alignment->Left,
BaselinePosition->Baseline,
FrameMargins->{{5, 4}, {0, 4}}], "DialogStyle",
FontFamily->"Roboto",
FontSize->11]}
},
BaselinePosition->{1, 1},
GridBoxAlignment->{"Columns" -> {{Left}}, "Rows" -> {{Baseline}}},
GridBoxDividers->{"Columns" -> {{None}}, "Rows" -> {False, {
GrayLevel[0.8]}, False}},
GridBoxItemSize->{"Columns" -> {{Automatic}}, "Rows" -> {{Automatic}}}]}, Dynamic[Typeset`open],
BaselinePosition->Baseline,
ImageSize->Automatic],
Background->RGBColor[
         0.9686274509803922, 0.9764705882352941, 0.984313725490196],
BaselinePosition->Baseline,
DefaultBaseStyle->{},
FrameMargins->{{0, 0}, {1, 0}},
FrameStyle->RGBColor[
         0.8313725490196079, 0.8470588235294118, 0.8509803921568627],
RoundingRadius->4]],
{"FunctionResourceBox", 
RGBColor[0.8745098039215686, 0.2784313725490196, 0.03137254901960784],
        "MultiFactorial"},
TagBoxNote->"FunctionResourceBox"],
ResourceFunction["MultiFactorial"],
BoxID -> "MultiFactorial",
Selectable->False], "[", 
RowBox[{"n", ",", "k"}], "]"}]]\), {k, {1, 2, 4}}]
Out[14]=

Version History

  • 1.0.1 – 01 March 2021
  • 1.0.0 – 08 February 2021

Related Resources

License Information