2
0
mirror of https://github.com/boostorg/math.git synced 2026-01-28 07:22:12 +00:00
Files
math/test/test_trigamma.cpp
jzmaddock 22bc7212e7 [Polygamma]
Hook up concept checks.
Move test instantiations into instances lib.
Fix a few test failures.
Add Nikhar's trigamma tests.
2014-10-26 09:42:11 +00:00

166 lines
7.5 KiB
C++

///////////////////////////////////////////////////////////////////////////////
// Copyright 2013 Nikhar Agrawal
// Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#define BOOST_TEST_MAIN
#include <boost/test/included/unit_test.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/math/concepts/real_concept.hpp>
#include <boost/math/special_functions/math_fwd.hpp>
#include <libs/math/test/table_type.hpp>
#define SC_(x) static_cast<typename table_type<T>::type>(BOOST_JOIN(x, L))
template <class T>
void test(const char* name)
{
std::cout << "Testing type " << name << ":\n";
static const typename table_type<T>::type data[] =
{
/* First 50 from 1 to 50 inclusive: */
/* [Table[N[polygamma(1,x),40],{x, 1,50,1}] */
SC_(1.644934066848226436472415166646025189219),
SC_(0.6449340668482264364724151666460251892189),
SC_(0.3949340668482264364724151666460251892189),
SC_(0.2838229557371153253613040555349140781078),
SC_(0.2213229557371153253613040555349140781078),
SC_(0.1813229557371153253613040555349140781078),
SC_(0.1535451779593375475835262777571363003301),
SC_(0.1331370146940314251345466859204016064525),
SC_(0.1175120146940314251345466859204016064525),
SC_(0.1051663356816857461222010069080559274402),
SC_(0.09516633568168574612220100690805592744016),
SC_(0.08690187287176839075030018046177493570463),
SC_(0.07995742842732394630585573601733049126018),
SC_(0.07404026866401033683840011471555534333119),
SC_(0.06893822784768380622615521675637166986180),
SC_(0.06449378340323936178171077231192722541736),
SC_(0.06058753340323936178171077231192722541736),
SC_(0.05712732579078261437686648165448777905057),
SC_(0.05404090603769619462378006190140135929749),
SC_(0.05127082293520311983153629458838196871577),
SC_(0.04877082293520311983153629458838196871577),
SC_(0.04650324923905799511498300660652255828493),
SC_(0.04443713353657865627200779999495231035105),
SC_(0.04254677436833669029847282835033983398054),
SC_(0.04081066325722557918736171723922872286943),
SC_(0.03921066325722557918736171723922872286943),
SC_(0.03773137331639717682049781191378493588718),
SC_(0.03635963120391432359690384757907986044136),
SC_(0.03508412099983269094384262308928394207401),
SC_(0.03389506035773994421375938884433744980291),
SC_(0.03278394924662883310264827773322633869180),
SC_(0.03174336652030209012658168043874142714133),
SC_(0.03076680402030209012658168043874142714133),
SC_(0.02984853037475571730748158861137687250405),
SC_(0.02898347847164153045627051594701701091235),
SC_(0.02816715194102928555831133227354762315725),
SC_(0.02739554700275768062003972733527601821898),
SC_(0.02666508681283803124093088876697799046149),
SC_(0.02597256603721476254286994693872314281606),
SC_(0.02531510384129102815759710012741479304617),
SC_(0.02469010384129102815759710012741479304617),
SC_(0.02409521984367056414807895616548736889388),
SC_(0.02352832641963428296894063417002251628617),
SC_(0.02298749353699501850166102356969801655659),
SC_(0.02247096461137518379091722191680545457312),
SC_(0.02197713745088135663042339475631162741262),
SC_(0.02150454765882086513703965184515850832000),
SC_(0.02105185413233829383780923084017887952869),
SC_(0.02061782635456051606003145306240110175091),
SC_(0.02020133322669712580597064506573304677382),
/* From 500 to 1000 inclusive: */
/* N[Table[polygamma(1,x),{x,500,1000,10}],40] */
SC_(0.002002001333332266669714268647774197060731),
SC_(0.001962707907716779452707536987802627805478),
SC_(0.001924927220830560087836886751110357728817),
SC_(0.001888573565201797462176247714903982850228),
SC_(0.001853567587934717491642342315537909130701),
SC_(0.001819835712496207207148883544824689071325),
SC_(0.001787309622509112919049294530378524341727),
SC_(0.001755925799930688909525507873736210387807),
SC_(0.001725625111046822227695996850789819829573),
SC_(0.001696352434604175251311909533625714712743),
SC_(0.001668056327160065158600874171864846275643),
SC_(0.001640688721375697019508021597082845963148),
SC_(0.001614204653530344531908147526628406223744),
SC_(0.001588562017007133389350166010439711886334),
SC_(0.001563721338907567163849825550712474891492),
SC_(0.001539645577302094752249567207416345365696),
SC_(0.001516299936926392520203240617160426547639),
SC_(0.001493651701394760695953585236460286481018),
SC_(0.001471670080229094300578280356096446686477),
SC_(0.001450326069199311597153133670448160203387),
SC_(0.001429592322643144721734539533648659286144),
SC_(0.001409443036583397946176993267702984100733),
SC_(0.001389853841592191696522797555468410819444),
SC_(0.001370801704466910484446604323882526177420),
SC_(0.001352264837883752677688324896962748941904),
SC_(0.001334222617283810151070001951163903617504),
SC_(0.001316655504325086010791929491458814498671),
SC_(0.001299544976303159784503980965599319524818),
SC_(0.001282873461004509259711608908038169904080),
SC_(0.001266624276510810009925604298617591070236),
SC_(0.001250781575520731608186449075029891794096),
SC_(0.001235330293798588858327739384385581649440),
SC_(0.001220256102397340964751055441376021959125),
SC_(0.001205545363337428588618639743321944385431),
SC_(0.001191185088453291061973294466848346283972),
SC_(0.001177162901146542691814823893259588004310),
SC_(0.001163467000809082214935959719602656350021),
SC_(0.001150086129701189861587852965952522886083),
SC_(0.001137009542089218078848777802653932997102),
SC_(0.001124226975465055320838136039288794501131),
SC_(0.001111728623685357358627683939948964547062),
SC_(0.001099505111882790624790340268963560561212),
SC_(0.001087547473014387385213628807079818129189),
SC_(0.001075847125923723081414745258211721267207),
SC_(0.001064395854804124498228502056895669702911),
SC_(0.001053185789959620623711365384007169340153),
SC_(0.001042209389768959890535954112125269154314),
SC_(0.001031459423765829864168427986966001957702),
SC_(0.001020928956755509990450221440026807721340),
SC_(0.001010611333894637278361033654755961804543),
SC_(0.001000500166666633333357142823809599566846)
};
static const unsigned index[] =
{
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50,
500, 510, 520, 530, 540, 550, 560, 570, 580, 590, 600, 610, 620, 630, 640, 650, 660, 670, 680, 690, 700, 710, 720, 730, 740, 750, 760, 770, 780, 790, 800, 810, 820, 830, 840, 850, 860, 870, 880, 890, 900, 910, 920, 930, 940, 950, 960, 970, 980, 990, 1000
};
static const unsigned table_size = sizeof(index) / sizeof(index[0]);
T tol = boost::math::tools::epsilon<T>() * 10;
for(unsigned i = 1; i < table_size; ++i)
{
T x(index[i]);
T tg = boost::math::trigamma(x);
BOOST_CHECK_CLOSE_FRACTION(tg, static_cast<T>(data[i]), tol);
}
}
BOOST_AUTO_TEST_CASE(test_main)
{
test<float>("float");
test<double>("double");
#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
test<long double>("long double");
test<boost::math::concepts::real_concept>("real_concept");
#endif
}