The
{{arrangements}} mathematical function template returns the
number of arrangements of
otherwise returns an error message.
Usage
- {{arrangements|a nonnegative integer}}
or (by analogy with subfactorial, i.e. number of derangements: unfortunately the term superfactorial[1] has another meaning)
{{superfactorial|a nonnegative integer}}
or (by analogy with subfactorial, i.e. number of derangements: unfortunately the term superfactorial[1] has another meaning)
{{superfact|a nonnegative integer}}
Valid arguments
Returns the
number of arrangements for a
nonnegative integer otherwise returns an error message.
Examples
A000522 The
number of arrangements of
- {1, 2, 5, 16, 65, 326, 1957, 13700, 109601, 986410, 9864101, 108505112, 1302061345, 16926797486, 236975164805, 3554627472076, 56874039553217, 966858672404690, ...}
Examples with valid argument (returns the number of arrangements)
Code
|
Result
|
{{arrangements|0}} |
1
|
{{arrangements|1}} |
2
|
{{arrangements|2}} |
5
|
{{arrangements|3}} |
16
|
{{arrangements|4}} |
65
|
{{arrangements|5}} |
326
|
{{arrangements|6}} |
1957
|
{{arrangements|7}} |
13700
|
{{arrangements|8}} |
109601
|
{{arrangements|9}} |
986410
|
{{arrangements|10}} |
9864101
|
{{arrangements|11}} |
108505112
|
{{arrangements|12}} |
1302061345
|
The
geometric mean of
and
rounded to nearest integer yields
, for
, where
and
are the
number of arrangements and the
number of derangements of
, respectively.
Code
|
Result
|
|
Code
|
Result
|
{{root| {{arrangements|0}} * {{derangements|0}} }}
|
2√ 1 * 1
|
|
{{n!|0}}
|
1
|
{{root| {{arrangements|1}} * {{derangements|1}} }}
|
2√ 2 * 0
|
|
{{n!|1}}
|
1
|
{{root| {{arrangements|2}} * {{derangements|2}} }}
|
2√ 5 * 1
|
|
{{n!|2}}
|
2
|
{{root| {{arrangements|3}} * {{derangements|3}} }}
|
2√ 16 * 2
|
|
{{n!|3}}
|
6
|
{{root| {{arrangements|4}} * {{derangements|4}} }}
|
2√ 65 * 9
|
|
{{n!|4}}
|
24
|
{{root| {{arrangements|5}} * {{derangements|5}} }}
|
2√ 326 * 44
|
|
{{n!|5}}
|
120
|
{{root| {{arrangements|6}} * {{derangements|6}} }}
|
2√ 1957 * 265
|
|
{{n!|6}}
|
720
|
{{root| {{arrangements|7}} * {{derangements|7}} }}
|
2√ 13700 * 1854
|
|
{{n!|7}}
|
5040
|
{{root| {{arrangements|8}} * {{derangements|8}} }}
|
2√ 109601 * 14833
|
|
{{n!|8}}
|
40320
|
{{root| {{arrangements|9}} * {{derangements|9}} }}
|
2√ 986410 * 133496
|
|
{{n!|9}}
|
362880
|
Examples with valid, but out of range, argument (returns a not so user friendly error message)
Code
|
Result
|
{{arrangements|13}} |
16926797486
|
{{arrangements|14}} |
236975164805
|
{{arrangements|15}} |
3554627472076
|
{{arrangements|16}} |
56874039553217
|
{{arrangements|80}} |
7.1526377254407E+35
|
Examples with invalid argument (returns a user friendly error message)
Code
|
Result
|
{{arrangements|-1}} |
Arrangements error: Argument must be a nonnegative integer
|
{{arrangements|0.5}} |
Arrangements error: Argument must be a nonnegative integer
|
{{arrangements|text}} |
Arrangements error: Argument must be a nonnegative integer
|
{{arrangements|6 blobs}} |
Arrangements error: Argument must be a nonnegative integer
|
Code
{{ifint| ( {{{1|empty}}} )
| {{#ifexpr: ( {{{1}}} ) >= 0
| {{#ifexpr: ( {{{1}}} ) = 0
| 1
| {{expr| floor ( {{~Pochhammer| 1 | ( {{{1}}} ) | 1 }} * e ) }}
}}
| {{error| Arrangements error: Argument must be a nonnegative integer}}
}}
| {{error| Arrangements error: Argument must be a nonnegative integer}}
}}
Gotcha: using round instead of ceil
Using round instead of ceil gives 3 instead of 2 for , otherwise results seem to agree.
{{ifint| ( {{{1|empty}}} )
| {{#ifexpr: ( {{{1}}} ) >= 0
| {{#ifexpr: ( {{{1}}} ) = 0
| 1
| {{expr| ( {{~Pochhammer| 1 | ( {{{1}}} ) | 1 }} * e ) round 0 }}
}}
| {{error| Derangements error: Argument must be a nonnegative integer}}
}}
| {{error| Derangements error: Argument must be a nonnegative integer}}
}}
{{ifint| ( {{{1|empty}}} )
| {{#ifexpr: ( {{{1}}} ) >= 0
| {{#ifexpr: ( {{{1}}} ) = 0
| 1
| {{expr| ( {{~Pochhammer| 1 | ( {{{1}}} ) | 1 }} / e ) round 0 }}
}}
| {{error| Derangements error: Argument must be a nonnegative integer}}
}}
| {{error| Derangements error: Argument must be a nonnegative integer}}
}}
Notes
See also