Skip to content

Commit

Permalink
Add unit tests for special functions with added CC/RRi support
Browse files Browse the repository at this point in the history
  • Loading branch information
d-torrance committed Aug 5, 2024
1 parent 8f2734b commit f000169
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions M2/Macaulay2/tests/normal/numbers.m2
Original file line number Diff line number Diff line change
Expand Up @@ -858,26 +858,79 @@ assert ( instance(atan (1/(0.*ii)) , CC) )

assert small(1 - inverseErf erf 1)
assert small(1/2 - erf inverseErf(1/2))
assert isMember(erf 1, erf interval 1)
assert isMember(1, inverseErf erf interval 1)
assert (abs(erf ii - 1.65042575879754*ii) < 1e-14)
assert small(erfc 1 - (1 - erf 1))
assert isMember(1 - erf 1, erfc interval 1)
assert small abs (erfc ii - (1 - erf ii))

assert small(Gamma(5, 0) - Gamma 5)
assert small(Gamma(1, 5) - exp(-5))
assert small(Gamma(1/2, 5) - sqrt pi * erfc sqrt 5)
assert isMember(24, Gamma interval 5)
assert isMember(exp(-5), Gamma(1, interval 5))
assert isMember(exp(-5), Gamma(interval 1, 5))
assert isMember(exp(-5), Gamma(interval 1, interval 5))
assert small abs(Gamma ii + 0.15494982830181067 + 0.49801566811835607*ii)
assert small abs(Gamma(1, ii) - 0.54030230586813977 + 0.8414709848078965*ii)
assert small abs(Gamma(ii, 1) - 0.18664859155306995 - 0.087482052563195759*ii)
assert small abs(Gamma(ii, ii) + 0.014824818622885686 + 0.21654902748979538*ii)

assert small(Gamma(1/2, 5) / Gamma(1/2) - regularizedGamma(1/2, 5))
assert(abs(5 - inverseRegularizedGamma(1/2, regularizedGamma(1/2, 5))) < 1e-12)
assert small(1/5 - regularizedGamma(1/2, inverseRegularizedGamma(1/2, 1/5)))
assert isMember(0.13533528323661269, regularizedGamma(1, interval 2))
assert isMember(0.13533528323661269, regularizedGamma(interval 1, 2))
assert isMember(0.13533528323661269, regularizedGamma(interval 1, interval 2))
assert small abs(Gamma(1, ii) - 0.54030230586813977 + 0.8414709848078965*ii)
assert small abs(Gamma(ii, 1) - 0.18664859155306996 - 0.0874820525631958*ii)
assert small abs(Gamma(ii, ii) + 0.01482481862288569 + 0.2165490274897954*ii)

assert small(Digamma 1 + EulerConstant)
assert isMember(-EulerConstant, Digamma interval 1)
assert small(imaginaryPart Digamma ii - (1/2 + pi/2 * coth pi))

assert small(lngamma 0.5 - log sqrt pi)
assert small(lngamma(1/2) - log sqrt pi)
assert small(lngamma 4 - log 6)
assert small(lngamma pi - log Gamma pi)
assert isMember(log sqrt pi, lngamma interval 0.5)
assert small abs(lngamma ii - log Gamma ii)

assert small(zeta(-1) + 1/12)
assert isMember(-1/12, zeta interval(-1))
assert(abs zeta(1/2 + 14.1347251417347*ii) < 1e-14)

assert small(Beta(1, 2) - 1/2)
assert isMember(1/2, Beta(1, interval 2))
assert isMember(1/2, Beta(interval 1, 2))
assert isMember(1/2, Beta(interval 1, interval 2))
assert small abs(Beta(1, 1 + ii) - 1/2 + 1/2*ii)
assert small abs(Beta(1 + ii, 1) - 1/2 + 1/2*ii)
assert small abs(Beta(1 + ii, 1 + ii) + 0.211272372936533 + 0.7655283165378*ii)

