R Under development (unstable) (2025-11-06 r88990 ucrt) -- "Unsuffered Consequences" Copyright (C) 2025 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 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. > ### == expint: Exponential Integral and Incomplete Gamma Function == > ### > ### Tests for the incomplete gamma function > ### > ### G(a,x) = int_x^infty t^{a-1} exp(-t) dt > ### > ### for a *real* and x >= 0. > ### > ### AUTHOR: Vincent Goulet > > ## Load the package > library(expint) > > ## a > 0; direct link to the standard incomplete gamma function > x <- c(0.2, 2.5, 5, 8, 10) > a <- 1.2 > stopifnot(exprs = { + identical(gammainc(a, x), + gamma(a) * pgamma(x, a, 1, lower = FALSE)) + }) > > ## a = 0; direct link to the exponential integral > x <- c(0.2, 2.5, 5, 8, 10) > a <- 0 > stopifnot(exprs = { + identical(gammainc(a, x), expint(x)) + identical(gammainc(a, x), expint_E1(x)) + }) > > ## a < 0; compare to the recursive formula > x <- c(0.2, 2.5, 5, 8, 10) > a <- c(-0.25, -1.2, -2) > stopifnot(exprs = { + all.equal(gammainc(a[1], x), + -(x^a[1] * exp(-x))/a[1] + + gamma(a[1] + 1) * pgamma(x, a[1] + 1, 1, lower = FALSE)/a[1]) + all.equal(gammainc(a[2], x), + -(x^a[2] * exp(-x))/a[2] + + (-(x^(a[2] + 1) * exp(-x))/(a[2] + 1) + + gamma(a[2] + 2) * pgamma(x, a[2] + 2, 1, lower = FALSE)/(a[2] + 1))/a[2]) + all.equal( + gammainc(a[3], x), + -(x^a[3] * exp(-x))/a[3] + + (-(x^(a[3] + 1) * exp(-x))/(a[3] + 1) + expint_E1(x)/(a[3] + 1))/a[3]) + }) > > proc.time() user system elapsed 0.18 0.07 0.25