This site is supported by donations to The OEIS Foundation.
Template:Derangements/doc
From OeisWiki
derangements}} mathematical function template returns the subfactorial
, i.e. the number of derangements of
otherwise returns an error message.
for a nonnegative integer
otherwise returns an error message.
elements with no rencontres, i.e. no fixed points.
Examples with valid argument
and
rounded to nearest integer yields
, for
, where
and
are the number of arrangements and the number of derangements of
, respectively.
Examples with valid, but out of range, argument
The {{!n |
n, 0 ≤ n ≤ 12, |
Contents
Usage
- {{derangements|a nonnegative integer}}
or
- {{subfactorial|a nonnegative integer}}
or
- {{subfact|a nonnegative integer}}
or
- {{!n|a nonnegative integer}}
Valid argument
Returns!n |
n, 0 ≤ n ≤ 12, |
Examples
A000166 Subfactorial numbers, or number of derangements: number of permutations ofn, n ≥ 0, |
- {1, 0, 1, 2, 9, 44, 265, 1854, 14833, 133496, 1334961, 14684570, 176214841, 2290792932, 32071101049, 481066515734, 7697064251745, 130850092279664, 2355301661033953, ...}
Examples with valid argument 0 ≤ n ≤ 12
(returns the number of derangements)
Code Result {{derangements|12}} 176214841 {{subfactorial|12}} 176214841 {{subfact|12}} 176214841 {{!n|12}} 176214841
Code Result {{!n|0}} 1 {{!n|1}} 0 {{!n|2}} 1 {{!n|3}} 2 {{!n|4}} 9 {{!n|5}} 44 {{!n|6}} 265 {{!n|7}} 1854 {{!n|8}} 14833 {{!n|9}} 133496 {{!n|10}} 1334961 {{!n|11}} 14684570 {{!n|12}} 176214841
an |
dn |
n! |
n ≥ 2 |
an |
dn |
n |
Code Result Code Result {{root| {{arrangements|0}} * {{derangements|0}} }} √ 1 * 1{{n!|0}} 1 {{root| {{arrangements|1}} * {{derangements|1}} }} √ 2 * 0{{n!|1}} 1 {{root| {{arrangements|2}} * {{derangements|2}} }} √ 5 * 1{{n!|2}} 2 {{root| {{arrangements|3}} * {{derangements|3}} }} √ 16 * 2{{n!|3}} 6 {{root| {{arrangements|4}} * {{derangements|4}} }} √ 65 * 9{{n!|4}} 24 {{root| {{arrangements|5}} * {{derangements|5}} }} √ 326 * 44{{n!|5}} 120 {{root| {{arrangements|6}} * {{derangements|6}} }} √ 1957 * 265{{n!|6}} 720 {{root| {{arrangements|7}} * {{derangements|7}} }} √ 13700 * 1854{{n!|7}} 5040 {{root| {{arrangements|8}} * {{derangements|8}} }} √ 109601 * 14833{{n!|8}} 40320 {{root| {{arrangements|9}} * {{derangements|9}} }} √ 986410 * 133496{{n!|9}} 362880
Examples with valid, but out of range, argument n ≥ 13
(returns a not so user friendly error message)
Code Result {{!n|13}} 2290792932 {{!n|14}} 32071101049 {{!n|15}} 481066515734 {{!n|16}} 7697064251745 {{!n|80}} 9.680042524614E+34
Examples with invalid argument (returns a user friendly error message)
Code Result {{!n|-1}} Derangements error: Argument must be a nonnegative integer {{!n|0.5}} Derangements error: Argument must be a nonnegative integer {{!n|text}} Derangements error: Argument must be a nonnegative integer {{!n|6 blobs}} Derangements error: Argument must be a nonnegative integer
Code
{{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}} }}
Code for {{arrangements}}
{{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}} }}
See also
- {{factorial}} or {{n!}}
- {{rising factorial}} or {{risefact}} or {{Pochhammer}} or {{Poch}} or {{x^(n)}}
- {{falling factorial}} or {{fallfact}} or {{(x)_n}}
- {{derangements}} or {{subfactorial}} or {{subfact}} or {{!n}}
- {{arrangements}}