assert small(regularizedBeta(1/3, 4, 1) - 1/81)
assert small(regularizedBeta(1/3, 4, 5) -
(regularizedBeta(1/3, 3, 5) - (1/3)^3 * (2/3)^5 / (3 * Beta(3, 5))))
assert small(1/3 - inverseRegularizedBeta(regularizedBeta(1/3, 4, 5), 4, 5))
assert small(1/3 - regularizedBeta(inverseRegularizedBeta(1/3, 4, 5), 4, 5))

assert isMember(1/81, regularizedBeta(1/3, 4, interval 1))
assert isMember(1/81, regularizedBeta(1/3, interval 4, 1))
assert isMember(1/81, regularizedBeta(interval(1/3), 4, 1))
assert isMember(1/81, regularizedBeta(1/3, interval 4, interval 1))
assert isMember(1/81, regularizedBeta(interval(1/3), 4, interval 1))
assert isMember(1/81, regularizedBeta(interval(1/3), interval 4, 1))
assert isMember(1/81, regularizedBeta(1/3, 4, interval 1))
assert small abs(regularizedBeta(ii, 2, 3) + 3 - 8*ii)
assert small abs(regularizedBeta(1/2, 2 + ii, 3) - 0.684520887983316 + 0.202969896572206*ii)
assert small abs(regularizedBeta(1/2, 2, 3 + ii) - 0.719677763554156 - 0.151597967512762*ii)
assert (abs(regularizedBeta(ii, 2 + ii, 3) + 1.87091618715686 - 1.24727745810457*ii) < 1e-14)
assert (abs(regularizedBeta(ii, 2, 3 + ii) + 15.8472757835638 - 7.90719103740708*ii) < 1e-13)
assert small abs(regularizedBeta(1/2, 2 + ii, 3 + ii) - 0.675624489980143 + 0.036930593255322*ii)
assert (abs(regularizedBeta(ii, 2 + ii, 3 + ii) + 3.51460542799295 + 0.957530220804034*ii) < 1e-14)

-- a few values from Abrahamowitz & Stegun Table 9.1
assert ( BesselJ(0, 0) == 1 )
assert ( abs(BesselJ(1, 2) - 0.5767248078) < 1e-10 )
Expand All @@ -886,6 +939,22 @@ assert ( abs(BesselY(0, 1) - 0.0882569642) < 1e-10 )
assert ( abs(BesselY(1, 2) + 0.1070324315) < 1e-10 )
assert ( abs(BesselY(2, 3) + 0.16040039) < 1e-8 )

assert small (BesselJ(1, 2) - BesselJ(1.0, 2.0))
assert isMember(BesselJ(1, 2), BesselJ(1, interval 2))
assert isMember(BesselJ(1, 2), BesselJ(interval 1, 2))
assert isMember(BesselJ(1, 2), BesselJ(interval 1, interval 2))
assert small abs (BesselJ(1, ii) - 0.565159103992485*ii)
assert (abs(BesselJ(ii, 1) - 1.64102417949508 + 0.437075010213683*ii) < 1e-14)
assert small abs(BesselJ(ii, ii) - .395137431337008 + 0.221175556871848*ii)

assert small (BesselY(1, 2) - BesselY(1.0, 2.0))
assert isMember(BesselY(1, 2), BesselY(1, interval 2))
assert isMember(BesselY(1, 2), BesselY(interval 1, 2))
assert isMember(BesselY(1, 2), BesselY(interval 1, interval 2))
assert small abs(BesselY(1, ii) + 0.565159103992484 - 0.383186043874565*ii)
assert (abs(BesselY(ii, 1) + 0.476556612479964 + 1.50506915911039*ii) < 1e-14)
assert small abs(BesselY(ii, ii) + 0.665181892391867 - 0.395137431337008*ii)

assert Equation(truncate 1, 1)
assert Equation(truncate 1.9, 1)
assert Equation(truncate(-1.9), -1)
Expand Down

0 comments on commit f000169

Please sign in to comment.