Last data update: 2014.03.03

R: Stirling Number of The Second Kind
Strlng2R Documentation

Stirling Number of The Second Kind

Description

Asymptotically computes natural logarithm of Stirling numbers of the second kind for large values of inputs by the approach of Bleick and Wang (1954) and Temme (1993). For small or moderate values of inputs, this function is not as precise as available functions.

Usage

Strlng2(n, k, log = TRUE)

Arguments

n

positive integer greater than zero.

k

positive integer between 1 and n.

log

if TRUE, natural logarithm of the Stirling numbers of the second kind is returned.

Details

Due to the overflows in the calculation of large factorials, an asymptotic calculation of the Stirling numbers of the second kind is required. This function makes use of Lambert W function to calculate the Stirling numbers of the second kind with large values of n and k.

Value

Stirling.num

the corresponding Stirling number of the second kind to the pair (n,k).

Author(s)

Haydar Demirhan

Maintainer: Haydar Demirhan <haydarde@hacettepe.edu.tr>

References

Bleick, W.W., Wang, P.C.C., Asymptotics of Stirling Numbers of the Second Kind. Proceedings of the American Mathematical Society (1974), 42(2), 575–580.

Temme, N.M., Asymptotic estimates of Stirling numbers. Studies in Applied Mathematics (1993), 89, 233–243.

See Also

See also Stirling2 function from the package copula.

Examples

# When n = 10 and k = 4, exact value is 34105
gmp::Stirling2(10,4)           
Strlng2(10,4,log=FALSE)
# ---- Moderate values of n and k ----
# When n = 30 and k = 20, exact value is 581535955088511150
log(581535955088511150)-log(gmp::Stirling2(30,20))
log(581535955088511150)-Strlng2(30,20,log=TRUE)  
# ---- Large values of n and k ----
gmp::Stirling2(50,10)
Strlng2(50,10,log=FALSE) 

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(CryptRndTest)
Loading required package: MissMech
Loading required package: kSamples
Loading required package: SuppDists
Loading required package: sfsmisc
Loading required package: Rmpfr
Loading required package: gmp

Attaching package: 'gmp'

The following objects are masked from 'package:sfsmisc':

    factorize, is.whole

The following objects are masked from 'package:base':

    %*%, apply, crossprod, matrix, tcrossprod

C code of R package 'Rmpfr': GMP using 64 bits per limb


Attaching package: 'Rmpfr'

The following objects are masked from 'package:stats':

    dbinom, dnorm, dpois, pnorm

The following objects are masked from 'package:base':

    cbind, pmax, pmin, rbind

Loading required package: parallel
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/CryptRndTest/Strlng2.Rd_%03d_medium.png", width=480, height=480)
> ### Name: Strlng2
> ### Title: Stirling Number of The Second Kind
> ### Aliases: Strlng2
> ### Keywords: approximation large factorials
> 
> ### ** Examples
> 
> # When n = 10 and k = 4, exact value is 34105
> gmp::Stirling2(10,4)           
Big Integer ('bigz') :
[1] 34105
> Strlng2(10,4,log=FALSE)
1 'mpfr' number of precision  250   bits 
[1] 34318.637340463845965440885499750212498821914500806637414602719628462478580532
> # ---- Moderate values of n and k ----
> # When n = 30 and k = 20, exact value is 581535955088511150
> log(581535955088511150)-log(gmp::Stirling2(30,20))
[1] 7.105427e-15
> log(581535955088511150)-Strlng2(30,20,log=TRUE)  
[1] -0.001070329
> # ---- Large values of n and k ----
> gmp::Stirling2(50,10)
Big Integer ('bigz') :
[1] 26154716515862881292012777396577993781727011
> Strlng2(50,10,log=FALSE) 
1 'mpfr' number of precision  250   bits 
[1] 26175204244392228378199474112731156675968829.472192027975523762778324299824879
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>