tests/testthat/test_aad.R

test_that("test suite aad", {

## Some random tests that check hypergeo::complex_gamma() against
## numerical results from sage 8.3

## File "aac.R" tests hypergeo::complex_gamma() in the same way.


sage_session_cut_and_pasted <- '
[gamma(1/2+n/11.3 + I*(pi-n)/4.4).n() for n in range(0,20)]

[0.512226518621323 - 0.630103381926982*I,
 0.859509460271277 - 0.615305347898946*I,
 1.15462446803178 - 0.376039439041294*I,
[snip]
 -0.0835370217294980 - 0.0635720482222887*I,
 -0.0880057419107945 - 0.0233691652237572*I,
 -0.0784999881240710 + 0.0115997795225445*I]


 [log(gamma(1/2+n/11.3 + I*(pi-n)/4.4)).n() for n in range(0,20)]

[-0.208207713583194 - 0.888224086156769*I,
 0.0554831196463532 - 0.621304146967948*I,
 0.194180946502494 - 0.314847863890735*I,
 0.185492109362300 - 0.0336686663751387*I,
 0.0643018485027639 + 0.160780646204407*I,
[snip]
 -2.39628459606810 - 2.88204114458424*I,
 -2.53385661572792 + 2.99488638638545*I]

'

## Use emacs to massage the sage output into R idiom, results below:

sage_output_gamma_R_format <- c(
0.512226518621323 - 0.630103381926982i,
 0.859509460271277 - 0.615305347898946i,
 1.15462446803178 - 0.376039439041294i,
 1.20312845803250 - 0.0405230438423441i,
 1.05266028681636 + 0.170721012330645i,
 0.863367840782331 + 0.223544182007551i,
 0.706039895635062 + 0.186102654254970i,
 0.584372712450627 + 0.113473566324999i,
 0.485536541939133 + 0.0339474421306985i,
 0.398264831370058 - 0.0391501571138128i,
 0.315979899240595 - 0.0992022846149194i,
 0.236181800279884 - 0.142674536666374i,
 0.159308894737013 - 0.167849388153350i,
 0.0876858706813683 - 0.174525361208074i,
 0.0245907094384454 - 0.164013184549426i,
 -0.0265923754894671 - 0.139116579036847i,
 -0.0631270763153247 - 0.103953973110958i,
 -0.0835370217294980 - 0.0635720482222887i,
 -0.0880057419107945 - 0.0233691652237572i,
 -0.0784999881240710 + 0.0115997795225445i
)

sage_output_lngamma_R_format <- c(
-0.208207713583194 - 0.888224086156769i,
 0.0554831196463532 - 0.621304146967948i,
 0.194180946502494 - 0.314847863890735i,
 0.185492109362300 - 0.0336686663751387i,
 0.0643018485027639 + 0.160780646204407i,
 -0.114470141343285 + 0.253357242420937i,
 -0.314498243419058 + 0.257724610307637i,
 -0.518710077753998 + 0.191793314628122i,
 -0.720062462384213 + 0.0698037824352696i,
 -0.915829661062507 - 0.0979870033718351i,
 -1.10507410951419 - 0.304206457587263i,
 -1.28760477657949 - 0.543419792497458i,
 -1.46354414836788 - 0.811497316653859i,
 -1.63314210577780 - 1.10521075539649i,
 -1.79669323284225 - 1.42197357133574i,
 -1.95449936664915 - 1.75966964441877i,
 -2.10685277131285 - 2.11653687452572i,
 -2.25402902830745 - 2.49108579488877i,
 -2.39628459606810 - 2.88204114458424i,
 -2.53385661572792 + 2.99488638638545i
)


# now perform the actual comparison:
jj <- 0:19 # note off-by-one issue
z <- 0.5 + jj/11.3 + 1i*(pi-jj)/4.4

## First, check hypergeo::lanczos(log=FALSE):
error1 <- sage_output_gamma_R_format - lanczos(z)
expect_true(all(abs(error1)<1e-10))


## Second, check hypergeo::lanczos(log=TRUE):
##  Need to account for sage's different cut lines:
sage_output_lngamma_R_format[20] %<>% "-"(pi*2i)

error2 <- sage_output_lngamma_R_format - lanczos(z,log=TRUE) 
expect_true(all(abs(error2)<1e-13))

} )
RobinHankin/hypergeo documentation built on Aug. 29, 2023, 4 p.m.