Skip to contents

\(D_n\) is the nearest integer to \(n!/e\), with \(|D_n - n!/e| < 1/(n+1)\). Verified here by computing \(D_n\) twice in exact integers – by the recurrence \(D_n = (n-1)(D_{n-1} + D_{n-2})\) and by the inclusion-exclusion sum \(\sum_k (-1)^k n!/k!\) – and requiring the two to agree digit for digit. The alternating tail of the sum is what supplies the \(1/(n+1)\) bound, so agreement of the two routes IS the identity. Past \(n = 18\), \(n!/e\) does not fit a double.

Usage

morie_derangement_rounding(n)

Arguments

n

Number of objects.

Value

A list with derangements, exact (decimal string), routes_agree, is_nearest_integer, within_theoretical_bound.

Examples

morie_derangement_rounding(n = 5L)
#> $derangements
#> [1] 44
#> 
#> $exact
#> [1] "44"
#> 
#> $estimate
#> [1] 44
#> 
#> $routes_agree
#> [1] TRUE
#> 
#> $is_nearest_integer
#> [1] TRUE
#> 
#> $within_theoretical_bound
#> [1] TRUE
#> 
#> $distance_bound
#> [1] 0.1666667
#> 
#> $n
#> [1] 5
#> 
#> $warnings
#> character(0)
#> 
#> $method
#> [1] "Meromorphic asymptotics: D_n = round(n!/e)"
#>