expint/ 0000755 0001762 0000144 00000000000 13571662453 011575 5 ustar ligges users expint/NAMESPACE 0000644 0001762 0000144 00000000233 13103131603 012765 0 ustar ligges users ### C code
useDynLib(expint, .registration = TRUE, .fixes = "C_")
### Exports
export(expint, expint_E1, expint_E2, expint_En, expint_Ei)
export(gammainc)
expint/README.md 0000644 0001762 0000144 00000007567 13571545273 013073 0 ustar ligges users # expint
[](https://cran.r-project.org/package=expint) 
Exponential integral and incomplete gamma function for R.
## What it is
The exponential integral `E_1(x) = int_x^Inf exp(-t)/t dt` and the
incomplete gamma function `G(a, x) = int_x^Inf t^(a-1) exp(-t) dt`
are closely related functions that arise in various fields of
mathematics and statistics.
**expint** is a small R package that provides functions to compute
the exponential integral and the incomplete gamma function.
Most conveniently for R package developers, the package also gives
access to the underlying C workhorses through an API.
## Features
- R interface consisting of one main and four auxiliary functions to
compute the exponential integral, and one function to compute the
incomplete gamma function.
- Underlying C routines derived from mature and stable code of the
[GNU Scientific Library](https://www.gnu.org/software/gsl/).
- Test package implementing the access to the C routine
through the API. This test package uses the `.External` R to C
interface and, as a bonus, shows how to vectorize an R function on
the C side.
- Exhaustive
[package vignette](https://cran.r-project.org/package=expint/vignettes/expint.pdf)
providing all the details about the formulas that are implemented in
the package as well as a complete presentation of the API and its
usage.
## Examples
We tabulate the values of the exponential integral of order `n` for `x = 1.275, 10, 12.3` and
`n = 1, 2, ..., 10` as found in examples 4 through 6 of
[Abramowitz and Stegun (1972)](http://people.math.sfu.ca/~cbm/aands/), section 5.3.
```R
R> x <- c(1.275, 10, 12.3)
R > n <- 1:10
R> structure(t(outer(x, n, expint)),
+ dimnames = list(n, paste("x =", x)))
x = 1.275 x = 10 x = 12.3
1 0.14080993 4.156969e-06 3.439534e-07
2 0.09989831 3.830240e-06 3.211177e-07
3 0.07603031 3.548763e-06 3.009983e-07
4 0.06083077 3.304101e-06 2.831550e-07
5 0.05046793 3.089729e-06 2.672346e-07
6 0.04301687 2.900528e-06 2.529517e-07
7 0.03743074 2.732441e-06 2.400730e-07
8 0.03310097 2.582217e-06 2.284066e-07
9 0.02965340 2.447221e-06 2.177930e-07
10 0.02684699 2.325303e-06 2.080990e-07
```
We also tabulate the values of the incomplete gamma function for
`a = -1.5, -1, -0.5, 1` and `x = 1, 2, ..., 10`.
```R
R> a <- c(-1.5, -1, -0.5, 1)
R> x <- 1:10
R> structure(t(outer(a, x, gammainc)),
+ dimnames = list(x, paste("a =", a)))
a=-1.5 a=-1 a=-0.5 a=1
1 1.264878e-01 1.484955e-01 1.781477e-01 3.678794e-01
2 1.183299e-02 1.876713e-02 3.009876e-02 1.353353e-01
3 1.870260e-03 3.547308e-03 6.776136e-03 4.978707e-02
4 3.706365e-04 7.995573e-04 1.733500e-03 1.831564e-02
5 8.350921e-05 1.992938e-04 4.773965e-04 6.737947e-03
6 2.045031e-05 5.304291e-05 1.379823e-04 2.478752e-03
7 5.310564e-06 1.478712e-05 4.127115e-05 9.118820e-04
8 1.440569e-06 4.267206e-06 1.266464e-05 3.354626e-04
9 4.042025e-07 1.264846e-06 3.964430e-06 1.234098e-04
10 1.165117e-07 3.830240e-07 1.260904e-06 4.539993e-05
```
## Status
Unless important bugs are discovered either upstream in the GSL
functions or in our adaptation, the code base of the package is not
expected to change much in the future. In other words: stable.
## Installation
You should install the stable version of the package from the
[Comprehensive R Archive Network (CRAN)](https://cran.r-project.org/package=expint)
using:
```R
install.packages("expint")
```
## Author
Vincent Goulet is the author and maintainer of the package. Many other
copyright holders (for the original GSL code and for parts of the base
R code) are credited in the `DESCRIPTION` file.
## License
**expint** is free software licensed under the [GNU General Public
License (GPL)](https://www.gnu.org/copyleft/gpl.html), version 2 or later.
expint/man/ 0000755 0001762 0000144 00000000000 13044217657 012345 5 ustar ligges users expint/man/gammainc.Rd 0000644 0001762 0000144 00000003521 13044217657 014411 0 ustar ligges users \name{gammainc}
\alias{gammainc}
\alias{gamma_inc}
\alias{IncompleteGammaFunction}
\title{Incomplete Gamma Function}
\description{
The incomplete gamma function \eqn{\Gamma(a, x)}{G(a, x)}.
}
\usage{
gammainc(a, x)
}
\arguments{
\item{a}{vector of real numbers.}
\item{x}{vector of non-negative real numbers.}
}
\details{
As defined in 6.5.3 of Abramowitz and Stegun (1972), the incomplete
gamma function is
\deqn{
\Gamma(a, x) = \int_x^\infty t^{a-1} e^{-t}\, dt}{%
G(a, x) = int_x^Inf t^(a - 1) exp(-t) dt}
for \eqn{a} real and \eqn{x \ge 0}.
For non-negative values of \eqn{a}, we have
\deqn{
\Gamma(a, x) = \Gamma(a) (1 - P(a, x)),}{%
G(a, x) = Gamma(a) (1 - P(a, x)),}
where \eqn{\Gamma(a)}{Gamma(a)} is the function implemented
by \R's \code{\link{gamma}()} and \eqn{P(a, x)}{P(a, x)} is the
cumulative distribution function of the gamma distribution (with scale
equal to one) implemented by \R's \code{\link{pgamma}()}.
Also, \eqn{\Gamma(0, x) = E_1(x)}{G(0, x) = E_1(x)}, \eqn{x > 0},
where \eqn{E_1(x)} is the exponential integral implemented in
\code{\link{expint}}.
}
\value{
The value of the incomplete gamma function.
Invalid arguments will result in return value \code{NaN}, with a warning.
}
\note{
The C implementation is based on code from the GNU Software Library
\url{https://www.gnu.org/software/gsl/}.
}
\references{
Abramowitz, M. and Stegun, I. A. (1972), \emph{Handbook of Mathematical
Functions}, Dover.
}
\seealso{
\code{\link{expint}}
}
\author{
Vincent Goulet \email{vincent.goulet@act.ulaval.ca}
}
\examples{
## a > 0
x <- c(0.2, 2.5, 5, 8, 10)
a <- 1.2
gammainc(a, x)
gamma(a) * pgamma(x, a, 1, lower = FALSE) # same
## a = 0
a <- 0
gammainc(a, x)
expint(x) # same
## a < 0
a <- c(-0.25, -1.2, -2)
sapply(a, gammainc, x = x)
}
\keyword{math}
expint/man/expint-package.Rd 0000644 0001762 0000144 00000003006 13044217657 015533 0 ustar ligges users \name{expint-package}
\alias{expint-package}
\docType{package}
\title{
\packageTitle{expint}
}
\description{
The exponential integrals \eqn{E_1(x)}, \eqn{E_2(x)}, \eqn{E_n(x)} and
\eqn{Ei(x)}, and the incomplete gamma function \eqn{\Gamma(a, x)}{G(a,
x)} that is defined for negative values of its first argument.
}
\details{
The exponential integral
\deqn{
E_1(x) = \int_x^\infty \frac{e^{-t}}{t}\, dt}{%
E_1(x) = int_x^Inf exp(-t)/t dt}
and the incomplete gamma function
\deqn{
\Gamma(a, x) = \int_x^\infty t^{a-1} e^{-t}\, dt}{%
G(a, x) = int_x^Inf t^(a-1) exp(-t) dt}
are closely related functions that arise in various fields of
mathematics.
\pkg{expint} is a small package that provides \R functions to compute
the exponential integral and the incomplete gamma function.
Most conveniently for \R package developers, the package also gives
access to the underlying C workhorses through an API; see the package
vignette for instructions.
The C routines are adapted versions of those of the GNU Scientific
Library \url{https://www.gnu.org/software/gsl/}.
}
\seealso{
\code{\link{expint}} for the exponential integral family of functions.
\code{\link{gammainc}} for the incomplete gamma function.
\code{vignette("expint")} for a detailed presentation of the package.
}
\author{
Vincent Goulet \email{vincent.goulet@act.ulaval.ca}
}
\references{
Abramowitz, M. and Stegun, I. A. (1972), \emph{Handbook of Mathematical
Functions}, Dover.
}
\keyword{package}
\keyword{math}
expint/man/expint.Rd 0000644 0001762 0000144 00000006475 13044217657 014157 0 ustar ligges users \name{expint}
\alias{expint}
\alias{expint_E1}
\alias{expint_E2}
\alias{expint_En}
\alias{expint_Ei}
\alias{ExponentialIntegral}
\title{Exponential Integral}
\description{
The exponential integrals \eqn{E_1(x)}, \eqn{E_2(x)}, \eqn{E_n(x)} and
\eqn{Ei}.
}
\usage{
expint(x, order = 1L, scale = FALSE)
expint_E1(x, scale = FALSE)
expint_E2(x, scale = FALSE)
expint_En(x, order, scale = FALSE)
expint_Ei(x, scale = FALSE)
}
\arguments{
\item{x}{vector of real numbers.}
\item{order}{vector of non-negative integers; see Details.}
\item{scale}{logical; when \code{TRUE} the result will be scaled by
\eqn{e^x}{exp(x)}.}
}
\details{
Abramowitz and Stegun (1972) first define the exponential
integral as
\deqn{
E_1(x) = \int_x^\infty \frac{e^{-t}}{t}\, dt, \quad x \ne 0.}{%
E_1(x) = int_x^Inf exp(-t)/t dt, x != 0.}
An alternative definition (to be understood in terms of the Cauchy
principal value due to the singularity of the integrand at zero) is
\deqn{
\mathrm{Ei}(x) = - \int_{-x}^\infty \frac{e^{-t}}{t}\, dt
= - E_1(-x).}{%
Ei(x) = - int_{-x}^Inf exp(-t)/t dt = - E_1(-x).}
The exponential integral can also generalized to \code{order} \eqn{n} as
\deqn{
E_n(x) = \int_1^\infty \frac{e^{-xt}}{t^n}\, dt,}{%
E_n(x) = int_1^Inf exp(-xt)/t^n dt,}
for \eqn{n = 0, 1, 2, \dots}; \eqn{x} a real number (non-negative when
\eqn{n > 2}).
The following relation holds:
\deqn{
E_n(x) = x^{n - 1} \Gamma(1 - n, x),}{%
E_n(x) = x^(n-1) G(1-n, x),}
where \eqn{\Gamma(a, x)}{G(a, x)} is the incomplete gamma function
implemented in \code{\link{gammainc}}.
By definition, \eqn{E_0(x) = x^{-1} e^{-x}}{E_0(x) = exp(-x)/x},
\eqn{x \ne 0}{x != 0}.
Function \code{expint} is vectorized in both \code{x} and
\code{order}, whereas function \code{expint_En} expects a single value
for \code{order} and will only use the first value if \code{order} is
a vector.
Non-integer values of \code{order} will be silently coerced to
integers using truncation towards zero.
}
\value{
The value of the exponential integral.
Invalid arguments will result in return value \code{NaN}, with a warning.
}
\note{
The C implementation is based on code from the GNU Software Library
\url{https://www.gnu.org/software/gsl/}.
}
\references{
Abramowitz, M. and Stegun, I. A. (1972), \emph{Handbook of Mathematical
Functions}, Dover.
}
\seealso{
\code{\link{gammainc}}
}
\author{
Vincent Goulet \email{vincent.goulet@act.ulaval.ca}
}
\examples{
## See section 5.3 of Abramowitz and Stegun
expint(1.275, order = 1:10)
expint(10, order = 1:10) * 1e5
expint(c(1.275, 10), order = c(1, 2))
expint_E1(1.275) # same as above
expint_E2(10) # same as above
## Figure 5.1 of Abramowitz and Stegun
curve(expint_Ei, xlim = c(0, 1.6), ylim = c(-3.9, 3.9),
ylab = "y")
abline(h = 0)
curve(expint_E1, add = TRUE)
x <- 1.5
text(x, c(expint_Ei(x), expint_E1(x)),
expression(Ei(x), E[1](x)),
adj = c(0.5, -0.5))
## Figure 5.2 of Abramowitz and Stegun
plot(NA, xlim = c(-1.6, 1.6), ylim = c(0, 1),
xlab = "x", ylab = expression(E[n](x)))
n <- c(10, 5, 3, 2, 1, 0)
for (order in n)
curve(expint_En(x, order), add = TRUE)
x <- c(0.1, 0.15, 0.25, 0.35, 0.5, 0.7)
text(x, expint(x, n), paste("n =", n),
adj = c(-0.2, -0.5))
}
\keyword{math}
expint/DESCRIPTION 0000644 0001762 0000144 00000004301 13571662453 013301 0 ustar ligges users Package: expint
Type: Package
Title: Exponential Integral and Incomplete Gamma Function
Version: 0.1-6
Date: 2019-12-03
Authors@R: c(person("Vincent", "Goulet", role = c("cre", "aut"),
email = "vincent.goulet@act.ulaval.ca"),
person("Gerard", "Jungman", role = "aut",
email = "jungman@lanl.gov",
comment = "Original GSL code"),
person("Brian", "Gough", role = "aut",
email = "jungman@lanl.gov",
comment = "Original GSL code"),
person("Jeffrey A.", "Ryan", role = "aut",
email = "jeff.a.ryan@gmail.com",
comment = "Package API"),
person("Robert", "Gentleman", role = "aut",
comment = "Parts of the R to C interface"),
person("Ross", "Ihaka", role = "aut",
comment = "Parts of the R to C interface"),
person(family = "R Core Team", role = "aut",
comment = "Parts of the R to C interface"),
person(family = "R Foundation", role = "aut",
comment = "Parts of the R to C interface"))
Description: The exponential integrals E_1(x), E_2(x), E_n(x) and
Ei(x), and the incomplete gamma function G(a, x) defined for
negative values of its first argument. The package also gives easy
access to the underlying C routines through an API; see the package
vignette for details. A test package included in sub-directory
example_API provides an implementation. C routines derived from the
GNU Scientific Library .
Depends: R (>= 3.3.0)
License: GPL (>= 2)
URL: https://gitlab.com/vigou3/expint
BugReports: https://gitlab.com/vigou3/expint/issues
Encoding: UTF-8
LazyLoad: yes
LazyData: yes
NeedsCompilation: yes
Packaged: 2019-12-03 21:04:58 UTC; vincent
Author: Vincent Goulet [cre, aut],
Gerard Jungman [aut] (Original GSL code),
Brian Gough [aut] (Original GSL code),
Jeffrey A. Ryan [aut] (Package API),
Robert Gentleman [aut] (Parts of the R to C interface),
Ross Ihaka [aut] (Parts of the R to C interface),
R Core Team [aut] (Parts of the R to C interface),
R Foundation [aut] (Parts of the R to C interface)
Maintainer: Vincent Goulet
Repository: CRAN
Date/Publication: 2019-12-04 07:50:03 UTC
expint/build/ 0000755 0001762 0000144 00000000000 13571546771 012700 5 ustar ligges users expint/build/vignette.rds 0000644 0001762 0000144 00000000312 13571546771 015233 0 ustar ligges users b```b`fff`b2 1#'J(++G()&&[&3 a8DXԱ%ifwI-HK î?}ީE0=(jؠjX2sRad9.nP&c0Gq?gQ~n ݣ9JI,IK+ I\b expint/build/partial.rdb 0000644 0001762 0000144 00000007420 13571546764 015032 0 ustar ligges users kWFVl IH(v
a `Lȣ$
%NBOIt{jYr%@9o/{ˠGLs{wkq.r,E/_}pwc!RC5qӁjc]Ы:Q͉x˞o
oIE9wIV=sv^,=ZDYy&HS:6<͗W|`Po|_+WpqUѕ&OAefL\l zQFXEY*|&*~(I?Z}Nbwbe)+ptOzuA-`"zD~Bq4TaxNI%yroaq)]<+[;
ѿS~'DI!ƙ/[']Qx,rE} 4UH4$D( ^ Bj6V9jL,AE/*aĴJ.8P+"ʑSge{oSFS1'HV~bMMSG:)
-,8<8»rek}&dZYW.TuC>ʃ;T USDPEGU7lbRVMYSc3kqf