diff --git a/Code/FeatureExtraction/otbLineSegmentDetector.h b/Code/FeatureExtraction/otbLineSegmentDetector.h index 61579858468efd85fbbee651e2c5e98f32efecfa..348c9d4ba754e95fc2df94304820dd2670e327a7 100644 --- a/Code/FeatureExtraction/otbLineSegmentDetector.h +++ b/Code/FeatureExtraction/otbLineSegmentDetector.h @@ -216,12 +216,6 @@ protected: /** Create a copy of a rectangle*/ virtual void CopyRectangle(RectangleType& rDst, RectangleType& rSrc) const; - /** Rutines from numerical recipes*/ - virtual double betacf(double a, double b, double x) const; - virtual double gammln(double xx) const; - virtual double betai(double a, double b, double x) const; - virtual double factln(int n) const; - /** Printself method*/ void PrintSelf(std::ostream& os, itk::Indent indent) const; diff --git a/Code/FeatureExtraction/otbLineSegmentDetector.txx b/Code/FeatureExtraction/otbLineSegmentDetector.txx index a2a0bbccaca83b8cae4502338ceb664e89101794..3f1057331dfefc8d44ce1b9d22982a463175978d 100644 --- a/Code/FeatureExtraction/otbLineSegmentDetector.txx +++ b/Code/FeatureExtraction/otbLineSegmentDetector.txx @@ -18,6 +18,8 @@ #ifndef __otbLineSegmentDetector_txx #define __otbLineSegmentDetector_txx +#include <boost/math/special_functions/beta.hpp> + #include "otbLineSegmentDetector.h" #include "itkImageRegionIterator.h" #include "itkNumericTraits.h" @@ -885,14 +887,17 @@ LineSegmentDetector<TInputImage, TPrecision> ::NFA(int n, int k, double p, double logNT) const { double val; + double n_d = static_cast<double>(n); + double k_d = static_cast<double>(k); - if (k == 0) return -logNT; + if (k == 0) + return -logNT; - val = -logNT - log10(betai((double) k, (double) (n - k + 1), p)); + val = -logNT - log10( boost::math::ibeta(k_d, n_d - k_d + 1, p) ); if (vnl_math_isinf(val)) /* approximate by the first term of the tail */ - val = -logNT - (factln(n) - factln(k) - factln(n - k)) / CONST_LN10 - - (double) k * log10(p) - (double) (n - k) * log10(1.0 - p); + val = -logNT - (boost::math::lgamma(n_d + 1.0) - boost::math::lgamma(k_d + 1) - boost::math::lgamma(n_d - k_d + 1)) / CONST_LN10 + - k_d * log10(p) - (n_d - k_d) * log10(1.0 - p); return val; } @@ -909,105 +914,6 @@ LineSegmentDetector<TInputImage, TPrecision> } -/**************************************************************************************************************/ -/**************************************************************************************************************/ -/* - rutines betacf, gammln, betai, and factln - Taken from http://sd-www.jhupal.edu/IMP/data/spec_req/NR/Code -*/ -/**************************************************************************************************************/ -/**************************************************************************************************************/ -template <class TInputImage, class TPrecision> -double -LineSegmentDetector<TInputImage, TPrecision> -::betacf(double a, double b, double x) const -{ - int m, m2; - double aa, c, d, del, h, qab, qam, qap; - - qab = a + b; - qap = a + 1.0; - qam = a - 1.0; - c = 1.0; - d = 1.0 - qab * x / qap; - if (fabs(d) < FPMIN) d = FPMIN; - d = 1.0 / d; - h = d; - for (m = 1; m <= MAXIT; m++) - { - m2 = 2 * m; - aa = m * (b - m) * x / ((qam + m2) * (a + m2)); - d = 1.0 + aa * d; - if (fabs(d) < FPMIN) d = FPMIN; - c = 1.0 + aa / c; - if (fabs(c) < FPMIN) c = FPMIN; - d = 1.0 / d; - h *= d * c; - aa = -(a + m) * (qab + m) * x / ((a + m2) * (qap + m2)); - d = 1.0 + aa * d; - if (fabs(d) < FPMIN) d = FPMIN; - c = 1.0 + aa / c; - if (fabs(c) < FPMIN) c = FPMIN; - d = 1.0 / d; - del = d * c; - h *= del; - if (fabs(del - 1.0) < EPS) break; - } - - return h; -} - -template <class TInputImage, class TPrecision> -double -LineSegmentDetector<TInputImage, TPrecision> -::gammln(double xx) const -{ - double x, y, tmp, ser; - static double cof[6] = {76.18009172947146, -86.50532032941677, - 24.01409824083091, -1.231739572450155, - 0.1208650973866179e-2, -0.5395239384953e-5}; - int j; - - y = x = xx; - tmp = x + 5.5; - tmp -= (x + 0.5) * log(tmp); - ser = 1.000000000190015; - for (j = 0; j <= 5; ++j) - ser += cof[j] / ++y; - return -tmp + log(2.5066282746310005 * ser / x); -} - -template <class TInputImage, class TPrecision> -double -LineSegmentDetector<TInputImage, TPrecision> -::betai(double a, double b, double x) const -{ - double betacf(double a, double b, double x); - double gammln(double xx); - double bt; - - if (x == 0.0 || x == 1.0) bt = 0.0; - else bt = exp(this->gammln(a + b) - this->gammln(a) - this->gammln(b) + a * log(x) + b * log(1.0 - x)); - if (x < (a + 1.0) / (a + b + 2.0)) return bt * this->betacf(a, b, x) / a; - else return 1.0 - bt*this->betacf(b, a, 1.0 - x) / b; -} - -template <class TInputImage, class TPrecision> -double -LineSegmentDetector<TInputImage, TPrecision> -::factln(int n) const -{ - double gammln(double xx); - static double a[101]; - - if (n <= 1) return 0.0; - if (n <= 100) return a[n] ? a[n] : (a[n] = this->gammln(n + 1.0)); - else return this->gammln(n + 1.0); -} - -/********************* end Numerical Recipes functions **************************************************************************/ -/**************************************************************************************************************/ - } // end namespace otb #endif diff --git a/Utilities/BGL/boost/math/bindings/detail/big_digamma.hpp b/Utilities/BGL/boost/math/bindings/detail/big_digamma.hpp new file mode 100644 index 0000000000000000000000000000000000000000..0de1d94d083e3ea3fcac84d12d5be8aa6e58100d --- /dev/null +++ b/Utilities/BGL/boost/math/bindings/detail/big_digamma.hpp @@ -0,0 +1,294 @@ +// (C) Copyright John Maddock 2006-8. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_NTL_DIGAMMA +#define BOOST_MATH_NTL_DIGAMMA + +#include <boost/math/tools/rational.hpp> +#include <boost/math/policies/error_handling.hpp> +#include <boost/math/constants/constants.hpp> + +namespace boost{ namespace math{ namespace detail{ + +template <class T> +T big_digamma_helper(T x) +{ + static const T P[61] = { + boost::lexical_cast<T>("0.6660133691143982067148122682345055274952e81"), + boost::lexical_cast<T>("0.6365271516829242456324234577164675383137e81"), + boost::lexical_cast<T>("0.2991038873096202943405966144203628966976e81"), + boost::lexical_cast<T>("0.9211116495503170498076013367421231351115e80"), + boost::lexical_cast<T>("0.2090792764676090716286400360584443891749e80"), + boost::lexical_cast<T>("0.3730037777359591428226035156377978092809e79"), + boost::lexical_cast<T>("0.5446396536956682043376492370432031543834e78"), + boost::lexical_cast<T>("0.6692523966335177847425047827449069256345e77"), + boost::lexical_cast<T>("0.7062543624100864681625612653756619116848e76"), + boost::lexical_cast<T>("0.6499914905966283735005256964443226879158e75"), + boost::lexical_cast<T>("0.5280364564853225211197557708655426736091e74"), + boost::lexical_cast<T>("0.3823205608981176913075543599005095206953e73"), + boost::lexical_cast<T>("0.2486733714214237704739129972671154532415e72"), + boost::lexical_cast<T>("0.1462562139602039577983434547171318011675e71"), + boost::lexical_cast<T>("0.7821169065036815012381267259559910324285e69"), + boost::lexical_cast<T>("0.3820552182348155468636157988764435365078e68"), + boost::lexical_cast<T>("0.1711618296983598244658239925535632505062e67"), + boost::lexical_cast<T>("0.7056661618357643731419080738521475204245e65"), + boost::lexical_cast<T>("0.2685246896473614017356264531791459936036e64"), + boost::lexical_cast<T>("0.9455168125599643085283071944864977592391e62"), + boost::lexical_cast<T>("0.3087541626972538362237309145177486236219e61"), + boost::lexical_cast<T>("0.9367928873352980208052601301625005737407e59"), + boost::lexical_cast<T>("0.2645306130689794942883818547314327466007e58"), + boost::lexical_cast<T>("0.6961815141171454309161007351079576190079e56"), + boost::lexical_cast<T>("0.1709637824471794552313802669803885946843e55"), + boost::lexical_cast<T>("0.3921553258481531526663112728778759311158e53"), + boost::lexical_cast<T>("0.8409006354449988687714450897575728228696e51"), + boost::lexical_cast<T>("0.1686755204461325935742097669030363344927e50"), + boost::lexical_cast<T>("0.3166653542877070999007425197729038754254e48"), + boost::lexical_cast<T>("0.5566029092358215049069560272835654229637e46"), + boost::lexical_cast<T>("0.9161766287916328133080586672953875116242e44"), + boost::lexical_cast<T>("1412317772330871298317974693514430627922000"), + boost::lexical_cast<T>("20387991986727877473732570146112459874790"), + boost::lexical_cast<T>("275557928713904105182512535678580359839.3"), + boost::lexical_cast<T>("3485719851040516559072031256589598330.723"), + boost::lexical_cast<T>("41247046743564028399938106707656877.40859"), + boost::lexical_cast<T>("456274078125709314602601667471879.0147312"), + boost::lexical_cast<T>("4714450683242899367025707077155.310613012"), + boost::lexical_cast<T>("45453933537925041680009544258.75073849996"), + boost::lexical_cast<T>("408437900487067278846361972.302331241052"), + boost::lexical_cast<T>("3415719344386166273085838.705771571751035"), + boost::lexical_cast<T>("26541502879185876562320.93134691487351145"), + boost::lexical_cast<T>("191261415065918713661.1571433274648417668"), + boost::lexical_cast<T>("1275349770108718421.645275944284937551702"), + boost::lexical_cast<T>("7849171120971773.318910987434906905704272"), + boost::lexical_cast<T>("44455946386549.80866460312682983576538056"), + boost::lexical_cast<T>("230920362395.3198137186361608905136598046"), + boost::lexical_cast<T>("1095700096.240863858624279930600654130254"), + boost::lexical_cast<T>("4727085.467506050153744334085516289728134"), + boost::lexical_cast<T>("18440.75118859447173303252421991479005424"), + boost::lexical_cast<T>("64.62515887799460295677071749181651317052"), + boost::lexical_cast<T>("0.201851568864688406206528472883512147547"), + boost::lexical_cast<T>("0.0005565091674187978029138500039504078098143"), + boost::lexical_cast<T>("0.1338097668312907986354698683493366559613e-5"), + boost::lexical_cast<T>("0.276308225077464312820179030238305271638e-8"), + boost::lexical_cast<T>("0.4801582970473168520375942100071070575043e-11"), + boost::lexical_cast<T>("0.6829184144212920949740376186058541800175e-14"), + boost::lexical_cast<T>("0.7634080076358511276617829524639455399182e-17"), + boost::lexical_cast<T>("0.6290035083727140966418512608156646142409e-20"), + boost::lexical_cast<T>("0.339652245667538733044036638506893821352e-23"), + boost::lexical_cast<T>("0.9017518064256388530773585529891677854909e-27") + }; + static const T Q[61] = { + boost::lexical_cast<T>("0"), + boost::lexical_cast<T>("0.1386831185456898357379390197203894063459e81"), + boost::lexical_cast<T>("0.6467076379487574703291056110838151259438e81"), + boost::lexical_cast<T>("0.1394967823848615838336194279565285465161e82"), + boost::lexical_cast<T>("0.1872927317344192945218570366455046340458e82"), + boost::lexical_cast<T>("0.1772461045338946243584650759986310355937e82"), + boost::lexical_cast<T>("0.1267294892200258648315971144069595555118e82"), + boost::lexical_cast<T>("0.7157764838362416821508872117623058626589e81"), + boost::lexical_cast<T>("0.329447266909948668265277828268378274513e81"), + boost::lexical_cast<T>("0.1264376077317689779509250183194342571207e81"), + boost::lexical_cast<T>("0.4118230304191980787640446056583623228873e80"), + boost::lexical_cast<T>("0.1154393529762694616405952270558316515261e80"), + boost::lexical_cast<T>("0.281655612889423906125295485693696744275e79"), + boost::lexical_cast<T>("0.6037483524928743102724159846414025482077e78"), + boost::lexical_cast<T>("0.1145927995397835468123576831800276999614e78"), + boost::lexical_cast<T>("0.1938624296151985600348534009382865995154e77"), + boost::lexical_cast<T>("0.293980925856227626211879961219188406675e76"), + boost::lexical_cast<T>("0.4015574518216966910319562902099567437832e75"), + boost::lexical_cast<T>("0.4961475457509727343545565970423431880907e74"), + boost::lexical_cast<T>("0.5565482348278933960215521991000378896338e73"), + boost::lexical_cast<T>("0.5686112924615820754631098622770303094938e72"), + boost::lexical_cast<T>("0.5305988545844796293285410303747469932856e71"), + boost::lexical_cast<T>("0.4533363413802585060568537458067343491358e70"), + boost::lexical_cast<T>("0.3553932059473516064068322757331575565718e69"), + boost::lexical_cast<T>("0.2561198565218704414618802902533972354203e68"), + boost::lexical_cast<T>("0.1699519313292900324098102065697454295572e67"), + boost::lexical_cast<T>("0.1039830160862334505389615281373574959236e66"), + boost::lexical_cast<T>("0.5873082967977428281000961954715372504986e64"), + boost::lexical_cast<T>("0.3065255179030575882202133042549783442446e63"), + boost::lexical_cast<T>("0.1479494813481364701208655943688307245459e62"), + boost::lexical_cast<T>("0.6608150467921598615495180659808895663164e60"), + boost::lexical_cast<T>("0.2732535313770902021791888953487787496976e59"), + boost::lexical_cast<T>("0.1046402297662493314531194338414508049069e58"), + boost::lexical_cast<T>("0.3711375077192882936085049147920021549622e56"), + boost::lexical_cast<T>("0.1219154482883895482637944309702972234576e55"), + boost::lexical_cast<T>("0.3708359374149458741391374452286837880162e53"), + boost::lexical_cast<T>("0.1044095509971707189716913168889769471468e52"), + boost::lexical_cast<T>("0.271951506225063286130946773813524945052e50"), + boost::lexical_cast<T>("0.6548016291215163843464133978454065823866e48"), + boost::lexical_cast<T>("0.1456062447610542135403751730809295219344e47"), + boost::lexical_cast<T>("0.2986690175077969760978388356833006028929e45"), + boost::lexical_cast<T>("5643149706574013350061247429006443326844000"), + boost::lexical_cast<T>("98047545414467090421964387960743688053480"), + boost::lexical_cast<T>("1563378767746846395507385099301468978550"), + boost::lexical_cast<T>("22823360528584500077862274918382796495"), + boost::lexical_cast<T>("304215527004115213046601295970388750"), + boost::lexical_cast<T>("3690289075895685793844344966820325"), + boost::lexical_cast<T>("40584512015702371433911456606050"), + boost::lexical_cast<T>("402834190897282802772754873905"), + boost::lexical_cast<T>("3589522158493606918146495750"), + boost::lexical_cast<T>("28530557707503483723634725"), + boost::lexical_cast<T>("200714561335055753000730"), + boost::lexical_cast<T>("1237953783437761888641"), + boost::lexical_cast<T>("6614698701445762950"), + boost::lexical_cast<T>("30155495647727505"), + boost::lexical_cast<T>("114953256021450"), + boost::lexical_cast<T>("356398020013"), + boost::lexical_cast<T>("863113950"), + boost::lexical_cast<T>("1531345"), + boost::lexical_cast<T>("1770"), + boost::lexical_cast<T>("1") + }; + static const T PD[60] = { + boost::lexical_cast<T>("0.6365271516829242456324234577164675383137e81"), + 2*boost::lexical_cast<T>("0.2991038873096202943405966144203628966976e81"), + 3*boost::lexical_cast<T>("0.9211116495503170498076013367421231351115e80"), + 4*boost::lexical_cast<T>("0.2090792764676090716286400360584443891749e80"), + 5*boost::lexical_cast<T>("0.3730037777359591428226035156377978092809e79"), + 6*boost::lexical_cast<T>("0.5446396536956682043376492370432031543834e78"), + 7*boost::lexical_cast<T>("0.6692523966335177847425047827449069256345e77"), + 8*boost::lexical_cast<T>("0.7062543624100864681625612653756619116848e76"), + 9*boost::lexical_cast<T>("0.6499914905966283735005256964443226879158e75"), + 10*boost::lexical_cast<T>("0.5280364564853225211197557708655426736091e74"), + 11*boost::lexical_cast<T>("0.3823205608981176913075543599005095206953e73"), + 12*boost::lexical_cast<T>("0.2486733714214237704739129972671154532415e72"), + 13*boost::lexical_cast<T>("0.1462562139602039577983434547171318011675e71"), + 14*boost::lexical_cast<T>("0.7821169065036815012381267259559910324285e69"), + 15*boost::lexical_cast<T>("0.3820552182348155468636157988764435365078e68"), + 16*boost::lexical_cast<T>("0.1711618296983598244658239925535632505062e67"), + 17*boost::lexical_cast<T>("0.7056661618357643731419080738521475204245e65"), + 18*boost::lexical_cast<T>("0.2685246896473614017356264531791459936036e64"), + 19*boost::lexical_cast<T>("0.9455168125599643085283071944864977592391e62"), + 20*boost::lexical_cast<T>("0.3087541626972538362237309145177486236219e61"), + 21*boost::lexical_cast<T>("0.9367928873352980208052601301625005737407e59"), + 22*boost::lexical_cast<T>("0.2645306130689794942883818547314327466007e58"), + 23*boost::lexical_cast<T>("0.6961815141171454309161007351079576190079e56"), + 24*boost::lexical_cast<T>("0.1709637824471794552313802669803885946843e55"), + 25*boost::lexical_cast<T>("0.3921553258481531526663112728778759311158e53"), + 26*boost::lexical_cast<T>("0.8409006354449988687714450897575728228696e51"), + 27*boost::lexical_cast<T>("0.1686755204461325935742097669030363344927e50"), + 28*boost::lexical_cast<T>("0.3166653542877070999007425197729038754254e48"), + 29*boost::lexical_cast<T>("0.5566029092358215049069560272835654229637e46"), + 30*boost::lexical_cast<T>("0.9161766287916328133080586672953875116242e44"), + 31*boost::lexical_cast<T>("1412317772330871298317974693514430627922000"), + 32*boost::lexical_cast<T>("20387991986727877473732570146112459874790"), + 33*boost::lexical_cast<T>("275557928713904105182512535678580359839.3"), + 34*boost::lexical_cast<T>("3485719851040516559072031256589598330.723"), + 35*boost::lexical_cast<T>("41247046743564028399938106707656877.40859"), + 36*boost::lexical_cast<T>("456274078125709314602601667471879.0147312"), + 37*boost::lexical_cast<T>("4714450683242899367025707077155.310613012"), + 38*boost::lexical_cast<T>("45453933537925041680009544258.75073849996"), + 39*boost::lexical_cast<T>("408437900487067278846361972.302331241052"), + 40*boost::lexical_cast<T>("3415719344386166273085838.705771571751035"), + 41*boost::lexical_cast<T>("26541502879185876562320.93134691487351145"), + 42*boost::lexical_cast<T>("191261415065918713661.1571433274648417668"), + 43*boost::lexical_cast<T>("1275349770108718421.645275944284937551702"), + 44*boost::lexical_cast<T>("7849171120971773.318910987434906905704272"), + 45*boost::lexical_cast<T>("44455946386549.80866460312682983576538056"), + 46*boost::lexical_cast<T>("230920362395.3198137186361608905136598046"), + 47*boost::lexical_cast<T>("1095700096.240863858624279930600654130254"), + 48*boost::lexical_cast<T>("4727085.467506050153744334085516289728134"), + 49*boost::lexical_cast<T>("18440.75118859447173303252421991479005424"), + 50*boost::lexical_cast<T>("64.62515887799460295677071749181651317052"), + 51*boost::lexical_cast<T>("0.201851568864688406206528472883512147547"), + 52*boost::lexical_cast<T>("0.0005565091674187978029138500039504078098143"), + 53*boost::lexical_cast<T>("0.1338097668312907986354698683493366559613e-5"), + 54*boost::lexical_cast<T>("0.276308225077464312820179030238305271638e-8"), + 55*boost::lexical_cast<T>("0.4801582970473168520375942100071070575043e-11"), + 56*boost::lexical_cast<T>("0.6829184144212920949740376186058541800175e-14"), + 57*boost::lexical_cast<T>("0.7634080076358511276617829524639455399182e-17"), + 58*boost::lexical_cast<T>("0.6290035083727140966418512608156646142409e-20"), + 59*boost::lexical_cast<T>("0.339652245667538733044036638506893821352e-23"), + 60*boost::lexical_cast<T>("0.9017518064256388530773585529891677854909e-27") + }; + static const T QD[60] = { + boost::lexical_cast<T>("0.1386831185456898357379390197203894063459e81"), + 2*boost::lexical_cast<T>("0.6467076379487574703291056110838151259438e81"), + 3*boost::lexical_cast<T>("0.1394967823848615838336194279565285465161e82"), + 4*boost::lexical_cast<T>("0.1872927317344192945218570366455046340458e82"), + 5*boost::lexical_cast<T>("0.1772461045338946243584650759986310355937e82"), + 6*boost::lexical_cast<T>("0.1267294892200258648315971144069595555118e82"), + 7*boost::lexical_cast<T>("0.7157764838362416821508872117623058626589e81"), + 8*boost::lexical_cast<T>("0.329447266909948668265277828268378274513e81"), + 9*boost::lexical_cast<T>("0.1264376077317689779509250183194342571207e81"), + 10*boost::lexical_cast<T>("0.4118230304191980787640446056583623228873e80"), + 11*boost::lexical_cast<T>("0.1154393529762694616405952270558316515261e80"), + 12*boost::lexical_cast<T>("0.281655612889423906125295485693696744275e79"), + 13*boost::lexical_cast<T>("0.6037483524928743102724159846414025482077e78"), + 14*boost::lexical_cast<T>("0.1145927995397835468123576831800276999614e78"), + 15*boost::lexical_cast<T>("0.1938624296151985600348534009382865995154e77"), + 16*boost::lexical_cast<T>("0.293980925856227626211879961219188406675e76"), + 17*boost::lexical_cast<T>("0.4015574518216966910319562902099567437832e75"), + 18*boost::lexical_cast<T>("0.4961475457509727343545565970423431880907e74"), + 19*boost::lexical_cast<T>("0.5565482348278933960215521991000378896338e73"), + 20*boost::lexical_cast<T>("0.5686112924615820754631098622770303094938e72"), + 21*boost::lexical_cast<T>("0.5305988545844796293285410303747469932856e71"), + 22*boost::lexical_cast<T>("0.4533363413802585060568537458067343491358e70"), + 23*boost::lexical_cast<T>("0.3553932059473516064068322757331575565718e69"), + 24*boost::lexical_cast<T>("0.2561198565218704414618802902533972354203e68"), + 25*boost::lexical_cast<T>("0.1699519313292900324098102065697454295572e67"), + 26*boost::lexical_cast<T>("0.1039830160862334505389615281373574959236e66"), + 27*boost::lexical_cast<T>("0.5873082967977428281000961954715372504986e64"), + 28*boost::lexical_cast<T>("0.3065255179030575882202133042549783442446e63"), + 29*boost::lexical_cast<T>("0.1479494813481364701208655943688307245459e62"), + 30*boost::lexical_cast<T>("0.6608150467921598615495180659808895663164e60"), + 31*boost::lexical_cast<T>("0.2732535313770902021791888953487787496976e59"), + 32*boost::lexical_cast<T>("0.1046402297662493314531194338414508049069e58"), + 33*boost::lexical_cast<T>("0.3711375077192882936085049147920021549622e56"), + 34*boost::lexical_cast<T>("0.1219154482883895482637944309702972234576e55"), + 35*boost::lexical_cast<T>("0.3708359374149458741391374452286837880162e53"), + 36*boost::lexical_cast<T>("0.1044095509971707189716913168889769471468e52"), + 37*boost::lexical_cast<T>("0.271951506225063286130946773813524945052e50"), + 38*boost::lexical_cast<T>("0.6548016291215163843464133978454065823866e48"), + 39*boost::lexical_cast<T>("0.1456062447610542135403751730809295219344e47"), + 40*boost::lexical_cast<T>("0.2986690175077969760978388356833006028929e45"), + 41*boost::lexical_cast<T>("5643149706574013350061247429006443326844000"), + 42*boost::lexical_cast<T>("98047545414467090421964387960743688053480"), + 43*boost::lexical_cast<T>("1563378767746846395507385099301468978550"), + 44*boost::lexical_cast<T>("22823360528584500077862274918382796495"), + 45*boost::lexical_cast<T>("304215527004115213046601295970388750"), + 46*boost::lexical_cast<T>("3690289075895685793844344966820325"), + 47*boost::lexical_cast<T>("40584512015702371433911456606050"), + 48*boost::lexical_cast<T>("402834190897282802772754873905"), + 49*boost::lexical_cast<T>("3589522158493606918146495750"), + 50*boost::lexical_cast<T>("28530557707503483723634725"), + 51*boost::lexical_cast<T>("200714561335055753000730"), + 52*boost::lexical_cast<T>("1237953783437761888641"), + 53*boost::lexical_cast<T>("6614698701445762950"), + 54*boost::lexical_cast<T>("30155495647727505"), + 55*boost::lexical_cast<T>("114953256021450"), + 56*boost::lexical_cast<T>("356398020013"), + 57*boost::lexical_cast<T>("863113950"), + 58*boost::lexical_cast<T>("1531345"), + 59*boost::lexical_cast<T>("1770"), + 60*boost::lexical_cast<T>("1") + }; + static const double g = 63.192152; + + T zgh = x + g - 0.5; + + T result = (x - 0.5) / zgh; + result += log(zgh); + result += tools::evaluate_polynomial(PD, x) / tools::evaluate_polynomial(P, x); + result -= tools::evaluate_polynomial(QD, x) / tools::evaluate_polynomial(Q, x); + result -= 1; + + return result; +} + +template <class T> +T big_digamma(T x) +{ + BOOST_MATH_STD_USING + if(x < 0) + { + return big_digamma_helper(static_cast<T>(1-x)) + constants::pi<T>() / tan(constants::pi<T>() * (1-x)); + } + return big_digamma_helper(x); +} + +}}} + +#endif // include guard diff --git a/Utilities/BGL/boost/math/bindings/detail/big_lanczos.hpp b/Utilities/BGL/boost/math/bindings/detail/big_lanczos.hpp new file mode 100644 index 0000000000000000000000000000000000000000..f51687dcb3a058da2adbb83b6473f531810ddfd3 --- /dev/null +++ b/Utilities/BGL/boost/math/bindings/detail/big_lanczos.hpp @@ -0,0 +1,887 @@ +// (C) Copyright John Maddock 2006-8. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_BIG_LANCZOS_HPP +#define BOOST_BIG_LANCZOS_HPP + +#include <boost/math/special_functions/lanczos.hpp> +#include <boost/lexical_cast.hpp> + +namespace boost{ namespace math{ namespace lanczos{ + +struct lanczos13UDT +{ + template <class T> + static T lanczos_sum(const T& z) + { + static const T num[13] = { + boost::lexical_cast<T>("44012138428004.60895436261759919070125699"), + boost::lexical_cast<T>("41590453358593.20051581730723108131357995"), + boost::lexical_cast<T>("18013842787117.99677796276038389462742949"), + boost::lexical_cast<T>("4728736263475.388896889723995205703970787"), + boost::lexical_cast<T>("837910083628.4046470415724300225777912264"), + boost::lexical_cast<T>("105583707273.4299344907359855510105321192"), + boost::lexical_cast<T>("9701363618.494999493386608345339104922694"), + boost::lexical_cast<T>("654914397.5482052641016767125048538245644"), + boost::lexical_cast<T>("32238322.94213356530668889463945849409184"), + boost::lexical_cast<T>("1128514.219497091438040721811544858643121"), + boost::lexical_cast<T>("26665.79378459858944762533958798805525125"), + boost::lexical_cast<T>("381.8801248632926870394389468349331394196"), + boost::lexical_cast<T>("2.506628274631000502415763426076722427007"), + }; + static const boost::uint32_t denom[13] = { + static_cast<boost::uint32_t>(0u), + static_cast<boost::uint32_t>(39916800u), + static_cast<boost::uint32_t>(120543840u), + static_cast<boost::uint32_t>(150917976u), + static_cast<boost::uint32_t>(105258076u), + static_cast<boost::uint32_t>(45995730u), + static_cast<boost::uint32_t>(13339535u), + static_cast<boost::uint32_t>(2637558u), + static_cast<boost::uint32_t>(357423u), + static_cast<boost::uint32_t>(32670u), + static_cast<boost::uint32_t>(1925u), + static_cast<boost::uint32_t>(66u), + static_cast<boost::uint32_t>(1u), + }; + return boost::math::tools::evaluate_rational(num, denom, z, 13); + } + + template <class T> + static T lanczos_sum_expG_scaled(const T& z) + { + static const T num[13] = { + boost::lexical_cast<T>("86091529.53418537217994842267760536134841"), + boost::lexical_cast<T>("81354505.17858011242874285785316135398567"), + boost::lexical_cast<T>("35236626.38815461910817650960734605416521"), + boost::lexical_cast<T>("9249814.988024471294683815872977672237195"), + boost::lexical_cast<T>("1639024.216687146960253839656643518985826"), + boost::lexical_cast<T>("206530.8157641225032631778026076868855623"), + boost::lexical_cast<T>("18976.70193530288915698282139308582105936"), + boost::lexical_cast<T>("1281.068909912559479885759622791374106059"), + boost::lexical_cast<T>("63.06093343420234536146194868906771599354"), + boost::lexical_cast<T>("2.207470909792527638222674678171050209691"), + boost::lexical_cast<T>("0.05216058694613505427476207805814960742102"), + boost::lexical_cast<T>("0.0007469903808915448316510079585999893674101"), + boost::lexical_cast<T>("0.4903180573459871862552197089738373164184e-5"), + }; + static const boost::uint32_t denom[13] = { + static_cast<boost::uint32_t>(0u), + static_cast<boost::uint32_t>(39916800u), + static_cast<boost::uint32_t>(120543840u), + static_cast<boost::uint32_t>(150917976u), + static_cast<boost::uint32_t>(105258076u), + static_cast<boost::uint32_t>(45995730u), + static_cast<boost::uint32_t>(13339535u), + static_cast<boost::uint32_t>(2637558u), + static_cast<boost::uint32_t>(357423u), + static_cast<boost::uint32_t>(32670u), + static_cast<boost::uint32_t>(1925u), + static_cast<boost::uint32_t>(66u), + static_cast<boost::uint32_t>(1u), + }; + return boost::math::tools::evaluate_rational(num, denom, z, 13); + } + + + template<class T> + static T lanczos_sum_near_1(const T& dz) + { + static const T d[12] = { + boost::lexical_cast<T>("4.832115561461656947793029596285626840312"), + boost::lexical_cast<T>("-19.86441536140337740383120735104359034688"), + boost::lexical_cast<T>("33.9927422807443239927197864963170585331"), + boost::lexical_cast<T>("-31.41520692249765980987427413991250886138"), + boost::lexical_cast<T>("17.0270866009599345679868972409543597821"), + boost::lexical_cast<T>("-5.5077216950865501362506920516723682167"), + boost::lexical_cast<T>("1.037811741948214855286817963800439373362"), + boost::lexical_cast<T>("-0.106640468537356182313660880481398642811"), + boost::lexical_cast<T>("0.005276450526660653288757565778182586742831"), + boost::lexical_cast<T>("-0.0001000935625597121545867453746252064770029"), + boost::lexical_cast<T>("0.462590910138598083940803704521211569234e-6"), + boost::lexical_cast<T>("-0.1735307814426389420248044907765671743012e-9"), + }; + T result = 0; + for(unsigned k = 1; k <= sizeof(d)/sizeof(d[0]); ++k) + { + result += (-d[k-1]*dz)/(k*dz + k*k); + } + return result; + } + + template<class T> + static T lanczos_sum_near_2(const T& dz) + { + static const T d[12] = { + boost::lexical_cast<T>("26.96979819614830698367887026728396466395"), + boost::lexical_cast<T>("-110.8705424709385114023884328797900204863"), + boost::lexical_cast<T>("189.7258846119231466417015694690434770085"), + boost::lexical_cast<T>("-175.3397202971107486383321670769397356553"), + boost::lexical_cast<T>("95.03437648691551457087250340903980824948"), + boost::lexical_cast<T>("-30.7406022781665264273675797983497141978"), + boost::lexical_cast<T>("5.792405601630517993355102578874590410552"), + boost::lexical_cast<T>("-0.5951993240669148697377539518639997795831"), + boost::lexical_cast<T>("0.02944979359164017509944724739946255067671"), + boost::lexical_cast<T>("-0.0005586586555377030921194246330399163602684"), + boost::lexical_cast<T>("0.2581888478270733025288922038673392636029e-5"), + boost::lexical_cast<T>("-0.9685385411006641478305219367315965391289e-9"), + }; + T result = 0; + T z = dz + 2; + for(unsigned k = 1; k <= sizeof(d)/sizeof(d[0]); ++k) + { + result += (-d[k-1]*dz)/(z + k*z + k*k - 1); + } + return result; + } + + static double g(){ return 13.1445650000000000545696821063756942749; } +}; + + +// +// Lanczos Coefficients for N=22 G=22.61891 +// Max experimental error (with arbitary precision arithmetic) 2.9524e-38 +// Generated with compiler: Microsoft Visual C++ version 8.0 on Win32 at Mar 23 2006 +// +struct lanczos22UDT +{ + template <class T> + static T lanczos_sum(const T& z) + { + static const T num[22] = { + boost::lexical_cast<T>("46198410803245094237463011094.12173081986"), + boost::lexical_cast<T>("43735859291852324413622037436.321513777"), + boost::lexical_cast<T>("19716607234435171720534556386.97481377748"), + boost::lexical_cast<T>("5629401471315018442177955161.245623932129"), + boost::lexical_cast<T>("1142024910634417138386281569.245580222392"), + boost::lexical_cast<T>("175048529315951173131586747.695329230778"), + boost::lexical_cast<T>("21044290245653709191654675.41581372963167"), + boost::lexical_cast<T>("2033001410561031998451380.335553678782601"), + boost::lexical_cast<T>("160394318862140953773928.8736211601848891"), + boost::lexical_cast<T>("10444944438396359705707.48957290388740896"), + boost::lexical_cast<T>("565075825801617290121.1466393747967538948"), + boost::lexical_cast<T>("25475874292116227538.99448534450411942597"), + boost::lexical_cast<T>("957135055846602154.6720835535232270205725"), + boost::lexical_cast<T>("29874506304047462.23662392445173880821515"), + boost::lexical_cast<T>("769651310384737.2749087590725764959689181"), + boost::lexical_cast<T>("16193289100889.15989633624378404096011797"), + boost::lexical_cast<T>("273781151680.6807433264462376754578933261"), + boost::lexical_cast<T>("3630485900.32917021712188739762161583295"), + boost::lexical_cast<T>("36374352.05577334277856865691538582936484"), + boost::lexical_cast<T>("258945.7742115532455441786924971194951043"), + boost::lexical_cast<T>("1167.501919472435718934219997431551246996"), + boost::lexical_cast<T>("2.50662827463100050241576528481104525333"), + }; + static const T denom[22] = { + boost::lexical_cast<T>("0"), + boost::lexical_cast<T>("2432902008176640000"), + boost::lexical_cast<T>("8752948036761600000"), + boost::lexical_cast<T>("13803759753640704000"), + boost::lexical_cast<T>("12870931245150988800"), + boost::lexical_cast<T>("8037811822645051776"), + boost::lexical_cast<T>("3599979517947607200"), + boost::lexical_cast<T>("1206647803780373360"), + boost::lexical_cast<T>("311333643161390640"), + boost::lexical_cast<T>("63030812099294896"), + boost::lexical_cast<T>("10142299865511450"), + boost::lexical_cast<T>("1307535010540395"), + boost::lexical_cast<T>("135585182899530"), + boost::lexical_cast<T>("11310276995381"), + boost::lexical_cast<T>("756111184500"), + boost::lexical_cast<T>("40171771630"), + boost::lexical_cast<T>("1672280820"), + boost::lexical_cast<T>("53327946"), + boost::lexical_cast<T>("1256850"), + boost::lexical_cast<T>("20615"), + boost::lexical_cast<T>("210"), + boost::lexical_cast<T>("1"), + }; + return boost::math::tools::evaluate_rational(num, denom, z, 22); + } + + template <class T> + static T lanczos_sum_expG_scaled(const T& z) + { + static const T num[22] = { + boost::lexical_cast<T>("6939996264376682180.277485395074954356211"), + boost::lexical_cast<T>("6570067992110214451.87201438870245659384"), + boost::lexical_cast<T>("2961859037444440551.986724631496417064121"), + boost::lexical_cast<T>("845657339772791245.3541226499766163431651"), + boost::lexical_cast<T>("171556737035449095.2475716923888737881837"), + boost::lexical_cast<T>("26296059072490867.7822441885603400926007"), + boost::lexical_cast<T>("3161305619652108.433798300149816829198706"), + boost::lexical_cast<T>("305400596026022.4774396904484542582526472"), + boost::lexical_cast<T>("24094681058862.55120507202622377623528108"), + boost::lexical_cast<T>("1569055604375.919477574824168939428328839"), + boost::lexical_cast<T>("84886558909.02047889339710230696942513159"), + boost::lexical_cast<T>("3827024985.166751989686050643579753162298"), + boost::lexical_cast<T>("143782298.9273215199098728674282885500522"), + boost::lexical_cast<T>("4487794.24541641841336786238909171265944"), + boost::lexical_cast<T>("115618.2025760830513505888216285273541959"), + boost::lexical_cast<T>("2432.580773108508276957461757328744780439"), + boost::lexical_cast<T>("41.12782532742893597168530008461874360191"), + boost::lexical_cast<T>("0.5453771709477689805460179187388702295792"), + boost::lexical_cast<T>("0.005464211062612080347167337964166505282809"), + boost::lexical_cast<T>("0.388992321263586767037090706042788910953e-4"), + boost::lexical_cast<T>("0.1753839324538447655939518484052327068859e-6"), + boost::lexical_cast<T>("0.3765495513732730583386223384116545391759e-9"), + }; + static const T denom[22] = { + boost::lexical_cast<T>("0"), + boost::lexical_cast<T>("2432902008176640000"), + boost::lexical_cast<T>("8752948036761600000"), + boost::lexical_cast<T>("13803759753640704000"), + boost::lexical_cast<T>("12870931245150988800"), + boost::lexical_cast<T>("8037811822645051776"), + boost::lexical_cast<T>("3599979517947607200"), + boost::lexical_cast<T>("1206647803780373360"), + boost::lexical_cast<T>("311333643161390640"), + boost::lexical_cast<T>("63030812099294896"), + boost::lexical_cast<T>("10142299865511450"), + boost::lexical_cast<T>("1307535010540395"), + boost::lexical_cast<T>("135585182899530"), + boost::lexical_cast<T>("11310276995381"), + boost::lexical_cast<T>("756111184500"), + boost::lexical_cast<T>("40171771630"), + boost::lexical_cast<T>("1672280820"), + boost::lexical_cast<T>("53327946"), + boost::lexical_cast<T>("1256850"), + boost::lexical_cast<T>("20615"), + boost::lexical_cast<T>("210"), + boost::lexical_cast<T>("1"), + }; + return boost::math::tools::evaluate_rational(num, denom, z, 22); + } + + + template<class T> + static T lanczos_sum_near_1(const T& dz) + { + static const T d[21] = { + boost::lexical_cast<T>("8.318998691953337183034781139546384476554"), + boost::lexical_cast<T>("-63.15415991415959158214140353299240638675"), + boost::lexical_cast<T>("217.3108224383632868591462242669081540163"), + boost::lexical_cast<T>("-448.5134281386108366899784093610397354889"), + boost::lexical_cast<T>("619.2903759363285456927248474593012711346"), + boost::lexical_cast<T>("-604.1630177420625418522025080080444177046"), + boost::lexical_cast<T>("428.8166750424646119935047118287362193314"), + boost::lexical_cast<T>("-224.6988753721310913866347429589434550302"), + boost::lexical_cast<T>("87.32181627555510833499451817622786940961"), + boost::lexical_cast<T>("-25.07866854821128965662498003029199058098"), + boost::lexical_cast<T>("5.264398125689025351448861011657789005392"), + boost::lexical_cast<T>("-0.792518936256495243383586076579921559914"), + boost::lexical_cast<T>("0.08317448364744713773350272460937904691566"), + boost::lexical_cast<T>("-0.005845345166274053157781068150827567998882"), + boost::lexical_cast<T>("0.0002599412126352082483326238522490030412391"), + boost::lexical_cast<T>("-0.6748102079670763884917431338234783496303e-5"), + boost::lexical_cast<T>("0.908824383434109002762325095643458603605e-7"), + boost::lexical_cast<T>("-0.5299325929309389890892469299969669579725e-9"), + boost::lexical_cast<T>("0.994306085859549890267983602248532869362e-12"), + boost::lexical_cast<T>("-0.3499893692975262747371544905820891835298e-15"), + boost::lexical_cast<T>("0.7260746353663365145454867069182884694961e-20"), + }; + T result = 0; + for(unsigned k = 1; k <= sizeof(d)/sizeof(d[0]); ++k) + { + result += (-d[k-1]*dz)/(k*dz + k*k); + } + return result; + } + + template<class T> + static T lanczos_sum_near_2(const T& dz) + { + static const T d[21] = { + boost::lexical_cast<T>("75.39272007105208086018421070699575462226"), + boost::lexical_cast<T>("-572.3481967049935412452681346759966390319"), + boost::lexical_cast<T>("1969.426202741555335078065370698955484358"), + boost::lexical_cast<T>("-4064.74968778032030891520063865996757519"), + boost::lexical_cast<T>("5612.452614138013929794736248384309574814"), + boost::lexical_cast<T>("-5475.357667500026172903620177988213902339"), + boost::lexical_cast<T>("3886.243614216111328329547926490398103492"), + boost::lexical_cast<T>("-2036.382026072125407192448069428134470564"), + boost::lexical_cast<T>("791.3727954936062108045551843636692287652"), + boost::lexical_cast<T>("-227.2808432388436552794021219198885223122"), + boost::lexical_cast<T>("47.70974355562144229897637024320739257284"), + boost::lexical_cast<T>("-7.182373807798293545187073539819697141572"), + boost::lexical_cast<T>("0.7537866989631514559601547530490976100468"), + boost::lexical_cast<T>("-0.05297470142240154822658739758236594717787"), + boost::lexical_cast<T>("0.00235577330936380542539812701472320434133"), + boost::lexical_cast<T>("-0.6115613067659273118098229498679502138802e-4"), + boost::lexical_cast<T>("0.8236417010170941915758315020695551724181e-6"), + boost::lexical_cast<T>("-0.4802628430993048190311242611330072198089e-8"), + boost::lexical_cast<T>("0.9011113376981524418952720279739624707342e-11"), + boost::lexical_cast<T>("-0.3171854152689711198382455703658589996796e-14"), + boost::lexical_cast<T>("0.6580207998808093935798753964580596673177e-19"), + }; + T result = 0; + T z = dz + 2; + for(unsigned k = 1; k <= sizeof(d)/sizeof(d[0]); ++k) + { + result += (-d[k-1]*dz)/(z + k*z + k*k - 1); + } + return result; + } + + static double g(){ return 22.61890999999999962710717227309942245483; } +}; + +// +// Lanczos Coefficients for N=31 G=32.08067 +// Max experimental error (with arbitary precision arithmetic) 0.162e-52 +// Generated with compiler: Microsoft Visual C++ version 8.0 on Win32 at May 9 2006 +// +struct lanczos31UDT +{ + template <class T> + static T lanczos_sum(const T& z) + { + static const T num[31] = { + boost::lexical_cast<T>("0.2579646553333513328235723061836959833277e46"), + boost::lexical_cast<T>("0.2444796504337453845497419271639377138264e46"), + boost::lexical_cast<T>("0.1119885499016017172212179730662673475329e46"), + boost::lexical_cast<T>("0.3301983829072723658949204487793889113715e45"), + boost::lexical_cast<T>("0.7041171040503851585152895336505379417066e44"), + boost::lexical_cast<T>("0.1156687509001223855125097826246939403504e44"), + boost::lexical_cast<T>("1522559363393940883866575697565974893306000"), + boost::lexical_cast<T>("164914363507650839510801418717701057005700"), + boost::lexical_cast<T>("14978522943127593263654178827041568394060"), + boost::lexical_cast<T>("1156707153701375383907746879648168666774"), + boost::lexical_cast<T>("76739431129980851159755403434593664173.2"), + boost::lexical_cast<T>("4407916278928188620282281495575981079.306"), + boost::lexical_cast<T>("220487883931812802092792125175269667.3004"), + boost::lexical_cast<T>("9644828280794966468052381443992828.433924"), + boost::lexical_cast<T>("369996467042247229310044531282837.6549068"), + boost::lexical_cast<T>("12468380890717344610932904378961.13494291"), + boost::lexical_cast<T>("369289245210898235894444657859.0529720075"), + boost::lexical_cast<T>("9607992460262594951559461829.34885209022"), + boost::lexical_cast<T>("219225935074853412540086410.981421315799"), + boost::lexical_cast<T>("4374309943598658046326340.720767382079549"), + boost::lexical_cast<T>("76008779092264509404014.10530947173485581"), + boost::lexical_cast<T>("1143503533822162444712.335663112617754987"), + boost::lexical_cast<T>("14779233719977576920.37884890049671578409"), + boost::lexical_cast<T>("162409028440678302.9992838032166348069916"), + boost::lexical_cast<T>("1496561553388385.733407609544964535634135"), + boost::lexical_cast<T>("11347624460661.81008311053190661436107043"), + boost::lexical_cast<T>("68944915931.32004991941950530448472223832"), + boost::lexical_cast<T>("322701221.6391432296123937035480931903651"), + boost::lexical_cast<T>("1092364.213992634267819050120261755371294"), + boost::lexical_cast<T>("2380.151399852411512711176940867823024864"), + boost::lexical_cast<T>("2.506628274631000502415765284811045253007"), + }; + static const T denom[31] = { + boost::lexical_cast<T>("0"), + boost::lexical_cast<T>("0.8841761993739701954543616e31"), + boost::lexical_cast<T>("0.3502799997985980526649278464e32"), + boost::lexical_cast<T>("0.622621928420356134910574592e32"), + boost::lexical_cast<T>("66951000306085302338993639424000"), + boost::lexical_cast<T>("49361465831621147825759587123200"), + boost::lexical_cast<T>("26751280755793398822580822142976"), + boost::lexical_cast<T>("11139316913434780466101123891200"), + boost::lexical_cast<T>("3674201658710345201899117607040"), + boost::lexical_cast<T>("981347603630155088295475765440"), + boost::lexical_cast<T>("215760462268683520394805979744"), + boost::lexical_cast<T>("39539238727270799376544542000"), + boost::lexical_cast<T>("6097272817323042122728617800"), + boost::lexical_cast<T>("796974693974455191377937300"), + boost::lexical_cast<T>("88776380550648116217781890"), + boost::lexical_cast<T>("8459574446076318147830625"), + boost::lexical_cast<T>("691254538651580660999025"), + boost::lexical_cast<T>("48487623689430693038025"), + boost::lexical_cast<T>("2918939500751087661105"), + boost::lexical_cast<T>("150566737512021319125"), + boost::lexical_cast<T>("6634460278534540725"), + boost::lexical_cast<T>("248526574856284725"), + boost::lexical_cast<T>("7860403394108265"), + boost::lexical_cast<T>("207912996295875"), + boost::lexical_cast<T>("4539323721075"), + boost::lexical_cast<T>("80328850875"), + boost::lexical_cast<T>("1122686019"), + boost::lexical_cast<T>("11921175"), + boost::lexical_cast<T>("90335"), + boost::lexical_cast<T>("435"), + boost::lexical_cast<T>("1"), + }; + return boost::math::tools::evaluate_rational(num, denom, z, 31); + } + + template <class T> + static T lanczos_sum_expG_scaled(const T& z) + { + static const T num[31] = { + boost::lexical_cast<T>("30137154810677525966583148469478.52374216"), + boost::lexical_cast<T>("28561746428637727032849890123131.36314653"), + boost::lexical_cast<T>("13083250730789213354063781611435.74046294"), + boost::lexical_cast<T>("3857598154697777600846539129354.783647"), + boost::lexical_cast<T>("822596651552555685068015316144.0952185852"), + boost::lexical_cast<T>("135131964033213842052904200372.039133532"), + boost::lexical_cast<T>("17787555889683709693655685146.19771358863"), + boost::lexical_cast<T>("1926639793777927562221423874.149673297196"), + boost::lexical_cast<T>("174989113988888477076973808.6991839697774"), + boost::lexical_cast<T>("13513425905835560387095425.01158383184045"), + boost::lexical_cast<T>("896521313378762433091075.1446749283094845"), + boost::lexical_cast<T>("51496223433749515758124.71524415105430686"), + boost::lexical_cast<T>("2575886794780078381228.37205955912263407"), + boost::lexical_cast<T>("112677328855422964200.4155776009524490958"), + boost::lexical_cast<T>("4322545967487943330.625233358130724324796"), + boost::lexical_cast<T>("145663957202380774.0362027607207590519723"), + boost::lexical_cast<T>("4314283729473470.686566233465428332496534"), + boost::lexical_cast<T>("112246988185485.8877916434026906290603878"), + boost::lexical_cast<T>("2561143864972.040563435178307062626388193"), + boost::lexical_cast<T>("51103611767.9626550674442537989885239605"), + boost::lexical_cast<T>("887985348.0369447209508500133077232094491"), + boost::lexical_cast<T>("13359172.3954672607019822025834072685839"), + boost::lexical_cast<T>("172660.8841147568768783928167105965064459"), + boost::lexical_cast<T>("1897.370795407433013556725714874693719617"), + boost::lexical_cast<T>("17.48383210090980598861217644749573257178"), + boost::lexical_cast<T>("0.1325705316732132940835251054350153028901"), + boost::lexical_cast<T>("0.0008054605783673449641889260501816356090452"), + boost::lexical_cast<T>("0.377001130700104515644336869896819162464e-5"), + boost::lexical_cast<T>("0.1276172868883867038813825443204454996531e-7"), + boost::lexical_cast<T>("0.2780651912081116274907381023821492811093e-10"), + boost::lexical_cast<T>("0.2928410648650955854121639682890739211234e-13"), + }; + static const T denom[31] = { + boost::lexical_cast<T>("0"), + boost::lexical_cast<T>("0.8841761993739701954543616e31"), + boost::lexical_cast<T>("0.3502799997985980526649278464e32"), + boost::lexical_cast<T>("0.622621928420356134910574592e32"), + boost::lexical_cast<T>("66951000306085302338993639424000"), + boost::lexical_cast<T>("49361465831621147825759587123200"), + boost::lexical_cast<T>("26751280755793398822580822142976"), + boost::lexical_cast<T>("11139316913434780466101123891200"), + boost::lexical_cast<T>("3674201658710345201899117607040"), + boost::lexical_cast<T>("981347603630155088295475765440"), + boost::lexical_cast<T>("215760462268683520394805979744"), + boost::lexical_cast<T>("39539238727270799376544542000"), + boost::lexical_cast<T>("6097272817323042122728617800"), + boost::lexical_cast<T>("796974693974455191377937300"), + boost::lexical_cast<T>("88776380550648116217781890"), + boost::lexical_cast<T>("8459574446076318147830625"), + boost::lexical_cast<T>("691254538651580660999025"), + boost::lexical_cast<T>("48487623689430693038025"), + boost::lexical_cast<T>("2918939500751087661105"), + boost::lexical_cast<T>("150566737512021319125"), + boost::lexical_cast<T>("6634460278534540725"), + boost::lexical_cast<T>("248526574856284725"), + boost::lexical_cast<T>("7860403394108265"), + boost::lexical_cast<T>("207912996295875"), + boost::lexical_cast<T>("4539323721075"), + boost::lexical_cast<T>("80328850875"), + boost::lexical_cast<T>("1122686019"), + boost::lexical_cast<T>("11921175"), + boost::lexical_cast<T>("90335"), + boost::lexical_cast<T>("435"), + boost::lexical_cast<T>("1"), + }; + return boost::math::tools::evaluate_rational(num, denom, z, 31); + } + + + template<class T> + static T lanczos_sum_near_1(const T& dz) + { + static const T d[30] = { + boost::lexical_cast<T>("11.80038544942943603508206880307972596807"), + boost::lexical_cast<T>("-130.6355975335626214564236363322099481079"), + boost::lexical_cast<T>("676.2177719145993049893392276809256538927"), + boost::lexical_cast<T>("-2174.724497783850503069990936574060452057"), + boost::lexical_cast<T>("4869.877180638131076410069103742986502022"), + boost::lexical_cast<T>("-8065.744271864238179992762265472478229172"), + boost::lexical_cast<T>("10245.03825618572106228191509520638651539"), + boost::lexical_cast<T>("-10212.83902362683215459850403668669647192"), + boost::lexical_cast<T>("8110.289185383288952562767679576754140336"), + boost::lexical_cast<T>("-5179.310892558291062401828964000776095156"), + boost::lexical_cast<T>("2673.987492589052370230989109591011091273"), + boost::lexical_cast<T>("-1118.342574651205183051884250033505609141"), + boost::lexical_cast<T>("378.5812742511620662650096436471920295596"), + boost::lexical_cast<T>("-103.3725999812126067084828735543906768961"), + boost::lexical_cast<T>("22.62913974335996321848099677797888917792"), + boost::lexical_cast<T>("-3.936414819950859548507275533569588041446"), + boost::lexical_cast<T>("0.5376818198843817355682124535902641644854"), + boost::lexical_cast<T>("-0.0567827903603478957483409124122554243201"), + boost::lexical_cast<T>("0.004545544993648879420352693271088478106482"), + boost::lexical_cast<T>("-0.0002689795568951033950042375135970897959935"), + boost::lexical_cast<T>("0.1139493459006846530734617710847103572122e-4"), + boost::lexical_cast<T>("-0.3316581197839213921885210451302820192794e-6"), + boost::lexical_cast<T>("0.6285613334898374028443777562554713906213e-8"), + boost::lexical_cast<T>("-0.7222145115734409070310317999856424167091e-10"), + boost::lexical_cast<T>("0.4562976983547274766890241815002584238219e-12"), + boost::lexical_cast<T>("-0.1380593023819058919640038942493212141072e-14"), + boost::lexical_cast<T>("0.1629663871586410129307496385264268190679e-17"), + boost::lexical_cast<T>("-0.5429994291916548849493889660077076739993e-21"), + boost::lexical_cast<T>("0.2922682842441892106795386303084661338957e-25"), + boost::lexical_cast<T>("-0.8456967065309046044689041041336866118459e-31"), + }; + T result = 0; + for(unsigned k = 1; k <= sizeof(d)/sizeof(d[0]); ++k) + { + result += (-d[k-1]*dz)/(k*dz + k*k); + } + return result; + } + + template<class T> + static T lanczos_sum_near_2(const T& dz) + { + static const T d[30] = { + boost::lexical_cast<T>("147.9979641587472136175636384176549713358"), + boost::lexical_cast<T>("-1638.404318611773924210055619836375434296"), + boost::lexical_cast<T>("8480.981744216135641122944743711911653273"), + boost::lexical_cast<T>("-27274.93942104458448200467097634494071176"), + boost::lexical_cast<T>("61076.98019918759324489193232276937262854"), + boost::lexical_cast<T>("-101158.8762737154296509560513952101409264"), + boost::lexical_cast<T>("128491.1252383947174824913796141607174379"), + boost::lexical_cast<T>("-128087.2892038336581928787480535905496026"), + boost::lexical_cast<T>("101717.5492545853663296795562084430123258"), + boost::lexical_cast<T>("-64957.8330410311808907869707511362206858"), + boost::lexical_cast<T>("33536.59139229792478811870738772305570317"), + boost::lexical_cast<T>("-14026.01847115365926835980820243003785821"), + boost::lexical_cast<T>("4748.087094096186515212209389240715050212"), + boost::lexical_cast<T>("-1296.477510211815971152205100242259733245"), + boost::lexical_cast<T>("283.8099337545793198947620951499958085157"), + boost::lexical_cast<T>("-49.36969067101255103452092297769364837753"), + boost::lexical_cast<T>("6.743492833270653628580811118017061581404"), + boost::lexical_cast<T>("-0.7121578704864048548351804794951487823626"), + boost::lexical_cast<T>("0.0570092738016915476694118877057948681298"), + boost::lexical_cast<T>("-0.003373485297696102660302960722607722438643"), + boost::lexical_cast<T>("0.0001429128843527532859999752593761934089751"), + boost::lexical_cast<T>("-0.41595867130858508233493767243236888636e-5"), + boost::lexical_cast<T>("0.7883284669307241040059778207492255409785e-7"), + boost::lexical_cast<T>("-0.905786322462384670803148223703187214379e-9"), + boost::lexical_cast<T>("0.5722790216999820323272452464661250331451e-11"), + boost::lexical_cast<T>("-0.1731510870832349779315841757234562309727e-13"), + boost::lexical_cast<T>("0.2043890314358438601429048378015983874378e-16"), + boost::lexical_cast<T>("-0.6810185176079344204740000170500311171065e-20"), + boost::lexical_cast<T>("0.3665567641131713928114853776588342403919e-24"), + boost::lexical_cast<T>("-0.1060655106553177007425710511436497259484e-29"), + }; + T result = 0; + T z = dz + 2; + for(unsigned k = 1; k <= sizeof(d)/sizeof(d[0]); ++k) + { + result += (-d[k-1]*dz)/(z + k*z + k*k - 1); + } + return result; + } + + static double g(){ return 32.08066999999999779902282170951366424561; } +}; + +// +// Lanczos Coefficients for N=61 G=63.192152 +// Max experimental error (with 1000-bit precision arithmetic) 3.740e-113 +// Generated with compiler: Microsoft Visual C++ version 8.0 on Win32 at Mar 12 2006 +// +struct lanczos61UDT +{ + template <class T> + static T lanczos_sum(const T& z) + { + using namespace boost; + static const T d[61] = { + boost::lexical_cast<T>("2.50662827463100050241576528481104525300698674060993831662992357634229365460784197494659584"), + boost::lexical_cast<T>("13349415823254323512107320481.3495396037261649201426994438803767191136434970492309775123879"), + boost::lexical_cast<T>("-300542621510568204264185787475.230003734889859348050696493467253861933279360152095861484548"), + boost::lexical_cast<T>("3273919938390136737194044982676.40271056035622723775417608127544182097346526115858803376474"), + boost::lexical_cast<T>("-22989594065095806099337396006399.5874206181563663855129141706748733174902067950115092492439"), + boost::lexical_cast<T>("116970582893952893160414263796102.542775878583510989850142808618916073286745084692189044738"), + boost::lexical_cast<T>("-459561969036479455224850813196807.283291532483532558959779434457349912822256480548436066098"), + boost::lexical_cast<T>("1450959909778264914956547227964788.89797179379520834974601372820249784303794436366366810477"), + boost::lexical_cast<T>("-3782846865486775046285288437885921.41537699732805465141128848354901016102326190612528503251"), + boost::lexical_cast<T>("8305043213936355459145388670886540.09976337905520168067329932809302445437208115570138102767"), + boost::lexical_cast<T>("-15580988484396722546934484726970745.4927787160273626078250810989811865283255762028143642311"), + boost::lexical_cast<T>("25262722284076250779006793435537600.0822901485517345545978818780090308947301031347345640449"), + boost::lexical_cast<T>("-35714428027687018805443603728757116.5304655170478705341887572982734901197345415291580897698"), + boost::lexical_cast<T>("44334726194692443174715432419157343.2294160783772787096321009453791271387235388689346602833"), + boost::lexical_cast<T>("-48599573547617297831555162417695106.187829304963846482633791012658974681648157963911491985"), + boost::lexical_cast<T>("47258466493366798944386359199482189.0753349196625125615316002614813737880755896979754845101"), + boost::lexical_cast<T>("-40913448215392412059728312039233342.142914753896559359297977982314043378636755884088383226"), + boost::lexical_cast<T>("31626312914486892948769164616982902.7262756989418188077611392594232674722318027323102462687"), + boost::lexical_cast<T>("-21878079174441332123064991795834438.4699982361692990285700077902601657354101259411789722708"), + boost::lexical_cast<T>("13567268503974326527361474986354265.3136632133935430378937191911532112778452274286122946396"), + boost::lexical_cast<T>("-7551494211746723529747611556474669.62996644923557605747803028485900789337467673523741066527"), + boost::lexical_cast<T>("3775516572689476384052312341432597.70584966904950490541958869730702790312581801585742038997"), + boost::lexical_cast<T>("-1696271471453637244930364711513292.79902955514107737992185368006225264329876265486853482449"), + boost::lexical_cast<T>("684857608019352767999083000986166.20765273693720041519286231015176745354062413008561259139"), + boost::lexical_cast<T>("-248397566275708464679881624417990.410438107634139924805871051723444048539177890346227250473"), + boost::lexical_cast<T>("80880368999557992138783568858556.1512378233079327986518410244522800950609595592170022878937"), + boost::lexical_cast<T>("-23618197945394013802495450485616.9025005749893350650829964098117490779655546610665927669729"), + boost::lexical_cast<T>("6176884636893816103087134481332.06708966653493024119556843727320635285468825056891248447124"), + boost::lexical_cast<T>("-1444348683723439589948246285262.64080678953468490544615312565485170860503207005915261691108"), + boost::lexical_cast<T>("301342031656979076702313946827.961658905182634508217626783081241074250132289461989777865387"), + boost::lexical_cast<T>("-55959656587719766738301589651.3940625826610668990368881615587469329021742236397809951765678"), + boost::lexical_cast<T>("9223339169004064297247180402.36227016155682738556103138196079389248843082157924368301293963"), + boost::lexical_cast<T>("-1344882881571942601385730283.42710150182526891377514071881534880944872423492272147871101373"), + boost::lexical_cast<T>("172841913316760599352601139.54409257740173055624405575900164401527761357324625574736896079"), + boost::lexical_cast<T>("-19496120443876233531343952.3802212016691702737346568192063937387825469602063310488794471653"), + boost::lexical_cast<T>("1920907372583710284097959.44121420322495784420169085871802458519363819782779653621724219067"), + boost::lexical_cast<T>("-164429314798240461613359.399597503536657962383155875723527581699785846599051112719962464604"), + boost::lexical_cast<T>("12154026644351189572525.1452249886865981747374191977801688548318519692423556934568426042152"), + boost::lexical_cast<T>("-770443988366210815096.519382051977221101156336663806705367929328924137169970381042234329058"), + boost::lexical_cast<T>("41558909851418707920.4696085656889424895313728719601503526476333404973280596225722152966128"), + boost::lexical_cast<T>("-1890879946549708819.24562220042687554209318172044783707920086716716717574156283898330017796"), + boost::lexical_cast<T>("71844996557297623.9583461685535340440524052492427928388171299145330229958643439878608673403"), + boost::lexical_cast<T>("-2253785109518255.55600197759875781765803818232939130127735487613049577235879610065545755637"), + boost::lexical_cast<T>("57616883849355.997562563968344493719962252675875692642406455612671495250543228005045106721"), + boost::lexical_cast<T>("-1182495730353.08218118278997948852215670614084013289033222774171548915344541249351599628436"), + boost::lexical_cast<T>("19148649358.6196967288062261380599423925174178776792840639099120170800869284300966978300613"), + boost::lexical_cast<T>("-239779605.891370259668403359614360511661030470269478602533200704639655585967442891496784613"), + boost::lexical_cast<T>("2267583.00284368310957842936892685032434505866445291643236133553754152047677944820353796872"), + boost::lexical_cast<T>("-15749.490806784673108773558070497383604733010677027764233749920147549999361110299643477893"), + boost::lexical_cast<T>("77.7059495149052727171505425584459982871343274332635726864135949842508025564999785370162956"), + boost::lexical_cast<T>("-0.261619987273930331397625130282851629108569607193781378836014468617185550622160348688297247"), + boost::lexical_cast<T>("0.000572252321659691600529444769356185993188551770817110673186068921175991328434642504616377475"), + boost::lexical_cast<T>("-0.765167220661540041663007112207436426423746402583423562585653954743978584117929356523307954e-6"), + boost::lexical_cast<T>("0.579179571056209077507916813937971472839851499147582627425979879366849876944438724610663401e-9"), + boost::lexical_cast<T>("-0.224804733043915149719206760378355636826808754704148660354494460792713189958510735070096991e-12"), + boost::lexical_cast<T>("0.392711975389579343321746945135488409914483448652884894759297584020979857734289645857714768e-16"), + boost::lexical_cast<T>("-0.258603588346412049542768766878162221817684639789901440429511261589010049357907537684380983e-20"), + boost::lexical_cast<T>("0.499992460848751668441190360024540741752242879565548017176883304716370989218399797418478685e-25"), + boost::lexical_cast<T>("-0.196211614533318174187346267877390498735734213905206562766348625767919122511096089367364025e-30"), + boost::lexical_cast<T>("0.874722648949676363732094858062907290148733370978226751462386623191111439121706262759209573e-37"), + boost::lexical_cast<T>("-0.163907874717737848669759890242660846846105433791283903651924563157080252845636658802930428e-44"), + }; + T result = d[0]; + for(unsigned k = 1; k < sizeof(d)/sizeof(d[0]); ++k) + { + result += d[k]/(z+(k-1)); + } + return result; + } + + template <class T> + static T lanczos_sum_expG_scaled(const T& z) + { + using namespace boost; + static const T d[61] = { + boost::lexical_cast<T>("0.901751806425638853077358552989167785490911341809902155556127108480303870921448984935411583e-27"), + boost::lexical_cast<T>("4.80241125306810017699523302110401965428995345115391817406006361151407344955277298373661032"), + boost::lexical_cast<T>("-108.119283021710869401330097315436214587270846871451487282117128515476478251641970487922552"), + boost::lexical_cast<T>("1177.78262074811362219818923738088833932279000985161077740440010901595132448469513438139561"), + boost::lexical_cast<T>("-8270.43570321334374279057432173814835581983913167617217749736484999327758232081395983082867"), + boost::lexical_cast<T>("42079.807161997077661752306902088979258826568702655699995911391774839958572703348502730394"), + boost::lexical_cast<T>("-165326.003834443330215001219988296482004968548294447320869281647211603153902436231468280089"), + boost::lexical_cast<T>("521978.361504895300685499370463597042533432134369277742485307843747923127933979566742421213"), + boost::lexical_cast<T>("-1360867.51629992863544553419296636395576666570468519805449755596254912681418267100657262281"), + boost::lexical_cast<T>("2987713.73338656161102517003716335104823650191612448011720936412226357385029800040631754755"), + boost::lexical_cast<T>("-5605212.64915921452169919008770165304171481697939254152852673009005154549681704553438450709"), + boost::lexical_cast<T>("9088186.58332916818449459635132673652700922052988327069535513580836143146727832380184335474"), + boost::lexical_cast<T>("-12848155.5543636394746355365819800465364996596310467415907815393346205151090486190421959769"), + boost::lexical_cast<T>("15949281.2867656960575878805158849857756293807220033618942867694361569866468996967761600898"), + boost::lexical_cast<T>("-17483546.9948295433308250581770557182576171673272450149400973735206019559576269174369907171"), + boost::lexical_cast<T>("17001087.8599749419660906448951424280111036786456594738278573653160553115681287326064596964"), + boost::lexical_cast<T>("-14718487.0643665950346574802384331125115747311674609017568623694516187494204567579595827859"), + boost::lexical_cast<T>("11377468.7255609717716845971105161298889777425898291183866813269222281486121330837791392732"), + boost::lexical_cast<T>("-7870571.64253038587947746661946939286858490057774448573157856145556080330153403858747655263"), + boost::lexical_cast<T>("4880783.08440908743641723492059912671377140680710345996273343885045364205895751515063844239"), + boost::lexical_cast<T>("-2716626.7992639625103140035635916455652302249897918893040695025407382316653674141983775542"), + boost::lexical_cast<T>("1358230.46602865696544327299659410214201327791319846880787515156343361311278133805428800255"), + boost::lexical_cast<T>("-610228.440751458395860905749312275043435828322076830117123636938979942213530882048883969802"), + boost::lexical_cast<T>("246375.416501158654327780901087115642493055617468601787093268312234390446439555559050129729"), + boost::lexical_cast<T>("-89360.2599028475206119333931211015869139511677735549267100272095432140508089207221096740632"), + boost::lexical_cast<T>("29096.4637987498328341260960356772198979319790332957125131055960448759586930781530063775634"), + boost::lexical_cast<T>("-8496.57401431514433694413130585404918350686834939156759654375188338156288564260152505382438"), + boost::lexical_cast<T>("2222.11523574301594407443285016240908726891841242444092960094015874546135316534057865883047"), + boost::lexical_cast<T>("-519.599993280949289705514822058693289933461756514489674453254304308040888101533569480646682"), + boost::lexical_cast<T>("108.406868361306987817730701109400305482972790224573776407166683184990131682003417239181112"), + boost::lexical_cast<T>("-20.1313142142558596796857948064047373605439974799116521459977609253211918146595346493447238"), + boost::lexical_cast<T>("3.31806787671783168020012913552384112429614503798293169239082032849759155847394955909684383"), + boost::lexical_cast<T>("-0.483817477111537877685595212919784447924875428848331771524426361483392903320495411973587861"), + boost::lexical_cast<T>("0.0621793463102927384924303843912913542297042029136293808338022462765755471002366206711862637"), + boost::lexical_cast<T>("-0.00701366932085103924241526535768453911099671087892444015581511551813219720807206445462785293"), + boost::lexical_cast<T>("0.000691040514756294308758606917671220770856269030526647010461217455799229645004351524024364997"), + boost::lexical_cast<T>("-0.591529398871361458428147660822525365922497109038495896497692806150033516658042357799869656e-4"), + boost::lexical_cast<T>("0.437237367535177689875119370170434437030440227275583289093139147244747901678407875809020739e-5"), + boost::lexical_cast<T>("-0.277164853397051135996651958345647824709602266382721185838782221179129726200661453504250697e-6"), + boost::lexical_cast<T>("0.149506899012035980148891401548317536032574502641368034781671941165064546410613201579653674e-7"), + boost::lexical_cast<T>("-0.68023824066463262779882895193964639544061678698791279217407325790147925675797085217462974e-9"), + boost::lexical_cast<T>("0.258460163734186329938721529982859244969655253624066115559707985878606277800329299821882688e-10"), + boost::lexical_cast<T>("-0.810792256024669306744649981276512583535251727474303382740940985102669076169168931092026491e-12"), + boost::lexical_cast<T>("0.207274966207031327521921078048021807442500113231320959236850963529304158700096495799022922e-13"), + boost::lexical_cast<T>("-0.425399199286327802950259994834798737777721414442095221716122926637623478450472871269742436e-15"), + boost::lexical_cast<T>("0.688866766744198529064607574117697940084548375790020728788313274612845280173338912495478431e-17"), + boost::lexical_cast<T>("-0.862599751805643281578607291655858333628582704771553874199104377131082877406179933909898885e-19"), + boost::lexical_cast<T>("0.815756005678735657200275584442908437977926312650210429668619446123450972547018343768177988e-21"), + boost::lexical_cast<T>("-0.566583084099007858124915716926967268295318152203932871370429534546567151650626184750291695e-23"), + boost::lexical_cast<T>("0.279544761599725082805446124351997692260093135930731230328454667675190245860598623539891708e-25"), + boost::lexical_cast<T>("-0.941169851584987983984201821679114408126982142904386301937192011680047611188837432096199601e-28"), + boost::lexical_cast<T>("0.205866011331040736302780507155525142187875191518455173304638008169488993406425201915370746e-30"), + boost::lexical_cast<T>("-0.27526655245712584371295491216289353976964567057707464008951584303679019796521332324352501e-33"), + boost::lexical_cast<T>("0.208358067979444305082929004102609366169534624348056112144990933897581971394396210379638792e-36"), + boost::lexical_cast<T>("-0.808728107661779323263133007119729988596844663194254976820030366188579170595441991680169012e-40"), + boost::lexical_cast<T>("0.141276924383478964519776436955079978012672985961918248012931336621229652792338950573694356e-43"), + boost::lexical_cast<T>("-0.930318449287651389310440021745842417218125582685428432576258687100661462527604238849332053e-48"), + boost::lexical_cast<T>("0.179870748819321661641184169834635133045197146966203370650788171790610563029431722308057539e-52"), + boost::lexical_cast<T>("-0.705865243912790337263229413370018392321238639017433365017168104310561824133229343750737083e-58"), + boost::lexical_cast<T>("0.3146787805734405996448268100558028857930560442377698646099945108125281507396722995748398e-64"), + boost::lexical_cast<T>("-0.589653534231618730406843260601322236697428143603814281282790370329151249078338470962782338e-72"), + }; + T result = d[0]; + for(unsigned k = 1; k < sizeof(d)/sizeof(d[0]); ++k) + { + result += d[k]/(z+(k-1)); + } + return result; + } + + template<class T> + static T lanczos_sum_near_1(const T& dz) + { + using namespace boost; + static const T d[60] = { + boost::lexical_cast<T>("23.2463658527729692390378860713647146932236940604550445351214987229819352880524561852919518"), + boost::lexical_cast<T>("-523.358012551815715084547614110229469295755088686612838322817729744722233637819564673967396"), + boost::lexical_cast<T>("5701.12892340421080714956066268650092612647620400476183901625272640935853188559347587495571"), + boost::lexical_cast<T>("-40033.5506451901904954336453419007623117537868026994808919201793803506999271787018654246699"), + boost::lexical_cast<T>("203689.884259074923009439144410340256983393397995558814367995938668111650624499963153485034"), + boost::lexical_cast<T>("-800270.648969745331278757692597096167418585957703057412758177038340791380011708874081291202"), + boost::lexical_cast<T>("2526668.23380061659863999395867315313385499515711742092815402701950519696944982260718031476"), + boost::lexical_cast<T>("-6587362.57559198722630391278043503867973853468105110382293763174847657538179665571836023631"), + boost::lexical_cast<T>("14462211.3454541602975917764900442754186801975533106565506542322063393991552960595701762805"), + boost::lexical_cast<T>("-27132375.1879227404375395522940895789625516798992585980380939378508607160857820002128106898"), + boost::lexical_cast<T>("43991923.8735251977856804364757478459275087361742168436524951824945035673768875988985478116"), + boost::lexical_cast<T>("-62192284.0030124679010201921841372967696262036115679150017649233887633598058364494608060812"), + boost::lexical_cast<T>("77203473.0770033513405070667417251568915937590689150831268228886281254637715669678358204991"), + boost::lexical_cast<T>("-84630180.2217173903516348977915150565994784278120192219937728967986198118628659866582594874"), + boost::lexical_cast<T>("82294807.2253549409847505891112074804416229757832871133388349982640444405470371147991706317"), + boost::lexical_cast<T>("-71245738.2484649177928765605893043553453557808557887270209768163561363857395639001251515788"), + boost::lexical_cast<T>("55073334.3180266913441333534260714059077572215147571872597651029894142803987981342430068594"), + boost::lexical_cast<T>("-38097984.1648990787690036742690550656061009857688125101191167768314179751258568264424911474"), + boost::lexical_cast<T>("23625729.5032184580395130592017474282828236643586203914515183078852982915252442161768527976"), + boost::lexical_cast<T>("-13149998.4348054726172055622442157883429575511528431835657668083088902165366619827169829685"), + boost::lexical_cast<T>("6574597.77221556423683199818131482663205682902023554728024972161230111356285973623550338976"), + boost::lexical_cast<T>("-2953848.1483469149918109110050192571921018042012905892107136410603990336401921230407043408"), + boost::lexical_cast<T>("1192595.29584357246380113611351829515963605337523874715861849584306265512819543347806085356"), + boost::lexical_cast<T>("-432553.812019608638388918135375154289816441900572658692369491476137741687213006403648722272"), + boost::lexical_cast<T>("140843.215385933866391177743292449477205328233960902455943995092958295858485718885800427129"), + boost::lexical_cast<T>("-41128.186992679630058614841985110676526199977321524879849001760603476646382839182691529968"), + boost::lexical_cast<T>("10756.2849191854701631989789887757784944313743544315113894758328432005767448056040879337769"), + boost::lexical_cast<T>("-2515.15559672041299884426826962296210458052543246529646213159169885444118227871246315458787"), + boost::lexical_cast<T>("524.750087004805200600237632074908875763734578390662349666321453103782638818305404274166951"), + boost::lexical_cast<T>("-97.4468596421732493988298219295878130651986131393383646674144877163795143930682205035917965"), + boost::lexical_cast<T>("16.0613108128210806736384551896802799172445298357754547684100294231532127326987175444453058"), + boost::lexical_cast<T>("-2.34194813526540240672426202485306862230641838409943369059203455578340880900483887447559874"), + boost::lexical_cast<T>("0.300982934748016059399829007219431333744032924923669397318820178988611410275964499475465815"), + boost::lexical_cast<T>("-0.033950095985367909789000959795708551814461844488183964432565731809399824963680858993718525"), + boost::lexical_cast<T>("0.00334502394288921146242772614150438404658527112198421937945605441697314216921393987758378122"), + boost::lexical_cast<T>("-0.000286333429067523984607730553301991502191011265745476190940771685897687956262049750683013485"), + boost::lexical_cast<T>("0.211647426149364947402896718485536530479491688838087899435991994237067890628274492042231115e-4"), + boost::lexical_cast<T>("-0.134163345121302758109675190598169832775248626443483098532368562186356128620805552609175683e-5"), + boost::lexical_cast<T>("0.723697303042715085329782938306424498336642078597508935450663080894255773653328980495047891e-7"), + boost::lexical_cast<T>("-0.329273487343139063533251321553223583999676337945788660475231347828772272134656322947906888e-8"), + boost::lexical_cast<T>("0.12510922551028971731767784013117088894558604838820475961392154031378891971216135267744134e-9"), + boost::lexical_cast<T>("-0.392468958215589939603666430583400537413757786057185505426804034745840192914621891690369903e-11"), + boost::lexical_cast<T>("0.100332717101049934370760667782927946803279422001380028508200697081188326364078428184546051e-12"), + boost::lexical_cast<T>("-0.205917088291197705194762747639836655808855850989058813560983717575008725393428497910009756e-14"), + boost::lexical_cast<T>("0.333450178247893143608439314203175490705783992567107481617660357577257627854979230819461489e-16"), + boost::lexical_cast<T>("-0.417546693906616047110563550428133589051498362676394888715581845170969319500638944065594319e-18"), + boost::lexical_cast<T>("0.394871691642184410859178529844325390739857256666676534513661579365702353214518478078730801e-20"), + boost::lexical_cast<T>("-0.274258012587811199757875927548699264063511843669070634471054184977334027224611843434000922e-22"), + boost::lexical_cast<T>("0.135315354265459854889496635967343027244391821142592599244505313738163473730636430399785048e-24"), + boost::lexical_cast<T>("-0.455579032003288910408487905303223613382276173706542364543918076752861628464036586507967767e-27"), + boost::lexical_cast<T>("0.99650703862462739161520123768147312466695159780582506041370833824093136783202694548427718e-30"), + boost::lexical_cast<T>("-0.1332444609228706921659395801935919548447859029572115502899861345555006827214220195650058e-32"), + boost::lexical_cast<T>("0.100856999148765307000182397631280249632761913433008379786888200467467364474581430670889392e-35"), + boost::lexical_cast<T>("-0.39146979455613683472384690509165395074425354524713697428673406058157887065953366609738731e-39"), + boost::lexical_cast<T>("0.683859606707931248105140296850112494069265272540298100341919970496564103098283709868586478e-43"), + boost::lexical_cast<T>("-0.450326344248604222735147147805963966503893913752040066400766411031387063854141246972061792e-47"), + boost::lexical_cast<T>("0.870675378039492904184581895322153006461319724931909799151743284769901586333730037761678891e-52"), + boost::lexical_cast<T>("-0.341678395249272265744518787745356400350877656459401143889000625280131819505857966769964401e-57"), + boost::lexical_cast<T>("0.152322191370871666358069530949353871960316638394428595988162174042653299702098929238880862e-63"), + boost::lexical_cast<T>("-0.285425405297633795767452984791738825078111150078605004958179057245980222485147999495352632e-71"), + }; + T result = 0; + for(unsigned k = 1; k <= sizeof(d)/sizeof(d[0]); ++k) + { + result += (-d[k-1]*dz)/(k*dz + k*k); + } + return result; + } + + template<class T> + static T lanczos_sum_near_2(const T& dz) + { + using namespace boost; + static const T d[60] = { + boost::lexical_cast<T>("557.56438192770795764344217888434355281097193198928944200046501607026919782564033547346298"), + boost::lexical_cast<T>("-12552.748616427645475141433405567201788681683808077269330800392600825597799119572762385222"), + boost::lexical_cast<T>("136741.650054039199076788077149441364242294724343897779563222338447737802381279007988884806"), + boost::lexical_cast<T>("-960205.223613240309942047656967301131022760634321049075674684679438471862998829007639437133"), + boost::lexical_cast<T>("4885504.47588736223774859617054275229642041717942140469884121916073195308537421162982679289"), + boost::lexical_cast<T>("-19194501.738192166918904824982935279260356575935661514109550613809352009246483412530545583"), + boost::lexical_cast<T>("60602169.8633537742937457094837494059849674261357199218329545854990149896822944801504450843"), + boost::lexical_cast<T>("-157997975.522506767297528502540724511908584668874487506510120462561270100749019845014382885"), + boost::lexical_cast<T>("346876323.86092543685419723290495817330608574729543216092477261152247521712190505658568876"), + boost::lexical_cast<T>("-650770365.471136883718747607976242475416651908858429752332176373467422603953536408709972919"), + boost::lexical_cast<T>("1055146856.05909309330903130910708372830487315684258450293308627289334336871273080305128138"), + boost::lexical_cast<T>("-1491682726.25614447429071368736790697283307005456720192465860871846879804207692411263924608"), + boost::lexical_cast<T>("1851726287.94866167094858600116562210167031458934987154557042242638980748286188183300900268"), + boost::lexical_cast<T>("-2029855953.68334371445800569238095379629407314338521720558391277508374519526853827142679839"), + boost::lexical_cast<T>("1973842002.53354868177824629525448788555435194808657489238517523691040148611221295436287925"), + boost::lexical_cast<T>("-1708829941.98209573247426625323314413060108441455314880934710595647408841619484540679859098"), + boost::lexical_cast<T>("1320934627.12433688699625456833930317624783222321555050330381730035733198249283009357314954"), + boost::lexical_cast<T>("-913780636.858542526294419197161614811332299249415125108737474024007693329922089123296358727"), + boost::lexical_cast<T>("566663423.929632170286007468016419798879660054391183200464733820209439185545886930103546787"), + boost::lexical_cast<T>("-315402880.436816230388857961460509181823167373029384218959199936902955049832392362044305869"), + boost::lexical_cast<T>("157691811.550465734461741500275930418786875005567018699867961482249002625886064187146134966"), + boost::lexical_cast<T>("-70848085.5705405970640618473551954585013808128304384354476488268600720054598122945113512731"), + boost::lexical_cast<T>("28604413.4050137708444142264980840059788755325900041515286382001704951527733220637586013815"), + boost::lexical_cast<T>("-10374808.7067303054787164054055989420809074792801592763124972441820101840292558840131568633"), + boost::lexical_cast<T>("3378126.32016207486657791623723515804931231041318964254116390764473281291389374196880720069"), + boost::lexical_cast<T>("-986460.090390653140964189383080344920103075349535669020623874668558777188889544398718979744"), + boost::lexical_cast<T>("257989.631187387317948158483575125380011593209850756066176921901006833159795100137743395985"), + boost::lexical_cast<T>("-60326.0391159227288325790327830741260824763549807922845004854215660451399733578621565837087"), + boost::lexical_cast<T>("12586.1375399649496159880821645216260841794563919652590583420570326276086323953958907053394"), + boost::lexical_cast<T>("-2337.26417330316922535871922886167444795452055677161063205953141105726549966801856628447293"), + boost::lexical_cast<T>("385.230745012608736644117458716226876976056390433401632749144285378123105481506733917763829"), + boost::lexical_cast<T>("-56.1716559403731491675970177460841997333796694857076749852739159067307309470690838101179615"), + boost::lexical_cast<T>("7.21907953468550196348585224042498727840087634483369357697580053424523903859773769748599575"), + boost::lexical_cast<T>("-0.814293485887386870805786409956942772883474224091975496298369877683530509729332902182019049"), + boost::lexical_cast<T>("0.0802304419995150047616460464220884371214157889148846405799324851793571580868840034085001373"), + boost::lexical_cast<T>("-0.00686771095380619535195996193943858680694970000948742557733102777115482017857981277171196115"), + boost::lexical_cast<T>("0.000507636621977556438232617777542864427109623356049335590894564220687567763620803789858345916"), + boost::lexical_cast<T>("-0.32179095465362720747836116655088181481893063531138957363431280817392443948706754917605911e-4"), + boost::lexical_cast<T>("0.173578890579848508947329833426585354230744194615295570820295052665075101971588563893718407e-5"), + boost::lexical_cast<T>("-0.789762880006288893888161070734302768702358633525134582027140158619195373770299678322596835e-7"), + boost::lexical_cast<T>("0.300074637200885066788470310738617992259402710843493097610337134266720909870967550606601658e-8"), + boost::lexical_cast<T>("-0.941337297619721713151110244242536308266701344868601679868536153775533330272973088246835359e-10"), + boost::lexical_cast<T>("0.24064815013182536657310186836079333949814111498828401548170442715552017773994482539471456e-11"), + boost::lexical_cast<T>("-0.493892399304811910466345686492277504628763169549384435563232052965821874553923373100791477e-13"), + boost::lexical_cast<T>("0.799780678476644196901221989475355609743387528732994566453160178199295104357319723742820593e-15"), + boost::lexical_cast<T>("-0.100148627870893347527249092785257443532967736956154251497569191947184705954310833302770086e-16"), + boost::lexical_cast<T>("0.947100256812658897084619699699028861352615460106539259289295071616221848196411749449858071e-19"), + boost::lexical_cast<T>("-0.657808193528898116367845405906343884364280888644748907819280236995018351085371701094007759e-21"), + boost::lexical_cast<T>("0.324554050057463845012469010247790763753999056976705084126950591088538742509983426730851614e-23"), + boost::lexical_cast<T>("-0.10927068902162908990029309141242256163212535730975970310918370355165185052827948996110107e-25"), + boost::lexical_cast<T>("0.239012340507870646690121104637467232366271566488184795459093215303237974655782634371712486e-28"), + boost::lexical_cast<T>("-0.31958700972990573259359660326375143524864710953063781494908314884519046349402409667329667e-31"), + boost::lexical_cast<T>("0.241905641292988284384362036555782113275737930713192053073501265726048089991747342247551645e-34"), + boost::lexical_cast<T>("-0.93894080230619233745797029179332447129464915420290457418429337322820997038069119047864035e-38"), + boost::lexical_cast<T>("0.164023814025085488413251990798690797467351995518990067783355251949198292596815470576539877e-41"), + boost::lexical_cast<T>("-0.108010831192689925518484618970761942019888832176355541674171850211917230280206410356465451e-45"), + boost::lexical_cast<T>("0.208831600642796805563854019033577205240227465154130766898180386564934443551840379116390645e-50"), + boost::lexical_cast<T>("-0.819516067465171848863933747691434138146789031214932473898084756489529673230665363014007306e-56"), + boost::lexical_cast<T>("0.365344970579318347488211604761724311582675708113250505307342682118101409913523622073678179e-62"), + boost::lexical_cast<T>("-0.684593199208628857931267904308244537968349564351534581234005234847904343404822808648361291e-70"), + }; + T result = 0; + T z = dz + 2; + for(unsigned k = 1; k <= sizeof(d)/sizeof(d[0]); ++k) + { + result += (-d[k-1]*dz)/(z + k*z + k*k - 1); + } + return result; + } + + static double g(){ return 63.19215200000000010049916454590857028961181640625; } +}; + +}}} // namespaces + +#endif + + diff --git a/Utilities/BGL/boost/math/bindings/mpfr.hpp b/Utilities/BGL/boost/math/bindings/mpfr.hpp new file mode 100644 index 0000000000000000000000000000000000000000..16743ed5c67c86be6cef7cd2abf0f3080b57cb36 --- /dev/null +++ b/Utilities/BGL/boost/math/bindings/mpfr.hpp @@ -0,0 +1,850 @@ +// Copyright John Maddock 2008. +// Use, modification and distribution are subject to 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) +// +// Wrapper that works with mpfr_class defined in gmpfrxx.h +// See http://math.berkeley.edu/~wilken/code/gmpfrxx/ +// Also requires the gmp and mpfr libraries. +// + +#ifndef BOOST_MATH_MPLFR_BINDINGS_HPP +#define BOOST_MATH_MPLFR_BINDINGS_HPP + +#include <gmpfrxx.h> +#include <boost/math/tools/precision.hpp> +#include <boost/math/tools/real_cast.hpp> +#include <boost/math/policies/policy.hpp> +#include <boost/math/distributions/fwd.hpp> +#include <boost/math/special_functions/math_fwd.hpp> +#include <boost/math/bindings/detail/big_digamma.hpp> +#include <boost/math/bindings/detail/big_lanczos.hpp> + +inline mpfr_class fabs(const mpfr_class& v) +{ + return abs(v); +} + +inline mpfr_class pow(const mpfr_class& b, const mpfr_class e) +{ + mpfr_class result; + mpfr_pow(result.__get_mp(), b.__get_mp(), e.__get_mp(), GMP_RNDN); + return result; +} + +inline mpfr_class ldexp(const mpfr_class& v, int e) +{ + //int e = mpfr_get_exp(*v.__get_mp()); + mpfr_class result(v); + mpfr_set_exp(result.__get_mp(), e); + return result; +} + +inline mpfr_class frexp(const mpfr_class& v, int* expon) +{ + int e = mpfr_get_exp(v.__get_mp()); + mpfr_class result(v); + mpfr_set_exp(result.__get_mp(), 0); + *expon = e; + return result; +} + +mpfr_class fmod(const mpfr_class& v1, const mpfr_class& v2) +{ + mpfr_class n; + if(v1 < 0) + n = ceil(v1 / v2); + else + n = floor(v1 / v2); + return v1 - n * v2; +} + +template <class Policy> +inline mpfr_class modf(const mpfr_class& v, long long* ipart, const Policy& pol) +{ + *ipart = lltrunc(v, pol); + return v - boost::math::tools::real_cast<mpfr_class>(*ipart); +} +template <class Policy> +inline int iround(mpfr_class const& x, const Policy& pol) +{ + return boost::math::tools::real_cast<int>(boost::math::round(x, pol)); +} + +template <class Policy> +inline long lround(mpfr_class const& x, const Policy& pol) +{ + return boost::math::tools::real_cast<long>(boost::math::round(x, pol)); +} + +template <class Policy> +inline long long llround(mpfr_class const& x, const Policy& pol) +{ + return boost::math::tools::real_cast<long long>(boost::math::round(x, pol)); +} + +template <class Policy> +inline int itrunc(mpfr_class const& x, const Policy& pol) +{ + return boost::math::tools::real_cast<int>(boost::math::trunc(x, pol)); +} + +template <class Policy> +inline long ltrunc(mpfr_class const& x, const Policy& pol) +{ + return boost::math::tools::real_cast<long>(boost::math::trunc(x, pol)); +} + +template <class Policy> +inline long long lltrunc(mpfr_class const& x, const Policy& pol) +{ + return boost::math::tools::real_cast<long long>(boost::math::trunc(x, pol)); +} + +namespace boost{ namespace math{ + +#if defined(__GNUC__) && (__GNUC__ < 4) + using ::iround; + using ::lround; + using ::llround; + using ::itrunc; + using ::ltrunc; + using ::lltrunc; + using ::modf; +#endif + +namespace lanczos{ + +struct mpfr_lanczos +{ + static mpfr_class lanczos_sum(const mpfr_class& z) + { + unsigned long p = z.get_dprec(); + if(p <= 72) + return lanczos13UDT::lanczos_sum(z); + else if(p <= 120) + return lanczos22UDT::lanczos_sum(z); + else if(p <= 170) + return lanczos31UDT::lanczos_sum(z); + else //if(p <= 370) approx 100 digit precision: + return lanczos61UDT::lanczos_sum(z); + } + static mpfr_class lanczos_sum_expG_scaled(const mpfr_class& z) + { + unsigned long p = z.get_dprec(); + if(p <= 72) + return lanczos13UDT::lanczos_sum_expG_scaled(z); + else if(p <= 120) + return lanczos22UDT::lanczos_sum_expG_scaled(z); + else if(p <= 170) + return lanczos31UDT::lanczos_sum_expG_scaled(z); + else //if(p <= 370) approx 100 digit precision: + return lanczos61UDT::lanczos_sum_expG_scaled(z); + } + static mpfr_class lanczos_sum_near_1(const mpfr_class& z) + { + unsigned long p = z.get_dprec(); + if(p <= 72) + return lanczos13UDT::lanczos_sum_near_1(z); + else if(p <= 120) + return lanczos22UDT::lanczos_sum_near_1(z); + else if(p <= 170) + return lanczos31UDT::lanczos_sum_near_1(z); + else //if(p <= 370) approx 100 digit precision: + return lanczos61UDT::lanczos_sum_near_1(z); + } + static mpfr_class lanczos_sum_near_2(const mpfr_class& z) + { + unsigned long p = z.get_dprec(); + if(p <= 72) + return lanczos13UDT::lanczos_sum_near_2(z); + else if(p <= 120) + return lanczos22UDT::lanczos_sum_near_2(z); + else if(p <= 170) + return lanczos31UDT::lanczos_sum_near_2(z); + else //if(p <= 370) approx 100 digit precision: + return lanczos61UDT::lanczos_sum_near_2(z); + } + static mpfr_class g() + { + unsigned long p = mpfr_class::get_dprec(); + if(p <= 72) + return lanczos13UDT::g(); + else if(p <= 120) + return lanczos22UDT::g(); + else if(p <= 170) + return lanczos31UDT::g(); + else //if(p <= 370) approx 100 digit precision: + return lanczos61UDT::g(); + } +}; + +template<class Policy> +struct lanczos<mpfr_class, Policy> +{ + typedef mpfr_lanczos type; +}; + +} // namespace lanczos + +namespace tools +{ + +template <class T, class U> +struct promote_arg<__gmp_expr<T,U> > +{ // If T is integral type, then promote to double. + typedef mpfr_class type; +}; + +template<> +inline int digits<mpfr_class>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(mpfr_class)) +{ + return mpfr_class::get_dprec(); +} + +namespace detail{ + +template<class I> +void convert_to_long_result(mpfr_class const& r, I& result) +{ + result = 0; + I last_result(0); + mpfr_class t(r); + double term; + do + { + term = real_cast<double>(t); + last_result = result; + result += static_cast<I>(term); + t -= term; + }while(result != last_result); +} + +} + +template <> +inline mpfr_class real_cast<mpfr_class, long long>(long long t) +{ + mpfr_class result; + int expon = 0; + int sign = 1; + if(t < 0) + { + sign = -1; + t = -t; + } + while(t) + { + result += ldexp((double)(t & 0xffffL), expon); + expon += 32; + t >>= 32; + } + return result * sign; +} +template <> +inline unsigned real_cast<unsigned, mpfr_class>(mpfr_class t) +{ + return t.get_ui(); +} +template <> +inline int real_cast<int, mpfr_class>(mpfr_class t) +{ + return t.get_si(); +} +template <> +inline double real_cast<double, mpfr_class>(mpfr_class t) +{ + return t.get_d(); +} +template <> +inline float real_cast<float, mpfr_class>(mpfr_class t) +{ + return static_cast<float>(t.get_d()); +} +template <> +inline long real_cast<long, mpfr_class>(mpfr_class t) +{ + long result; + detail::convert_to_long_result(t, result); + return result; +} +template <> +inline long long real_cast<long long, mpfr_class>(mpfr_class t) +{ + long long result; + detail::convert_to_long_result(t, result); + return result; +} + +template <> +inline mpfr_class max_value<mpfr_class>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(mpfr_class)) +{ + static bool has_init = false; + static mpfr_class val; + if(!has_init) + { + val = 0.5; + mpfr_set_exp(val.__get_mp(), mpfr_get_emax()); + has_init = true; + } + return val; +} + +template <> +inline mpfr_class min_value<mpfr_class>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(mpfr_class)) +{ + static bool has_init = false; + static mpfr_class val; + if(!has_init) + { + val = 0.5; + mpfr_set_exp(val.__get_mp(), mpfr_get_emin()); + has_init = true; + } + return val; +} + +template <> +inline mpfr_class log_max_value<mpfr_class>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(mpfr_class)) +{ + static bool has_init = false; + static mpfr_class val = max_value<mpfr_class>(); + if(!has_init) + { + val = log(val); + has_init = true; + } + return val; +} + +template <> +inline mpfr_class log_min_value<mpfr_class>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(mpfr_class)) +{ + static bool has_init = false; + static mpfr_class val = max_value<mpfr_class>(); + if(!has_init) + { + val = log(val); + has_init = true; + } + return val; +} + +template <> +inline mpfr_class epsilon<mpfr_class>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(mpfr_class)) +{ + return ldexp(mpfr_class(1), 1-boost::math::policies::digits<mpfr_class, boost::math::policies::policy<> >()); +} + +} // namespace tools + +namespace policies{ + +template <class T, class U, class Policy> +struct evaluation<__gmp_expr<T, U>, Policy> +{ + typedef mpfr_class type; +}; + +} + +template <class Policy> +inline mpfr_class skewness(const extreme_value_distribution<mpfr_class, Policy>& /*dist*/) +{ + // + // This is 12 * sqrt(6) * zeta(3) / pi^3: + // See http://mathworld.wolfram.com/ExtremeValueDistribution.html + // + return boost::lexical_cast<mpfr_class>("1.1395470994046486574927930193898461120875997958366"); +} + +template <class Policy> +inline mpfr_class skewness(const rayleigh_distribution<mpfr_class, Policy>& /*dist*/) +{ + // using namespace boost::math::constants; + return boost::lexical_cast<mpfr_class>("0.63111065781893713819189935154422777984404221106391"); + // Computed using NTL at 150 bit, about 50 decimal digits. + // return 2 * root_pi<RealType>() * pi_minus_three<RealType>() / pow23_four_minus_pi<RealType>(); +} + +template <class Policy> +inline mpfr_class kurtosis(const rayleigh_distribution<mpfr_class, Policy>& /*dist*/) +{ + // using namespace boost::math::constants; + return boost::lexical_cast<mpfr_class>("3.2450893006876380628486604106197544154170667057995"); + // Computed using NTL at 150 bit, about 50 decimal digits. + // return 3 - (6 * pi<RealType>() * pi<RealType>() - 24 * pi<RealType>() + 16) / + // (four_minus_pi<RealType>() * four_minus_pi<RealType>()); +} + +template <class Policy> +inline mpfr_class kurtosis_excess(const rayleigh_distribution<mpfr_class, Policy>& /*dist*/) +{ + //using namespace boost::math::constants; + // Computed using NTL at 150 bit, about 50 decimal digits. + return boost::lexical_cast<mpfr_class>("0.2450893006876380628486604106197544154170667057995"); + // return -(6 * pi<RealType>() * pi<RealType>() - 24 * pi<RealType>() + 16) / + // (four_minus_pi<RealType>() * four_minus_pi<RealType>()); +} // kurtosis + +namespace detail{ + +// +// Version of Digamma accurate to ~100 decimal digits. +// +template <class Policy> +mpfr_class digamma_imp(mpfr_class x, const mpl::int_<0>* , const Policy& pol) +{ + // + // This handles reflection of negative arguments, and all our + // empfr_classor handling, then forwards to the T-specific approximation. + // + BOOST_MATH_STD_USING // ADL of std functions. + + mpfr_class result = 0; + // + // Check for negative arguments and use reflection: + // + if(x < 0) + { + // Reflect: + x = 1 - x; + // Argument reduction for tan: + mpfr_class remainder = x - floor(x); + // Shift to negative if > 0.5: + if(remainder > 0.5) + { + remainder -= 1; + } + // + // check for evaluation at a negative pole: + // + if(remainder == 0) + { + return policies::raise_pole_error<mpfr_class>("boost::math::digamma<%1%>(%1%)", 0, (1-x), pol); + } + result = constants::pi<mpfr_class>() / tan(constants::pi<mpfr_class>() * remainder); + } + result += big_digamma(x); + return result; +} +// +// Specialisations of this function provides the initial +// starting guess for Halley iteration: +// +template <class Policy> +mpfr_class erf_inv_imp(const mpfr_class& p, const mpfr_class& q, const Policy&, const boost::mpl::int_<64>*) +{ + BOOST_MATH_STD_USING // for ADL of std names. + + mpfr_class result = 0; + + if(p <= 0.5) + { + // + // Evaluate inverse erf using the rational approximation: + // + // x = p(p+10)(Y+R(p)) + // + // Where Y is a constant, and R(p) is optimised for a low + // absolute empfr_classor compared to |Y|. + // + // double: Max empfr_classor found: 2.001849e-18 + // long double: Max empfr_classor found: 1.017064e-20 + // Maximum Deviation Found (actual empfr_classor term at infinite precision) 8.030e-21 + // + static const float Y = 0.0891314744949340820313f; + static const mpfr_class P[] = { + -0.000508781949658280665617, + -0.00836874819741736770379, + 0.0334806625409744615033, + -0.0126926147662974029034, + -0.0365637971411762664006, + 0.0219878681111168899165, + 0.00822687874676915743155, + -0.00538772965071242932965 + }; + static const mpfr_class Q[] = { + 1, + -0.970005043303290640362, + -1.56574558234175846809, + 1.56221558398423026363, + 0.662328840472002992063, + -0.71228902341542847553, + -0.0527396382340099713954, + 0.0795283687341571680018, + -0.00233393759374190016776, + 0.000886216390456424707504 + }; + mpfr_class g = p * (p + 10); + mpfr_class r = tools::evaluate_polynomial(P, p) / tools::evaluate_polynomial(Q, p); + result = g * Y + g * r; + } + else if(q >= 0.25) + { + // + // Rational approximation for 0.5 > q >= 0.25 + // + // x = sqrt(-2*log(q)) / (Y + R(q)) + // + // Where Y is a constant, and R(q) is optimised for a low + // absolute empfr_classor compared to Y. + // + // double : Max empfr_classor found: 7.403372e-17 + // long double : Max empfr_classor found: 6.084616e-20 + // Maximum Deviation Found (empfr_classor term) 4.811e-20 + // + static const float Y = 2.249481201171875f; + static const mpfr_class P[] = { + -0.202433508355938759655, + 0.105264680699391713268, + 8.37050328343119927838, + 17.6447298408374015486, + -18.8510648058714251895, + -44.6382324441786960818, + 17.445385985570866523, + 21.1294655448340526258, + -3.67192254707729348546 + }; + static const mpfr_class Q[] = { + 1, + 6.24264124854247537712, + 3.9713437953343869095, + -28.6608180499800029974, + -20.1432634680485188801, + 48.5609213108739935468, + 10.8268667355460159008, + -22.6436933413139721736, + 1.72114765761200282724 + }; + mpfr_class g = sqrt(-2 * log(q)); + mpfr_class xs = q - 0.25; + mpfr_class r = tools::evaluate_polynomial(P, xs) / tools::evaluate_polynomial(Q, xs); + result = g / (Y + r); + } + else + { + // + // For q < 0.25 we have a series of rational approximations all + // of the general form: + // + // let: x = sqrt(-log(q)) + // + // Then the result is given by: + // + // x(Y+R(x-B)) + // + // where Y is a constant, B is the lowest value of x for which + // the approximation is valid, and R(x-B) is optimised for a low + // absolute empfr_classor compared to Y. + // + // Note that almost all code will really go through the first + // or maybe second approximation. After than we're dealing with very + // small input values indeed: 80 and 128 bit long double's go all the + // way down to ~ 1e-5000 so the "tail" is rather long... + // + mpfr_class x = sqrt(-log(q)); + if(x < 3) + { + // Max empfr_classor found: 1.089051e-20 + static const float Y = 0.807220458984375f; + static const mpfr_class P[] = { + -0.131102781679951906451, + -0.163794047193317060787, + 0.117030156341995252019, + 0.387079738972604337464, + 0.337785538912035898924, + 0.142869534408157156766, + 0.0290157910005329060432, + 0.00214558995388805277169, + -0.679465575181126350155e-6, + 0.285225331782217055858e-7, + -0.681149956853776992068e-9 + }; + static const mpfr_class Q[] = { + 1, + 3.46625407242567245975, + 5.38168345707006855425, + 4.77846592945843778382, + 2.59301921623620271374, + 0.848854343457902036425, + 0.152264338295331783612, + 0.01105924229346489121 + }; + mpfr_class xs = x - 1.125; + mpfr_class R = tools::evaluate_polynomial(P, xs) / tools::evaluate_polynomial(Q, xs); + result = Y * x + R * x; + } + else if(x < 6) + { + // Max empfr_classor found: 8.389174e-21 + static const float Y = 0.93995571136474609375f; + static const mpfr_class P[] = { + -0.0350353787183177984712, + -0.00222426529213447927281, + 0.0185573306514231072324, + 0.00950804701325919603619, + 0.00187123492819559223345, + 0.000157544617424960554631, + 0.460469890584317994083e-5, + -0.230404776911882601748e-9, + 0.266339227425782031962e-11 + }; + static const mpfr_class Q[] = { + 1, + 1.3653349817554063097, + 0.762059164553623404043, + 0.220091105764131249824, + 0.0341589143670947727934, + 0.00263861676657015992959, + 0.764675292302794483503e-4 + }; + mpfr_class xs = x - 3; + mpfr_class R = tools::evaluate_polynomial(P, xs) / tools::evaluate_polynomial(Q, xs); + result = Y * x + R * x; + } + else if(x < 18) + { + // Max empfr_classor found: 1.481312e-19 + static const float Y = 0.98362827301025390625f; + static const mpfr_class P[] = { + -0.0167431005076633737133, + -0.00112951438745580278863, + 0.00105628862152492910091, + 0.000209386317487588078668, + 0.149624783758342370182e-4, + 0.449696789927706453732e-6, + 0.462596163522878599135e-8, + -0.281128735628831791805e-13, + 0.99055709973310326855e-16 + }; + static const mpfr_class Q[] = { + 1, + 0.591429344886417493481, + 0.138151865749083321638, + 0.0160746087093676504695, + 0.000964011807005165528527, + 0.275335474764726041141e-4, + 0.282243172016108031869e-6 + }; + mpfr_class xs = x - 6; + mpfr_class R = tools::evaluate_polynomial(P, xs) / tools::evaluate_polynomial(Q, xs); + result = Y * x + R * x; + } + else if(x < 44) + { + // Max empfr_classor found: 5.697761e-20 + static const float Y = 0.99714565277099609375f; + static const mpfr_class P[] = { + -0.0024978212791898131227, + -0.779190719229053954292e-5, + 0.254723037413027451751e-4, + 0.162397777342510920873e-5, + 0.396341011304801168516e-7, + 0.411632831190944208473e-9, + 0.145596286718675035587e-11, + -0.116765012397184275695e-17 + }; + static const mpfr_class Q[] = { + 1, + 0.207123112214422517181, + 0.0169410838120975906478, + 0.000690538265622684595676, + 0.145007359818232637924e-4, + 0.144437756628144157666e-6, + 0.509761276599778486139e-9 + }; + mpfr_class xs = x - 18; + mpfr_class R = tools::evaluate_polynomial(P, xs) / tools::evaluate_polynomial(Q, xs); + result = Y * x + R * x; + } + else + { + // Max empfr_classor found: 1.279746e-20 + static const float Y = 0.99941349029541015625f; + static const mpfr_class P[] = { + -0.000539042911019078575891, + -0.28398759004727721098e-6, + 0.899465114892291446442e-6, + 0.229345859265920864296e-7, + 0.225561444863500149219e-9, + 0.947846627503022684216e-12, + 0.135880130108924861008e-14, + -0.348890393399948882918e-21 + }; + static const mpfr_class Q[] = { + 1, + 0.0845746234001899436914, + 0.00282092984726264681981, + 0.468292921940894236786e-4, + 0.399968812193862100054e-6, + 0.161809290887904476097e-8, + 0.231558608310259605225e-11 + }; + mpfr_class xs = x - 44; + mpfr_class R = tools::evaluate_polynomial(P, xs) / tools::evaluate_polynomial(Q, xs); + result = Y * x + R * x; + } + } + return result; +} + +mpfr_class bessel_i0(mpfr_class x) +{ + static const mpfr_class P1[] = { + boost::lexical_cast<mpfr_class>("-2.2335582639474375249e+15"), + boost::lexical_cast<mpfr_class>("-5.5050369673018427753e+14"), + boost::lexical_cast<mpfr_class>("-3.2940087627407749166e+13"), + boost::lexical_cast<mpfr_class>("-8.4925101247114157499e+11"), + boost::lexical_cast<mpfr_class>("-1.1912746104985237192e+10"), + boost::lexical_cast<mpfr_class>("-1.0313066708737980747e+08"), + boost::lexical_cast<mpfr_class>("-5.9545626019847898221e+05"), + boost::lexical_cast<mpfr_class>("-2.4125195876041896775e+03"), + boost::lexical_cast<mpfr_class>("-7.0935347449210549190e+00"), + boost::lexical_cast<mpfr_class>("-1.5453977791786851041e-02"), + boost::lexical_cast<mpfr_class>("-2.5172644670688975051e-05"), + boost::lexical_cast<mpfr_class>("-3.0517226450451067446e-08"), + boost::lexical_cast<mpfr_class>("-2.6843448573468483278e-11"), + boost::lexical_cast<mpfr_class>("-1.5982226675653184646e-14"), + boost::lexical_cast<mpfr_class>("-5.2487866627945699800e-18"), + }; + static const mpfr_class Q1[] = { + boost::lexical_cast<mpfr_class>("-2.2335582639474375245e+15"), + boost::lexical_cast<mpfr_class>("7.8858692566751002988e+12"), + boost::lexical_cast<mpfr_class>("-1.2207067397808979846e+10"), + boost::lexical_cast<mpfr_class>("1.0377081058062166144e+07"), + boost::lexical_cast<mpfr_class>("-4.8527560179962773045e+03"), + boost::lexical_cast<mpfr_class>("1.0"), + }; + static const mpfr_class P2[] = { + boost::lexical_cast<mpfr_class>("-2.2210262233306573296e-04"), + boost::lexical_cast<mpfr_class>("1.3067392038106924055e-02"), + boost::lexical_cast<mpfr_class>("-4.4700805721174453923e-01"), + boost::lexical_cast<mpfr_class>("5.5674518371240761397e+00"), + boost::lexical_cast<mpfr_class>("-2.3517945679239481621e+01"), + boost::lexical_cast<mpfr_class>("3.1611322818701131207e+01"), + boost::lexical_cast<mpfr_class>("-9.6090021968656180000e+00"), + }; + static const mpfr_class Q2[] = { + boost::lexical_cast<mpfr_class>("-5.5194330231005480228e-04"), + boost::lexical_cast<mpfr_class>("3.2547697594819615062e-02"), + boost::lexical_cast<mpfr_class>("-1.1151759188741312645e+00"), + boost::lexical_cast<mpfr_class>("1.3982595353892851542e+01"), + boost::lexical_cast<mpfr_class>("-6.0228002066743340583e+01"), + boost::lexical_cast<mpfr_class>("8.5539563258012929600e+01"), + boost::lexical_cast<mpfr_class>("-3.1446690275135491500e+01"), + boost::lexical_cast<mpfr_class>("1.0"), + }; + mpfr_class value, factor, r; + + BOOST_MATH_STD_USING + using namespace boost::math::tools; + + if (x < 0) + { + x = -x; // even function + } + if (x == 0) + { + return static_cast<mpfr_class>(1); + } + if (x <= 15) // x in (0, 15] + { + mpfr_class y = x * x; + value = evaluate_polynomial(P1, y) / evaluate_polynomial(Q1, y); + } + else // x in (15, \infty) + { + mpfr_class y = 1 / x - 1 / 15; + r = evaluate_polynomial(P2, y) / evaluate_polynomial(Q2, y); + factor = exp(x) / sqrt(x); + value = factor * r; + } + + return value; +} + +mpfr_class bessel_i1(mpfr_class x) +{ + static const mpfr_class P1[] = { + static_cast<mpfr_class>("-1.4577180278143463643e+15"), + static_cast<mpfr_class>("-1.7732037840791591320e+14"), + static_cast<mpfr_class>("-6.9876779648010090070e+12"), + static_cast<mpfr_class>("-1.3357437682275493024e+11"), + static_cast<mpfr_class>("-1.4828267606612366099e+09"), + static_cast<mpfr_class>("-1.0588550724769347106e+07"), + static_cast<mpfr_class>("-5.1894091982308017540e+04"), + static_cast<mpfr_class>("-1.8225946631657315931e+02"), + static_cast<mpfr_class>("-4.7207090827310162436e-01"), + static_cast<mpfr_class>("-9.1746443287817501309e-04"), + static_cast<mpfr_class>("-1.3466829827635152875e-06"), + static_cast<mpfr_class>("-1.4831904935994647675e-09"), + static_cast<mpfr_class>("-1.1928788903603238754e-12"), + static_cast<mpfr_class>("-6.5245515583151902910e-16"), + static_cast<mpfr_class>("-1.9705291802535139930e-19"), + }; + static const mpfr_class Q1[] = { + static_cast<mpfr_class>("-2.9154360556286927285e+15"), + static_cast<mpfr_class>("9.7887501377547640438e+12"), + static_cast<mpfr_class>("-1.4386907088588283434e+10"), + static_cast<mpfr_class>("1.1594225856856884006e+07"), + static_cast<mpfr_class>("-5.1326864679904189920e+03"), + static_cast<mpfr_class>("1.0"), + }; + static const mpfr_class P2[] = { + static_cast<mpfr_class>("1.4582087408985668208e-05"), + static_cast<mpfr_class>("-8.9359825138577646443e-04"), + static_cast<mpfr_class>("2.9204895411257790122e-02"), + static_cast<mpfr_class>("-3.4198728018058047439e-01"), + static_cast<mpfr_class>("1.3960118277609544334e+00"), + static_cast<mpfr_class>("-1.9746376087200685843e+00"), + static_cast<mpfr_class>("8.5591872901933459000e-01"), + static_cast<mpfr_class>("-6.0437159056137599999e-02"), + }; + static const mpfr_class Q2[] = { + static_cast<mpfr_class>("3.7510433111922824643e-05"), + static_cast<mpfr_class>("-2.2835624489492512649e-03"), + static_cast<mpfr_class>("7.4212010813186530069e-02"), + static_cast<mpfr_class>("-8.5017476463217924408e-01"), + static_cast<mpfr_class>("3.2593714889036996297e+00"), + static_cast<mpfr_class>("-3.8806586721556593450e+00"), + static_cast<mpfr_class>("1.0"), + }; + mpfr_class value, factor, r, w; + + BOOST_MATH_STD_USING + using namespace boost::math::tools; + + w = abs(x); + if (x == 0) + { + return static_cast<mpfr_class>(0); + } + if (w <= 15) // w in (0, 15] + { + mpfr_class y = x * x; + r = evaluate_polynomial(P1, y) / evaluate_polynomial(Q1, y); + factor = w; + value = factor * r; + } + else // w in (15, \infty) + { + mpfr_class y = 1 / w - mpfr_class(1) / 15; + r = evaluate_polynomial(P2, y) / evaluate_polynomial(Q2, y); + factor = exp(w) / sqrt(w); + value = factor * r; + } + + if (x < 0) + { + value *= -value; // odd function + } + return value; +} + +} // namespace detail + +}} + +#endif // BOOST_MATH_MPLFR_BINDINGS_HPP + diff --git a/Utilities/BGL/boost/math/bindings/rr.hpp b/Utilities/BGL/boost/math/bindings/rr.hpp new file mode 100644 index 0000000000000000000000000000000000000000..31fefc444ab0df94e498ea91e7547eccabb15be0 --- /dev/null +++ b/Utilities/BGL/boost/math/bindings/rr.hpp @@ -0,0 +1,873 @@ +// Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_NTL_RR_HPP +#define BOOST_MATH_NTL_RR_HPP + +#include <boost/config.hpp> +#include <boost/limits.hpp> +#include <boost/math/tools/real_cast.hpp> +#include <boost/math/tools/precision.hpp> +#include <boost/math/constants/constants.hpp> +#include <boost/math/tools/roots.hpp> +#include <boost/math/special_functions/fpclassify.hpp> +#include <boost/math/bindings/detail/big_digamma.hpp> +#include <boost/math/bindings/detail/big_lanczos.hpp> + +#include <ostream> +#include <istream> +#include <boost/config/no_tr1/cmath.hpp> +#include <NTL/RR.h> + +namespace boost{ namespace math{ + +namespace ntl +{ + +class RR; + +RR ldexp(RR r, int exp); +RR frexp(RR r, int* exp); + +class RR +{ +public: + // Constructors: + RR() {} + RR(const ::NTL::RR& c) : m_value(c){} + RR(char c) + { + m_value = c; + } +#ifndef BOOST_NO_INTRINSIC_WCHAR_T + RR(wchar_t c) + { + m_value = c; + } +#endif + RR(unsigned char c) + { + m_value = c; + } + RR(signed char c) + { + m_value = c; + } + RR(unsigned short c) + { + m_value = c; + } + RR(short c) + { + m_value = c; + } + RR(unsigned int c) + { + assign_large_int(c); + } + RR(int c) + { + assign_large_int(c); + } + RR(unsigned long c) + { + assign_large_int(c); + } + RR(long c) + { + assign_large_int(c); + } +#ifdef BOOST_HAS_LONG_LONG + RR(boost::ulong_long_type c) + { + assign_large_int(c); + } + RR(boost::long_long_type c) + { + assign_large_int(c); + } +#endif + RR(float c) + { + m_value = c; + } + RR(double c) + { + m_value = c; + } + RR(long double c) + { + assign_large_real(c); + } + + // Assignment: + RR& operator=(char c) { m_value = c; return *this; } + RR& operator=(unsigned char c) { m_value = c; return *this; } + RR& operator=(signed char c) { m_value = c; return *this; } +#ifndef BOOST_NO_INTRINSIC_WCHAR_T + RR& operator=(wchar_t c) { m_value = c; return *this; } +#endif + RR& operator=(short c) { m_value = c; return *this; } + RR& operator=(unsigned short c) { m_value = c; return *this; } + RR& operator=(int c) { assign_large_int(c); return *this; } + RR& operator=(unsigned int c) { assign_large_int(c); return *this; } + RR& operator=(long c) { assign_large_int(c); return *this; } + RR& operator=(unsigned long c) { assign_large_int(c); return *this; } +#ifdef BOOST_HAS_LONG_LONG + RR& operator=(boost::long_long_type c) { assign_large_int(c); return *this; } + RR& operator=(boost::ulong_long_type c) { assign_large_int(c); return *this; } +#endif + RR& operator=(float c) { m_value = c; return *this; } + RR& operator=(double c) { m_value = c; return *this; } + RR& operator=(long double c) { assign_large_real(c); return *this; } + + // Access: + NTL::RR& value(){ return m_value; } + NTL::RR const& value()const{ return m_value; } + + // Member arithmetic: + RR& operator+=(const RR& other) + { m_value += other.value(); return *this; } + RR& operator-=(const RR& other) + { m_value -= other.value(); return *this; } + RR& operator*=(const RR& other) + { m_value *= other.value(); return *this; } + RR& operator/=(const RR& other) + { m_value /= other.value(); return *this; } + RR operator-()const + { return -m_value; } + RR const& operator+()const + { return *this; } + + // RR compatibity: + const ::NTL::ZZ& mantissa() const + { return m_value.mantissa(); } + long exponent() const + { return m_value.exponent(); } + + static void SetPrecision(long p) + { ::NTL::RR::SetPrecision(p); } + + static long precision() + { return ::NTL::RR::precision(); } + + static void SetOutputPrecision(long p) + { ::NTL::RR::SetOutputPrecision(p); } + static long OutputPrecision() + { return ::NTL::RR::OutputPrecision(); } + + +private: + ::NTL::RR m_value; + + template <class V> + void assign_large_real(const V& a) + { + using std::frexp; + using std::ldexp; + using std::floor; + if (a == 0) { + clear(m_value); + return; + } + + if (a == 1) { + NTL::set(m_value); + return; + } + + if (!(boost::math::isfinite)(a)) + { + throw std::overflow_error("Cannot construct an instance of NTL::RR with an infinite value."); + } + + int e; + long double f, term; + ::NTL::RR t; + clear(m_value); + + f = frexp(a, &e); + + while(f) + { + // extract 30 bits from f: + f = ldexp(f, 30); + term = floor(f); + e -= 30; + conv(t.x, (int)term); + t.e = e; + m_value += t; + f -= term; + } + } + + template <class V> + void assign_large_int(V a) + { +#ifdef BOOST_MSVC +#pragma warning(push) +#pragma warning(disable:4146) +#endif + clear(m_value); + int exp = 0; + NTL::RR t; + bool neg = a < V(0) ? true : false; + if(neg) + a = -a; + while(a) + { + t = static_cast<double>(a & 0xffff); + m_value += ldexp(RR(t), exp).value(); + a >>= 16; + exp += 16; + } + if(neg) + m_value = -m_value; +#ifdef BOOST_MSVC +#pragma warning(pop) +#endif + } +}; + +// Non-member arithmetic: +inline RR operator+(const RR& a, const RR& b) +{ + RR result(a); + result += b; + return result; +} +inline RR operator-(const RR& a, const RR& b) +{ + RR result(a); + result -= b; + return result; +} +inline RR operator*(const RR& a, const RR& b) +{ + RR result(a); + result *= b; + return result; +} +inline RR operator/(const RR& a, const RR& b) +{ + RR result(a); + result /= b; + return result; +} + +// Comparison: +inline bool operator == (const RR& a, const RR& b) +{ return a.value() == b.value() ? true : false; } +inline bool operator != (const RR& a, const RR& b) +{ return a.value() != b.value() ? true : false;} +inline bool operator < (const RR& a, const RR& b) +{ return a.value() < b.value() ? true : false; } +inline bool operator <= (const RR& a, const RR& b) +{ return a.value() <= b.value() ? true : false; } +inline bool operator > (const RR& a, const RR& b) +{ return a.value() > b.value() ? true : false; } +inline bool operator >= (const RR& a, const RR& b) +{ return a.value() >= b.value() ? true : false; } + +#if 0 +// Non-member mixed compare: +template <class T> +inline bool operator == (const T& a, const RR& b) +{ + return a == b.value(); +} +template <class T> +inline bool operator != (const T& a, const RR& b) +{ + return a != b.value(); +} +template <class T> +inline bool operator < (const T& a, const RR& b) +{ + return a < b.value(); +} +template <class T> +inline bool operator > (const T& a, const RR& b) +{ + return a > b.value(); +} +template <class T> +inline bool operator <= (const T& a, const RR& b) +{ + return a <= b.value(); +} +template <class T> +inline bool operator >= (const T& a, const RR& b) +{ + return a >= b.value(); +} +#endif // Non-member mixed compare: + +// Non-member functions: +/* +inline RR acos(RR a) +{ return ::NTL::acos(a.value()); } +*/ +inline RR cos(RR a) +{ return ::NTL::cos(a.value()); } +/* +inline RR asin(RR a) +{ return ::NTL::asin(a.value()); } +inline RR atan(RR a) +{ return ::NTL::atan(a.value()); } +inline RR atan2(RR a, RR b) +{ return ::NTL::atan2(a.value(), b.value()); } +*/ +inline RR ceil(RR a) +{ return ::NTL::ceil(a.value()); } +/* +inline RR fmod(RR a, RR b) +{ return ::NTL::fmod(a.value(), b.value()); } +inline RR cosh(RR a) +{ return ::NTL::cosh(a.value()); } +*/ +inline RR exp(RR a) +{ return ::NTL::exp(a.value()); } +inline RR fabs(RR a) +{ return ::NTL::fabs(a.value()); } +inline RR abs(RR a) +{ return ::NTL::abs(a.value()); } +inline RR floor(RR a) +{ return ::NTL::floor(a.value()); } +/* +inline RR modf(RR a, RR* ipart) +{ + ::NTL::RR ip; + RR result = modf(a.value(), &ip); + *ipart = ip; + return result; +} +inline RR frexp(RR a, int* expon) +{ return ::NTL::frexp(a.value(), expon); } +inline RR ldexp(RR a, int expon) +{ return ::NTL::ldexp(a.value(), expon); } +*/ +inline RR log(RR a) +{ return ::NTL::log(a.value()); } +inline RR log10(RR a) +{ return ::NTL::log10(a.value()); } +/* +inline RR tan(RR a) +{ return ::NTL::tan(a.value()); } +*/ +inline RR pow(RR a, RR b) +{ return ::NTL::pow(a.value(), b.value()); } +inline RR pow(RR a, int b) +{ return ::NTL::power(a.value(), b); } +inline RR sin(RR a) +{ return ::NTL::sin(a.value()); } +/* +inline RR sinh(RR a) +{ return ::NTL::sinh(a.value()); } +*/ +inline RR sqrt(RR a) +{ return ::NTL::sqrt(a.value()); } +/* +inline RR tanh(RR a) +{ return ::NTL::tanh(a.value()); } +*/ + inline RR pow(const RR& r, long l) + { + return ::NTL::power(r.value(), l); + } + inline RR tan(const RR& a) + { + return sin(a)/cos(a); + } + inline RR frexp(RR r, int* exp) + { + *exp = r.value().e; + r.value().e = 0; + while(r >= 1) + { + *exp += 1; + r.value().e -= 1; + } + while(r < 0.5) + { + *exp -= 1; + r.value().e += 1; + } + BOOST_ASSERT(r < 1); + BOOST_ASSERT(r >= 0.5); + return r; + } + inline RR ldexp(RR r, int exp) + { + r.value().e += exp; + return r; + } + +// Streaming: +template <class charT, class traits> +inline std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& os, const RR& a) +{ + return os << a.value(); +} +template <class charT, class traits> +inline std::basic_istream<charT, traits>& operator>>(std::basic_istream<charT, traits>& is, RR& a) +{ + ::NTL::RR v; + is >> v; + a = v; + return is; +} + +} // namespace ntl + +namespace lanczos{ + +struct ntl_lanczos +{ + static ntl::RR lanczos_sum(const ntl::RR& z) + { + unsigned long p = ntl::RR::precision(); + if(p <= 72) + return lanczos13UDT::lanczos_sum(z); + else if(p <= 120) + return lanczos22UDT::lanczos_sum(z); + else if(p <= 170) + return lanczos31UDT::lanczos_sum(z); + else //if(p <= 370) approx 100 digit precision: + return lanczos61UDT::lanczos_sum(z); + } + static ntl::RR lanczos_sum_expG_scaled(const ntl::RR& z) + { + unsigned long p = ntl::RR::precision(); + if(p <= 72) + return lanczos13UDT::lanczos_sum_expG_scaled(z); + else if(p <= 120) + return lanczos22UDT::lanczos_sum_expG_scaled(z); + else if(p <= 170) + return lanczos31UDT::lanczos_sum_expG_scaled(z); + else //if(p <= 370) approx 100 digit precision: + return lanczos61UDT::lanczos_sum_expG_scaled(z); + } + static ntl::RR lanczos_sum_near_1(const ntl::RR& z) + { + unsigned long p = ntl::RR::precision(); + if(p <= 72) + return lanczos13UDT::lanczos_sum_near_1(z); + else if(p <= 120) + return lanczos22UDT::lanczos_sum_near_1(z); + else if(p <= 170) + return lanczos31UDT::lanczos_sum_near_1(z); + else //if(p <= 370) approx 100 digit precision: + return lanczos61UDT::lanczos_sum_near_1(z); + } + static ntl::RR lanczos_sum_near_2(const ntl::RR& z) + { + unsigned long p = ntl::RR::precision(); + if(p <= 72) + return lanczos13UDT::lanczos_sum_near_2(z); + else if(p <= 120) + return lanczos22UDT::lanczos_sum_near_2(z); + else if(p <= 170) + return lanczos31UDT::lanczos_sum_near_2(z); + else //if(p <= 370) approx 100 digit precision: + return lanczos61UDT::lanczos_sum_near_2(z); + } + static ntl::RR g() + { + unsigned long p = ntl::RR::precision(); + if(p <= 72) + return lanczos13UDT::g(); + else if(p <= 120) + return lanczos22UDT::g(); + else if(p <= 170) + return lanczos31UDT::g(); + else //if(p <= 370) approx 100 digit precision: + return lanczos61UDT::g(); + } +}; + +template<class Policy> +struct lanczos<ntl::RR, Policy> +{ + typedef ntl_lanczos type; +}; + +} // namespace lanczos + +namespace tools +{ + +template<> +inline int digits<boost::math::ntl::RR>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(boost::math::ntl::RR)) +{ + return ::NTL::RR::precision(); +} + +template <> +inline float real_cast<float, boost::math::ntl::RR>(boost::math::ntl::RR t) +{ + double r; + conv(r, t.value()); + return static_cast<float>(r); +} +template <> +inline double real_cast<double, boost::math::ntl::RR>(boost::math::ntl::RR t) +{ + double r; + conv(r, t.value()); + return r; +} + +namespace detail{ + +template<class I> +void convert_to_long_result(NTL::RR const& r, I& result) +{ + result = 0; + I last_result(0); + NTL::RR t(r); + double term; + do + { + conv(term, t); + last_result = result; + result += static_cast<I>(term); + t -= term; + }while(result != last_result); +} + +} + +template <> +inline long double real_cast<long double, boost::math::ntl::RR>(boost::math::ntl::RR t) +{ + long double result(0); + detail::convert_to_long_result(t.value(), result); + return result; +} +template <> +inline boost::math::ntl::RR real_cast<boost::math::ntl::RR, boost::math::ntl::RR>(boost::math::ntl::RR t) +{ + return t; +} +template <> +inline unsigned real_cast<unsigned, boost::math::ntl::RR>(boost::math::ntl::RR t) +{ + unsigned result; + detail::convert_to_long_result(t.value(), result); + return result; +} +template <> +inline int real_cast<int, boost::math::ntl::RR>(boost::math::ntl::RR t) +{ + int result; + detail::convert_to_long_result(t.value(), result); + return result; +} +template <> +inline long real_cast<long, boost::math::ntl::RR>(boost::math::ntl::RR t) +{ + long result; + detail::convert_to_long_result(t.value(), result); + return result; +} +template <> +inline long long real_cast<long long, boost::math::ntl::RR>(boost::math::ntl::RR t) +{ + long long result; + detail::convert_to_long_result(t.value(), result); + return result; +} + +template <> +inline boost::math::ntl::RR max_value<boost::math::ntl::RR>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(boost::math::ntl::RR)) +{ + static bool has_init = false; + static NTL::RR val; + if(!has_init) + { + val = 1; + val.e = NTL_OVFBND-20; + has_init = true; + } + return val; +} + +template <> +inline boost::math::ntl::RR min_value<boost::math::ntl::RR>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(boost::math::ntl::RR)) +{ + static bool has_init = false; + static NTL::RR val; + if(!has_init) + { + val = 1; + val.e = -NTL_OVFBND+20; + has_init = true; + } + return val; +} + +template <> +inline boost::math::ntl::RR log_max_value<boost::math::ntl::RR>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(boost::math::ntl::RR)) +{ + static bool has_init = false; + static NTL::RR val; + if(!has_init) + { + val = 1; + val.e = NTL_OVFBND-20; + val = log(val); + has_init = true; + } + return val; +} + +template <> +inline boost::math::ntl::RR log_min_value<boost::math::ntl::RR>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(boost::math::ntl::RR)) +{ + static bool has_init = false; + static NTL::RR val; + if(!has_init) + { + val = 1; + val.e = -NTL_OVFBND+20; + val = log(val); + has_init = true; + } + return val; +} + +template <> +inline boost::math::ntl::RR epsilon<boost::math::ntl::RR>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(boost::math::ntl::RR)) +{ + return ldexp(boost::math::ntl::RR(1), 1-boost::math::policies::digits<boost::math::ntl::RR, boost::math::policies::policy<> >()); +} + +} // namespace tools + +// +// The number of digits precision in RR can vary with each call +// so we need to recalculate these with each call: +// +namespace constants{ + +template<> inline boost::math::ntl::RR pi<boost::math::ntl::RR>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(boost::math::ntl::RR)) +{ + NTL::RR result; + ComputePi(result); + return result; +} +template<> inline boost::math::ntl::RR e<boost::math::ntl::RR>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(boost::math::ntl::RR)) +{ + NTL::RR result; + result = 1; + return exp(result); +} + +} // namespace constants + +namespace ntl{ + // + // These are some fairly brain-dead versions of the math + // functions that NTL fails to provide. + // + + + // + // Inverse trig functions: + // + struct asin_root + { + asin_root(RR const& target) : t(target){} + + std::tr1::tuple<RR, RR, RR> operator()(RR const& p) + { + RR f0 = sin(p); + RR f1 = cos(p); + RR f2 = -f0; + f0 -= t; + return std::tr1::make_tuple(f0, f1, f2); + } + private: + RR t; + }; + + inline RR asin(RR z) + { + double r; + conv(r, z.value()); + return boost::math::tools::halley_iterate( + asin_root(z), + RR(std::asin(r)), + RR(-boost::math::constants::pi<RR>()/2), + RR(boost::math::constants::pi<RR>()/2), + NTL::RR::precision()); + } + + struct acos_root + { + acos_root(RR const& target) : t(target){} + + std::tr1::tuple<RR, RR, RR> operator()(RR const& p) + { + RR f0 = cos(p); + RR f1 = -sin(p); + RR f2 = -f0; + f0 -= t; + return std::tr1::make_tuple(f0, f1, f2); + } + private: + RR t; + }; + + inline RR acos(RR z) + { + double r; + conv(r, z.value()); + return boost::math::tools::halley_iterate( + acos_root(z), + RR(std::acos(r)), + RR(-boost::math::constants::pi<RR>()/2), + RR(boost::math::constants::pi<RR>()/2), + NTL::RR::precision()); + } + + struct atan_root + { + atan_root(RR const& target) : t(target){} + + std::tr1::tuple<RR, RR, RR> operator()(RR const& p) + { + RR c = cos(p); + RR ta = tan(p); + RR f0 = ta - t; + RR f1 = 1 / (c * c); + RR f2 = 2 * ta / (c * c); + return std::tr1::make_tuple(f0, f1, f2); + } + private: + RR t; + }; + + inline RR atan(RR z) + { + double r; + conv(r, z.value()); + return boost::math::tools::halley_iterate( + atan_root(z), + RR(std::atan(r)), + -boost::math::constants::pi<RR>()/2, + boost::math::constants::pi<RR>()/2, + NTL::RR::precision()); + } + + inline RR sinh(RR z) + { + return (expm1(z.value()) - expm1(-z.value())) / 2; + } + + inline RR cosh(RR z) + { + return (exp(z) + exp(-z)) / 2; + } + + inline RR tanh(RR z) + { + return sinh(z) / cosh(z); + } + + inline RR fmod(RR x, RR y) + { + // This is a really crummy version of fmod, we rely on lots + // of digits to get us out of trouble... + RR factor = floor(x/y); + return x - factor * y; + } + + template <class Policy> + inline int iround(RR const& x, const Policy& pol) + { + return tools::real_cast<int>(round(x, pol)); + } + + template <class Policy> + inline long lround(RR const& x, const Policy& pol) + { + return tools::real_cast<long>(round(x, pol)); + } + + template <class Policy> + inline long long llround(RR const& x, const Policy& pol) + { + return tools::real_cast<long long>(round(x, pol)); + } + + template <class Policy> + inline int itrunc(RR const& x, const Policy& pol) + { + return tools::real_cast<int>(trunc(x, pol)); + } + + template <class Policy> + inline long ltrunc(RR const& x, const Policy& pol) + { + return tools::real_cast<long>(trunc(x, pol)); + } + + template <class Policy> + inline long long lltrunc(RR const& x, const Policy& pol) + { + return tools::real_cast<long long>(trunc(x, pol)); + } + +} // namespace ntl + +namespace detail{ + +template <class Policy> +ntl::RR digamma_imp(ntl::RR x, const mpl::int_<0>* , const Policy& pol) +{ + // + // This handles reflection of negative arguments, and all our + // error handling, then forwards to the T-specific approximation. + // + BOOST_MATH_STD_USING // ADL of std functions. + + ntl::RR result = 0; + // + // Check for negative arguments and use reflection: + // + if(x < 0) + { + // Reflect: + x = 1 - x; + // Argument reduction for tan: + ntl::RR remainder = x - floor(x); + // Shift to negative if > 0.5: + if(remainder > 0.5) + { + remainder -= 1; + } + // + // check for evaluation at a negative pole: + // + if(remainder == 0) + { + return policies::raise_pole_error<ntl::RR>("boost::math::digamma<%1%>(%1%)", 0, (1-x), pol); + } + result = constants::pi<ntl::RR>() / tan(constants::pi<ntl::RR>() * remainder); + } + result += big_digamma(x); + return result; +} + +} // namespace detail + +} // namespace math +} // namespace boost + +#endif // BOOST_MATH_REAL_CONCEPT_HPP + + diff --git a/Utilities/BGL/boost/math/common_factor.hpp b/Utilities/BGL/boost/math/common_factor.hpp new file mode 100644 index 0000000000000000000000000000000000000000..ff06b018b575bdb8b81c4deb1a385e4173dba6e7 --- /dev/null +++ b/Utilities/BGL/boost/math/common_factor.hpp @@ -0,0 +1,16 @@ +// Boost common_factor.hpp header file -------------------------------------// + +// (C) Copyright Daryle Walker 2001-2002. +// 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) + +// See http://www.boost.org for updates, documentation, and revision history. + +#ifndef BOOST_MATH_COMMON_FACTOR_HPP +#define BOOST_MATH_COMMON_FACTOR_HPP + +#include <boost/math/common_factor_ct.hpp> +#include <boost/math/common_factor_rt.hpp> + +#endif // BOOST_MATH_COMMON_FACTOR_HPP diff --git a/Utilities/BGL/boost/math/common_factor_ct.hpp b/Utilities/BGL/boost/math/common_factor_ct.hpp new file mode 100644 index 0000000000000000000000000000000000000000..025b658544b0ddffc0afadaa8ad8de417bed1dfe --- /dev/null +++ b/Utilities/BGL/boost/math/common_factor_ct.hpp @@ -0,0 +1,188 @@ +// Boost common_factor_ct.hpp header file ----------------------------------// + +// (C) Copyright Daryle Walker and Stephen Cleary 2001-2002. +// 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) + +// See http://www.boost.org for updates, documentation, and revision history. + +#ifndef BOOST_MATH_COMMON_FACTOR_CT_HPP +#define BOOST_MATH_COMMON_FACTOR_CT_HPP + +#include <boost/math_fwd.hpp> // self include + +#include <boost/config.hpp> // for BOOST_STATIC_CONSTANT, etc. + + +namespace boost +{ +namespace math +{ + + +// Implementation details --------------------------------------------------// + +namespace detail +{ +#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION + // Build GCD with Euclid's recursive algorithm + template < unsigned long Value1, unsigned long Value2 > + struct static_gcd_helper_t + { + private: + BOOST_STATIC_CONSTANT( unsigned long, new_value1 = Value2 ); + BOOST_STATIC_CONSTANT( unsigned long, new_value2 = Value1 % Value2 ); + + #ifndef __BORLANDC__ + #define BOOST_DETAIL_GCD_HELPER_VAL(Value) static_cast<unsigned long>(Value) + #else + typedef static_gcd_helper_t self_type; + #define BOOST_DETAIL_GCD_HELPER_VAL(Value) (self_type:: Value ) + #endif + + typedef static_gcd_helper_t< BOOST_DETAIL_GCD_HELPER_VAL(new_value1), + BOOST_DETAIL_GCD_HELPER_VAL(new_value2) > next_step_type; + + #undef BOOST_DETAIL_GCD_HELPER_VAL + + public: + BOOST_STATIC_CONSTANT( unsigned long, value = next_step_type::value ); + }; + + // Non-recursive case + template < unsigned long Value1 > + struct static_gcd_helper_t< Value1, 0UL > + { + BOOST_STATIC_CONSTANT( unsigned long, value = Value1 ); + }; +#else + // Use inner class template workaround from Peter Dimov + template < unsigned long Value1 > + struct static_gcd_helper2_t + { + template < unsigned long Value2 > + struct helper + { + BOOST_STATIC_CONSTANT( unsigned long, value + = static_gcd_helper2_t<Value2>::BOOST_NESTED_TEMPLATE + helper<Value1 % Value2>::value ); + }; + + template < > + struct helper< 0UL > + { + BOOST_STATIC_CONSTANT( unsigned long, value = Value1 ); + }; + }; + + // Special case + template < > + struct static_gcd_helper2_t< 0UL > + { + template < unsigned long Value2 > + struct helper + { + BOOST_STATIC_CONSTANT( unsigned long, value = Value2 ); + }; + }; + + // Build the GCD from the above template(s) + template < unsigned long Value1, unsigned long Value2 > + struct static_gcd_helper_t + { + BOOST_STATIC_CONSTANT( unsigned long, value + = static_gcd_helper2_t<Value1>::BOOST_NESTED_TEMPLATE + helper<Value2>::value ); + }; +#endif + +#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION + // Build the LCM from the GCD + template < unsigned long Value1, unsigned long Value2 > + struct static_lcm_helper_t + { + typedef static_gcd_helper_t<Value1, Value2> gcd_type; + + BOOST_STATIC_CONSTANT( unsigned long, value = Value1 / gcd_type::value + * Value2 ); + }; + + // Special case for zero-GCD values + template < > + struct static_lcm_helper_t< 0UL, 0UL > + { + BOOST_STATIC_CONSTANT( unsigned long, value = 0UL ); + }; +#else + // Adapt GCD's inner class template workaround for LCM + template < unsigned long Value1 > + struct static_lcm_helper2_t + { + template < unsigned long Value2 > + struct helper + { + typedef static_gcd_helper_t<Value1, Value2> gcd_type; + + BOOST_STATIC_CONSTANT( unsigned long, value = Value1 + / gcd_type::value * Value2 ); + }; + + template < > + struct helper< 0UL > + { + BOOST_STATIC_CONSTANT( unsigned long, value = 0UL ); + }; + }; + + // Special case + template < > + struct static_lcm_helper2_t< 0UL > + { + template < unsigned long Value2 > + struct helper + { + BOOST_STATIC_CONSTANT( unsigned long, value = 0UL ); + }; + }; + + // Build the LCM from the above template(s) + template < unsigned long Value1, unsigned long Value2 > + struct static_lcm_helper_t + { + BOOST_STATIC_CONSTANT( unsigned long, value + = static_lcm_helper2_t<Value1>::BOOST_NESTED_TEMPLATE + helper<Value2>::value ); + }; +#endif + +} // namespace detail + + +// Compile-time greatest common divisor evaluator class declaration --------// + +template < unsigned long Value1, unsigned long Value2 > +struct static_gcd +{ + BOOST_STATIC_CONSTANT( unsigned long, value + = (detail::static_gcd_helper_t<Value1, Value2>::value) ); + +}; // boost::math::static_gcd + + +// Compile-time least common multiple evaluator class declaration ----------// + +template < unsigned long Value1, unsigned long Value2 > +struct static_lcm +{ + BOOST_STATIC_CONSTANT( unsigned long, value + = (detail::static_lcm_helper_t<Value1, Value2>::value) ); + +}; // boost::math::static_lcm + + +} // namespace math +} // namespace boost + + +#endif // BOOST_MATH_COMMON_FACTOR_CT_HPP diff --git a/Utilities/BGL/boost/math/common_factor_rt.hpp b/Utilities/BGL/boost/math/common_factor_rt.hpp new file mode 100644 index 0000000000000000000000000000000000000000..08eba9b07070826c1c23d0566deeed1b3d1b958c --- /dev/null +++ b/Utilities/BGL/boost/math/common_factor_rt.hpp @@ -0,0 +1,516 @@ +// Boost common_factor_rt.hpp header file ----------------------------------// + +// (C) Copyright Daryle Walker and Paul Moore 2001-2002. Permission to copy, +// use, modify, sell and distribute this software is granted provided this +// copyright notice appears in all copies. This software is provided "as is" +// without express or implied warranty, and with no claim as to its suitability +// for any purpose. + +// boostinspect:nolicense (don't complain about the lack of a Boost license) +// (Paul Moore hasn't been in contact for years, so there's no way to change the +// license.) + +// See http://www.boost.org for updates, documentation, and revision history. + +#ifndef BOOST_MATH_COMMON_FACTOR_RT_HPP +#define BOOST_MATH_COMMON_FACTOR_RT_HPP + +#include <boost/math_fwd.hpp> // self include + +#include <boost/config.hpp> // for BOOST_NESTED_TEMPLATE, etc. +#include <boost/limits.hpp> // for std::numeric_limits +#include <boost/detail/workaround.hpp> + + +namespace boost +{ +namespace math +{ + + +// Forward declarations for function templates -----------------------------// + +template < typename IntegerType > + IntegerType gcd( IntegerType const &a, IntegerType const &b ); + +template < typename IntegerType > + IntegerType lcm( IntegerType const &a, IntegerType const &b ); + + +// Greatest common divisor evaluator class declaration ---------------------// + +template < typename IntegerType > +class gcd_evaluator +{ +public: + // Types + typedef IntegerType result_type, first_argument_type, second_argument_type; + + // Function object interface + result_type operator ()( first_argument_type const &a, + second_argument_type const &b ) const; + +}; // boost::math::gcd_evaluator + + +// Least common multiple evaluator class declaration -----------------------// + +template < typename IntegerType > +class lcm_evaluator +{ +public: + // Types + typedef IntegerType result_type, first_argument_type, second_argument_type; + + // Function object interface + result_type operator ()( first_argument_type const &a, + second_argument_type const &b ) const; + +}; // boost::math::lcm_evaluator + + +// Implementation details --------------------------------------------------// + +namespace detail +{ + // Greatest common divisor for rings (including unsigned integers) + template < typename RingType > + RingType + gcd_euclidean + ( + RingType a, + RingType b + ) + { + // Avoid repeated construction + #ifndef __BORLANDC__ + RingType const zero = static_cast<RingType>( 0 ); + #else + RingType zero = static_cast<RingType>( 0 ); + #endif + + // Reduce by GCD-remainder property [GCD(a,b) == GCD(b,a MOD b)] + while ( true ) + { + if ( a == zero ) + return b; + b %= a; + + if ( b == zero ) + return a; + a %= b; + } + } + + // Greatest common divisor for (signed) integers + template < typename IntegerType > + inline + IntegerType + gcd_integer + ( + IntegerType const & a, + IntegerType const & b + ) + { + // Avoid repeated construction + IntegerType const zero = static_cast<IntegerType>( 0 ); + IntegerType const result = gcd_euclidean( a, b ); + + return ( result < zero ) ? -result : result; + } + + // Greatest common divisor for unsigned binary integers + template < typename BuiltInUnsigned > + BuiltInUnsigned + gcd_binary + ( + BuiltInUnsigned u, + BuiltInUnsigned v + ) + { + if ( u && v ) + { + // Shift out common factors of 2 + unsigned shifts = 0; + + while ( !(u & 1u) && !(v & 1u) ) + { + ++shifts; + u >>= 1; + v >>= 1; + } + + // Start with the still-even one, if any + BuiltInUnsigned r[] = { u, v }; + unsigned which = static_cast<bool>( u & 1u ); + + // Whittle down the values via their differences + do + { +#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582)) + while ( !(r[ which ] & 1u) ) + { + r[ which ] = (r[which] >> 1); + } +#else + // Remove factors of two from the even one + while ( !(r[ which ] & 1u) ) + { + r[ which ] >>= 1; + } +#endif + + // Replace the larger of the two with their difference + if ( r[!which] > r[which] ) + { + which ^= 1u; + } + + r[ which ] -= r[ !which ]; + } + while ( r[which] ); + + // Shift-in the common factor of 2 to the residues' GCD + return r[ !which ] << shifts; + } + else + { + // At least one input is zero, return the other + // (adding since zero is the additive identity) + // or zero if both are zero. + return u + v; + } + } + + // Least common multiple for rings (including unsigned integers) + template < typename RingType > + inline + RingType + lcm_euclidean + ( + RingType const & a, + RingType const & b + ) + { + RingType const zero = static_cast<RingType>( 0 ); + RingType const temp = gcd_euclidean( a, b ); + + return ( temp != zero ) ? ( a / temp * b ) : zero; + } + + // Least common multiple for (signed) integers + template < typename IntegerType > + inline + IntegerType + lcm_integer + ( + IntegerType const & a, + IntegerType const & b + ) + { + // Avoid repeated construction + IntegerType const zero = static_cast<IntegerType>( 0 ); + IntegerType const result = lcm_euclidean( a, b ); + + return ( result < zero ) ? -result : result; + } + + // Function objects to find the best way of computing GCD or LCM +#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS +#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION + template < typename T, bool IsSpecialized, bool IsSigned > + struct gcd_optimal_evaluator_helper_t + { + T operator ()( T const &a, T const &b ) + { + return gcd_euclidean( a, b ); + } + }; + + template < typename T > + struct gcd_optimal_evaluator_helper_t< T, true, true > + { + T operator ()( T const &a, T const &b ) + { + return gcd_integer( a, b ); + } + }; +#else + template < bool IsSpecialized, bool IsSigned > + struct gcd_optimal_evaluator_helper2_t + { + template < typename T > + struct helper + { + T operator ()( T const &a, T const &b ) + { + return gcd_euclidean( a, b ); + } + }; + }; + + template < > + struct gcd_optimal_evaluator_helper2_t< true, true > + { + template < typename T > + struct helper + { + T operator ()( T const &a, T const &b ) + { + return gcd_integer( a, b ); + } + }; + }; + + template < typename T, bool IsSpecialized, bool IsSigned > + struct gcd_optimal_evaluator_helper_t + : gcd_optimal_evaluator_helper2_t<IsSpecialized, IsSigned> + ::BOOST_NESTED_TEMPLATE helper<T> + { + }; +#endif + + template < typename T > + struct gcd_optimal_evaluator + { + T operator ()( T const &a, T const &b ) + { + typedef ::std::numeric_limits<T> limits_type; + + typedef gcd_optimal_evaluator_helper_t<T, + limits_type::is_specialized, limits_type::is_signed> helper_type; + + helper_type solver; + + return solver( a, b ); + } + }; +#else // BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS + template < typename T > + struct gcd_optimal_evaluator + { + T operator ()( T const &a, T const &b ) + { + return gcd_integer( a, b ); + } + }; +#endif + + // Specialize for the built-in integers +#define BOOST_PRIVATE_GCD_UF( Ut ) \ + template < > struct gcd_optimal_evaluator<Ut> \ + { Ut operator ()( Ut a, Ut b ) const { return gcd_binary( a, b ); } } + + BOOST_PRIVATE_GCD_UF( unsigned char ); + BOOST_PRIVATE_GCD_UF( unsigned short ); + BOOST_PRIVATE_GCD_UF( unsigned ); + BOOST_PRIVATE_GCD_UF( unsigned long ); + +#ifdef BOOST_HAS_LONG_LONG + BOOST_PRIVATE_GCD_UF( boost::ulong_long_type ); +#elif defined(BOOST_HAS_MS_INT64) + BOOST_PRIVATE_GCD_UF( unsigned __int64 ); +#endif + +#undef BOOST_PRIVATE_GCD_UF + +#define BOOST_PRIVATE_GCD_SF( St, Ut ) \ + template < > struct gcd_optimal_evaluator<St> \ + { St operator ()( St a, St b ) const { Ut const a_abs = \ + static_cast<Ut>( a < 0 ? -a : +a ), b_abs = static_cast<Ut>( \ + b < 0 ? -b : +b ); return static_cast<St>( \ + gcd_optimal_evaluator<Ut>()(a_abs, b_abs) ); } } + + BOOST_PRIVATE_GCD_SF( signed char, unsigned char ); + BOOST_PRIVATE_GCD_SF( short, unsigned short ); + BOOST_PRIVATE_GCD_SF( int, unsigned ); + BOOST_PRIVATE_GCD_SF( long, unsigned long ); + + BOOST_PRIVATE_GCD_SF( char, unsigned char ); // should work even if unsigned + +#ifdef BOOST_HAS_LONG_LONG + BOOST_PRIVATE_GCD_SF( boost::long_long_type, boost::ulong_long_type ); +#elif defined(BOOST_HAS_MS_INT64) + BOOST_PRIVATE_GCD_SF( __int64, unsigned __int64 ); +#endif + +#undef BOOST_PRIVATE_GCD_SF + +#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS +#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION + template < typename T, bool IsSpecialized, bool IsSigned > + struct lcm_optimal_evaluator_helper_t + { + T operator ()( T const &a, T const &b ) + { + return lcm_euclidean( a, b ); + } + }; + + template < typename T > + struct lcm_optimal_evaluator_helper_t< T, true, true > + { + T operator ()( T const &a, T const &b ) + { + return lcm_integer( a, b ); + } + }; +#else + template < bool IsSpecialized, bool IsSigned > + struct lcm_optimal_evaluator_helper2_t + { + template < typename T > + struct helper + { + T operator ()( T const &a, T const &b ) + { + return lcm_euclidean( a, b ); + } + }; + }; + + template < > + struct lcm_optimal_evaluator_helper2_t< true, true > + { + template < typename T > + struct helper + { + T operator ()( T const &a, T const &b ) + { + return lcm_integer( a, b ); + } + }; + }; + + template < typename T, bool IsSpecialized, bool IsSigned > + struct lcm_optimal_evaluator_helper_t + : lcm_optimal_evaluator_helper2_t<IsSpecialized, IsSigned> + ::BOOST_NESTED_TEMPLATE helper<T> + { + }; +#endif + + template < typename T > + struct lcm_optimal_evaluator + { + T operator ()( T const &a, T const &b ) + { + typedef ::std::numeric_limits<T> limits_type; + + typedef lcm_optimal_evaluator_helper_t<T, + limits_type::is_specialized, limits_type::is_signed> helper_type; + + helper_type solver; + + return solver( a, b ); + } + }; +#else // BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS + template < typename T > + struct lcm_optimal_evaluator + { + T operator ()( T const &a, T const &b ) + { + return lcm_integer( a, b ); + } + }; +#endif + + // Functions to find the GCD or LCM in the best way + template < typename T > + inline + T + gcd_optimal + ( + T const & a, + T const & b + ) + { + gcd_optimal_evaluator<T> solver; + + return solver( a, b ); + } + + template < typename T > + inline + T + lcm_optimal + ( + T const & a, + T const & b + ) + { + lcm_optimal_evaluator<T> solver; + + return solver( a, b ); + } + +} // namespace detail + + +// Greatest common divisor evaluator member function definition ------------// + +template < typename IntegerType > +inline +typename gcd_evaluator<IntegerType>::result_type +gcd_evaluator<IntegerType>::operator () +( + first_argument_type const & a, + second_argument_type const & b +) const +{ + return detail::gcd_optimal( a, b ); +} + + +// Least common multiple evaluator member function definition --------------// + +template < typename IntegerType > +inline +typename lcm_evaluator<IntegerType>::result_type +lcm_evaluator<IntegerType>::operator () +( + first_argument_type const & a, + second_argument_type const & b +) const +{ + return detail::lcm_optimal( a, b ); +} + + +// Greatest common divisor and least common multiple function definitions --// + +template < typename IntegerType > +inline +IntegerType +gcd +( + IntegerType const & a, + IntegerType const & b +) +{ + gcd_evaluator<IntegerType> solver; + + return solver( a, b ); +} + +template < typename IntegerType > +inline +IntegerType +lcm +( + IntegerType const & a, + IntegerType const & b +) +{ + lcm_evaluator<IntegerType> solver; + + return solver( a, b ); +} + + +} // namespace math +} // namespace boost + + +#endif // BOOST_MATH_COMMON_FACTOR_RT_HPP diff --git a/Utilities/BGL/boost/math/complex.hpp b/Utilities/BGL/boost/math/complex.hpp new file mode 100644 index 0000000000000000000000000000000000000000..d839efb09e1fe83aa7c97c61c246e748b28204c6 --- /dev/null +++ b/Utilities/BGL/boost/math/complex.hpp @@ -0,0 +1,32 @@ +// (C) Copyright John Maddock 2005. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_COMPLEX_INCLUDED +#define BOOST_MATH_COMPLEX_INCLUDED + +#ifndef BOOST_MATH_COMPLEX_ASIN_INCLUDED +# include <boost/math/complex/asin.hpp> +#endif +#ifndef BOOST_MATH_COMPLEX_ASINH_INCLUDED +# include <boost/math/complex/asinh.hpp> +#endif +#ifndef BOOST_MATH_COMPLEX_ACOS_INCLUDED +# include <boost/math/complex/acos.hpp> +#endif +#ifndef BOOST_MATH_COMPLEX_ACOSH_INCLUDED +# include <boost/math/complex/acosh.hpp> +#endif +#ifndef BOOST_MATH_COMPLEX_ATAN_INCLUDED +# include <boost/math/complex/atan.hpp> +#endif +#ifndef BOOST_MATH_COMPLEX_ATANH_INCLUDED +# include <boost/math/complex/atanh.hpp> +#endif +#ifndef BOOST_MATH_COMPLEX_FABS_INCLUDED +# include <boost/math/complex/fabs.hpp> +#endif + + +#endif // BOOST_MATH_COMPLEX_INCLUDED diff --git a/Utilities/BGL/boost/math/complex/acos.hpp b/Utilities/BGL/boost/math/complex/acos.hpp new file mode 100644 index 0000000000000000000000000000000000000000..86e4f06ab8c088130e53239ea4d629afd4825970 --- /dev/null +++ b/Utilities/BGL/boost/math/complex/acos.hpp @@ -0,0 +1,235 @@ +// (C) Copyright John Maddock 2005. +// 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) + +#ifndef BOOST_MATH_COMPLEX_ACOS_INCLUDED +#define BOOST_MATH_COMPLEX_ACOS_INCLUDED + +#ifndef BOOST_MATH_COMPLEX_DETAILS_INCLUDED +# include <boost/math/complex/details.hpp> +#endif +#ifndef BOOST_MATH_LOG1P_INCLUDED +# include <boost/math/special_functions/log1p.hpp> +#endif +#include <boost/assert.hpp> + +#ifdef BOOST_NO_STDC_NAMESPACE +namespace std{ using ::sqrt; using ::fabs; using ::acos; using ::asin; using ::atan; using ::atan2; } +#endif + +namespace boost{ namespace math{ + +template<class T> +std::complex<T> acos(const std::complex<T>& z) +{ + // + // This implementation is a transcription of the pseudo-code in: + // + // "Implementing the Complex Arcsine and Arccosine Functions using Exception Handling." + // T E Hull, Thomas F Fairgrieve and Ping Tak Peter Tang. + // ACM Transactions on Mathematical Software, Vol 23, No 3, Sept 1997. + // + + // + // These static constants should really be in a maths constants library: + // + static const T one = static_cast<T>(1); + //static const T two = static_cast<T>(2); + static const T half = static_cast<T>(0.5L); + static const T a_crossover = static_cast<T>(1.5L); + static const T b_crossover = static_cast<T>(0.6417L); + static const T s_pi = static_cast<T>(3.141592653589793238462643383279502884197L); + static const T half_pi = static_cast<T>(1.57079632679489661923132169163975144L); + static const T log_two = static_cast<T>(0.69314718055994530941723212145817657L); + static const T quarter_pi = static_cast<T>(0.78539816339744830961566084581987572L); + + // + // Get real and imaginary parts, discard the signs as we can + // figure out the sign of the result later: + // + T x = std::fabs(z.real()); + T y = std::fabs(z.imag()); + + T real, imag; // these hold our result + + // + // Handle special cases specified by the C99 standard, + // many of these special cases aren't really needed here, + // but doing it this way prevents overflow/underflow arithmetic + // in the main body of the logic, which may trip up some machines: + // + if(std::numeric_limits<T>::has_infinity && (x == std::numeric_limits<T>::infinity())) + { + if(y == std::numeric_limits<T>::infinity()) + { + real = quarter_pi; + imag = std::numeric_limits<T>::infinity(); + } + else if(detail::test_is_nan(y)) + { + return std::complex<T>(y, -std::numeric_limits<T>::infinity()); + } + else + { + // y is not infinity or nan: + real = 0; + imag = std::numeric_limits<T>::infinity(); + } + } + else if(detail::test_is_nan(x)) + { + if(y == std::numeric_limits<T>::infinity()) + return std::complex<T>(x, (z.imag() < 0) ? std::numeric_limits<T>::infinity() : -std::numeric_limits<T>::infinity()); + return std::complex<T>(x, x); + } + else if(std::numeric_limits<T>::has_infinity && (y == std::numeric_limits<T>::infinity())) + { + real = half_pi; + imag = std::numeric_limits<T>::infinity(); + } + else if(detail::test_is_nan(y)) + { + return std::complex<T>((x == 0) ? half_pi : y, y); + } + else + { + // + // What follows is the regular Hull et al code, + // begin with the special case for real numbers: + // + if((y == 0) && (x <= one)) + return std::complex<T>((x == 0) ? half_pi : std::acos(z.real())); + // + // Figure out if our input is within the "safe area" identified by Hull et al. + // This would be more efficient with portable floating point exception handling; + // fortunately the quantities M and u identified by Hull et al (figure 3), + // match with the max and min methods of numeric_limits<T>. + // + T safe_max = detail::safe_max(static_cast<T>(8)); + T safe_min = detail::safe_min(static_cast<T>(4)); + + T xp1 = one + x; + T xm1 = x - one; + + if((x < safe_max) && (x > safe_min) && (y < safe_max) && (y > safe_min)) + { + T yy = y * y; + T r = std::sqrt(xp1*xp1 + yy); + T s = std::sqrt(xm1*xm1 + yy); + T a = half * (r + s); + T b = x / a; + + if(b <= b_crossover) + { + real = std::acos(b); + } + else + { + T apx = a + x; + if(x <= one) + { + real = std::atan(std::sqrt(half * apx * (yy /(r + xp1) + (s-xm1)))/x); + } + else + { + real = std::atan((y * std::sqrt(half * (apx/(r + xp1) + apx/(s+xm1))))/x); + } + } + + if(a <= a_crossover) + { + T am1; + if(x < one) + { + am1 = half * (yy/(r + xp1) + yy/(s - xm1)); + } + else + { + am1 = half * (yy/(r + xp1) + (s + xm1)); + } + imag = boost::math::log1p(am1 + std::sqrt(am1 * (a + one))); + } + else + { + imag = std::log(a + std::sqrt(a*a - one)); + } + } + else + { + // + // This is the Hull et al exception handling code from Fig 6 of their paper: + // + if(y <= (std::numeric_limits<T>::epsilon() * std::fabs(xm1))) + { + if(x < one) + { + real = std::acos(x); + imag = y / std::sqrt(xp1*(one-x)); + } + else + { + real = 0; + if(((std::numeric_limits<T>::max)() / xp1) > xm1) + { + // xp1 * xm1 won't overflow: + imag = boost::math::log1p(xm1 + std::sqrt(xp1*xm1)); + } + else + { + imag = log_two + std::log(x); + } + } + } + else if(y <= safe_min) + { + // There is an assumption in Hull et al's analysis that + // if we get here then x == 1. This is true for all "good" + // machines where : + // + // E^2 > 8*sqrt(u); with: + // + // E = std::numeric_limits<T>::epsilon() + // u = (std::numeric_limits<T>::min)() + // + // Hull et al provide alternative code for "bad" machines + // but we have no way to test that here, so for now just assert + // on the assumption: + // + BOOST_ASSERT(x == 1); + real = std::sqrt(y); + imag = std::sqrt(y); + } + else if(std::numeric_limits<T>::epsilon() * y - one >= x) + { + real = half_pi; + imag = log_two + std::log(y); + } + else if(x > one) + { + real = std::atan(y/x); + T xoy = x/y; + imag = log_two + std::log(y) + half * boost::math::log1p(xoy*xoy); + } + else + { + real = half_pi; + T a = std::sqrt(one + y*y); + imag = half * boost::math::log1p(static_cast<T>(2)*y*(y+a)); + } + } + } + + // + // Finish off by working out the sign of the result: + // + if(z.real() < 0) + real = s_pi - real; + if(z.imag() > 0) + imag = -imag; + + return std::complex<T>(real, imag); +} + +} } // namespaces + +#endif // BOOST_MATH_COMPLEX_ACOS_INCLUDED diff --git a/Utilities/BGL/boost/math/complex/acosh.hpp b/Utilities/BGL/boost/math/complex/acosh.hpp new file mode 100644 index 0000000000000000000000000000000000000000..51712a7467aa3d0a5fc1e878fe460a80c5ee4931 --- /dev/null +++ b/Utilities/BGL/boost/math/complex/acosh.hpp @@ -0,0 +1,34 @@ +// (C) Copyright John Maddock 2005. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_COMPLEX_ACOSH_INCLUDED +#define BOOST_MATH_COMPLEX_ACOSH_INCLUDED + +#ifndef BOOST_MATH_COMPLEX_DETAILS_INCLUDED +# include <boost/math/complex/details.hpp> +#endif +#ifndef BOOST_MATH_COMPLEX_ATANH_INCLUDED +# include <boost/math/complex/acos.hpp> +#endif + +namespace boost{ namespace math{ + +template<class T> +inline std::complex<T> acosh(const std::complex<T>& z) +{ + // + // We use the relation acosh(z) = +-i acos(z) + // Choosing the sign of multiplier to give real(acosh(z)) >= 0 + // as well as compatibility with C99. + // + std::complex<T> result = boost::math::acos(z); + if(!detail::test_is_nan(result.imag()) && result.imag() <= 0) + return detail::mult_i(result); + return detail::mult_minus_i(result); +} + +} } // namespaces + +#endif // BOOST_MATH_COMPLEX_ACOSH_INCLUDED diff --git a/Utilities/BGL/boost/math/complex/asin.hpp b/Utilities/BGL/boost/math/complex/asin.hpp new file mode 100644 index 0000000000000000000000000000000000000000..5dbb0ace7ec36b5659cfda00adbd395ca3a9b5e6 --- /dev/null +++ b/Utilities/BGL/boost/math/complex/asin.hpp @@ -0,0 +1,245 @@ +// (C) Copyright John Maddock 2005. +// 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) + +#ifndef BOOST_MATH_COMPLEX_ASIN_INCLUDED +#define BOOST_MATH_COMPLEX_ASIN_INCLUDED + +#ifndef BOOST_MATH_COMPLEX_DETAILS_INCLUDED +# include <boost/math/complex/details.hpp> +#endif +#ifndef BOOST_MATH_LOG1P_INCLUDED +# include <boost/math/special_functions/log1p.hpp> +#endif +#include <boost/assert.hpp> + +#ifdef BOOST_NO_STDC_NAMESPACE +namespace std{ using ::sqrt; using ::fabs; using ::acos; using ::asin; using ::atan; using ::atan2; } +#endif + +namespace boost{ namespace math{ + +template<class T> +inline std::complex<T> asin(const std::complex<T>& z) +{ + // + // This implementation is a transcription of the pseudo-code in: + // + // "Implementing the complex Arcsine and Arccosine Functions using Exception Handling." + // T E Hull, Thomas F Fairgrieve and Ping Tak Peter Tang. + // ACM Transactions on Mathematical Software, Vol 23, No 3, Sept 1997. + // + + // + // These static constants should really be in a maths constants library: + // + static const T one = static_cast<T>(1); + //static const T two = static_cast<T>(2); + static const T half = static_cast<T>(0.5L); + static const T a_crossover = static_cast<T>(1.5L); + static const T b_crossover = static_cast<T>(0.6417L); + //static const T pi = static_cast<T>(3.141592653589793238462643383279502884197L); + static const T half_pi = static_cast<T>(1.57079632679489661923132169163975144L); + static const T log_two = static_cast<T>(0.69314718055994530941723212145817657L); + static const T quarter_pi = static_cast<T>(0.78539816339744830961566084581987572L); + + // + // Get real and imaginary parts, discard the signs as we can + // figure out the sign of the result later: + // + T x = std::fabs(z.real()); + T y = std::fabs(z.imag()); + T real, imag; // our results + + // + // Begin by handling the special cases for infinities and nan's + // specified in C99, most of this is handled by the regular logic + // below, but handling it as a special case prevents overflow/underflow + // arithmetic which may trip up some machines: + // + if(detail::test_is_nan(x)) + { + if(detail::test_is_nan(y)) + return std::complex<T>(x, x); + if(std::numeric_limits<T>::has_infinity && (y == std::numeric_limits<T>::infinity())) + { + real = x; + imag = std::numeric_limits<T>::infinity(); + } + else + return std::complex<T>(x, x); + } + else if(detail::test_is_nan(y)) + { + if(x == 0) + { + real = 0; + imag = y; + } + else if(std::numeric_limits<T>::has_infinity && (x == std::numeric_limits<T>::infinity())) + { + real = y; + imag = std::numeric_limits<T>::infinity(); + } + else + return std::complex<T>(y, y); + } + else if(std::numeric_limits<T>::has_infinity && (x == std::numeric_limits<T>::infinity())) + { + if(y == std::numeric_limits<T>::infinity()) + { + real = quarter_pi; + imag = std::numeric_limits<T>::infinity(); + } + else + { + real = half_pi; + imag = std::numeric_limits<T>::infinity(); + } + } + else if(std::numeric_limits<T>::has_infinity && (y == std::numeric_limits<T>::infinity())) + { + real = 0; + imag = std::numeric_limits<T>::infinity(); + } + else + { + // + // special case for real numbers: + // + if((y == 0) && (x <= one)) + return std::complex<T>(std::asin(z.real())); + // + // Figure out if our input is within the "safe area" identified by Hull et al. + // This would be more efficient with portable floating point exception handling; + // fortunately the quantities M and u identified by Hull et al (figure 3), + // match with the max and min methods of numeric_limits<T>. + // + T safe_max = detail::safe_max(static_cast<T>(8)); + T safe_min = detail::safe_min(static_cast<T>(4)); + + T xp1 = one + x; + T xm1 = x - one; + + if((x < safe_max) && (x > safe_min) && (y < safe_max) && (y > safe_min)) + { + T yy = y * y; + T r = std::sqrt(xp1*xp1 + yy); + T s = std::sqrt(xm1*xm1 + yy); + T a = half * (r + s); + T b = x / a; + + if(b <= b_crossover) + { + real = std::asin(b); + } + else + { + T apx = a + x; + if(x <= one) + { + real = std::atan(x/std::sqrt(half * apx * (yy /(r + xp1) + (s-xm1)))); + } + else + { + real = std::atan(x/(y * std::sqrt(half * (apx/(r + xp1) + apx/(s+xm1))))); + } + } + + if(a <= a_crossover) + { + T am1; + if(x < one) + { + am1 = half * (yy/(r + xp1) + yy/(s - xm1)); + } + else + { + am1 = half * (yy/(r + xp1) + (s + xm1)); + } + imag = boost::math::log1p(am1 + std::sqrt(am1 * (a + one))); + } + else + { + imag = std::log(a + std::sqrt(a*a - one)); + } + } + else + { + // + // This is the Hull et al exception handling code from Fig 3 of their paper: + // + if(y <= (std::numeric_limits<T>::epsilon() * std::fabs(xm1))) + { + if(x < one) + { + real = std::asin(x); + imag = y / std::sqrt(xp1*xm1); + } + else + { + real = half_pi; + if(((std::numeric_limits<T>::max)() / xp1) > xm1) + { + // xp1 * xm1 won't overflow: + imag = boost::math::log1p(xm1 + std::sqrt(xp1*xm1)); + } + else + { + imag = log_two + std::log(x); + } + } + } + else if(y <= safe_min) + { + // There is an assumption in Hull et al's analysis that + // if we get here then x == 1. This is true for all "good" + // machines where : + // + // E^2 > 8*sqrt(u); with: + // + // E = std::numeric_limits<T>::epsilon() + // u = (std::numeric_limits<T>::min)() + // + // Hull et al provide alternative code for "bad" machines + // but we have no way to test that here, so for now just assert + // on the assumption: + // + BOOST_ASSERT(x == 1); + real = half_pi - std::sqrt(y); + imag = std::sqrt(y); + } + else if(std::numeric_limits<T>::epsilon() * y - one >= x) + { + real = x/y; // This can underflow! + imag = log_two + std::log(y); + } + else if(x > one) + { + real = std::atan(x/y); + T xoy = x/y; + imag = log_two + std::log(y) + half * boost::math::log1p(xoy*xoy); + } + else + { + T a = std::sqrt(one + y*y); + real = x/a; // This can underflow! + imag = half * boost::math::log1p(static_cast<T>(2)*y*(y+a)); + } + } + } + + // + // Finish off by working out the sign of the result: + // + if(z.real() < 0) + real = -real; + if(z.imag() < 0) + imag = -imag; + + return std::complex<T>(real, imag); +} + +} } // namespaces + +#endif // BOOST_MATH_COMPLEX_ASIN_INCLUDED diff --git a/Utilities/BGL/boost/math/complex/asinh.hpp b/Utilities/BGL/boost/math/complex/asinh.hpp new file mode 100644 index 0000000000000000000000000000000000000000..f5dbe7b8339167a7383ebabd163821fe0d182bdf --- /dev/null +++ b/Utilities/BGL/boost/math/complex/asinh.hpp @@ -0,0 +1,32 @@ +// (C) Copyright John Maddock 2005. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_COMPLEX_ASINH_INCLUDED +#define BOOST_MATH_COMPLEX_ASINH_INCLUDED + +#ifndef BOOST_MATH_COMPLEX_DETAILS_INCLUDED +# include <boost/math/complex/details.hpp> +#endif +#ifndef BOOST_MATH_COMPLEX_ASIN_INCLUDED +# include <boost/math/complex/asin.hpp> +#endif + +namespace boost{ namespace math{ + +template<class T> +inline std::complex<T> asinh(const std::complex<T>& x) +{ + // + // We use asinh(z) = i asin(-i z); + // Note that C99 defines this the other way around (which is + // to say asin is specified in terms of asinh), this is consistent + // with C99 though: + // + return ::boost::math::detail::mult_i(::boost::math::asin(::boost::math::detail::mult_minus_i(x))); +} + +} } // namespaces + +#endif // BOOST_MATH_COMPLEX_ASINH_INCLUDED diff --git a/Utilities/BGL/boost/math/complex/atan.hpp b/Utilities/BGL/boost/math/complex/atan.hpp new file mode 100644 index 0000000000000000000000000000000000000000..bf3fdf6d79396863f41c25974c3a94fd57460b91 --- /dev/null +++ b/Utilities/BGL/boost/math/complex/atan.hpp @@ -0,0 +1,36 @@ +// (C) Copyright John Maddock 2005. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_COMPLEX_ATAN_INCLUDED +#define BOOST_MATH_COMPLEX_ATAN_INCLUDED + +#ifndef BOOST_MATH_COMPLEX_DETAILS_INCLUDED +# include <boost/math/complex/details.hpp> +#endif +#ifndef BOOST_MATH_COMPLEX_ATANH_INCLUDED +# include <boost/math/complex/atanh.hpp> +#endif + +namespace boost{ namespace math{ + +template<class T> +std::complex<T> atan(const std::complex<T>& x) +{ + // + // We're using the C99 definition here; atan(z) = -i atanh(iz): + // + if(x.real() == 0) + { + if(x.imag() == 1) + return std::complex<T>(0, std::numeric_limits<T>::has_infinity ? std::numeric_limits<T>::infinity() : static_cast<T>(HUGE_VAL)); + if(x.imag() == -1) + return std::complex<T>(0, std::numeric_limits<T>::has_infinity ? -std::numeric_limits<T>::infinity() : -static_cast<T>(HUGE_VAL)); + } + return ::boost::math::detail::mult_minus_i(::boost::math::atanh(::boost::math::detail::mult_i(x))); +} + +} } // namespaces + +#endif // BOOST_MATH_COMPLEX_ATAN_INCLUDED diff --git a/Utilities/BGL/boost/math/complex/atanh.hpp b/Utilities/BGL/boost/math/complex/atanh.hpp new file mode 100644 index 0000000000000000000000000000000000000000..f8cbed7bc572349ee42d8fbcef3dc6eabe109990 --- /dev/null +++ b/Utilities/BGL/boost/math/complex/atanh.hpp @@ -0,0 +1,245 @@ +// (C) Copyright John Maddock 2005. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_COMPLEX_ATANH_INCLUDED +#define BOOST_MATH_COMPLEX_ATANH_INCLUDED + +#ifndef BOOST_MATH_COMPLEX_DETAILS_INCLUDED +# include <boost/math/complex/details.hpp> +#endif +#ifndef BOOST_MATH_LOG1P_INCLUDED +# include <boost/math/special_functions/log1p.hpp> +#endif +#include <boost/assert.hpp> + +#ifdef BOOST_NO_STDC_NAMESPACE +namespace std{ using ::sqrt; using ::fabs; using ::acos; using ::asin; using ::atan; using ::atan2; } +#endif + +namespace boost{ namespace math{ + +template<class T> +std::complex<T> atanh(const std::complex<T>& z) +{ + // + // References: + // + // Eric W. Weisstein. "Inverse Hyperbolic Tangent." + // From MathWorld--A Wolfram Web Resource. + // http://mathworld.wolfram.com/InverseHyperbolicTangent.html + // + // Also: The Wolfram Functions Site, + // http://functions.wolfram.com/ElementaryFunctions/ArcTanh/ + // + // Also "Abramowitz and Stegun. Handbook of Mathematical Functions." + // at : http://jove.prohosting.com/~skripty/toc.htm + // + + static const T half_pi = static_cast<T>(1.57079632679489661923132169163975144L); + static const T pi = static_cast<T>(3.141592653589793238462643383279502884197L); + static const T one = static_cast<T>(1.0L); + static const T two = static_cast<T>(2.0L); + static const T four = static_cast<T>(4.0L); + static const T zero = static_cast<T>(0); + static const T a_crossover = static_cast<T>(0.3L); + + T x = std::fabs(z.real()); + T y = std::fabs(z.imag()); + + T real, imag; // our results + + T safe_upper = detail::safe_max(two); + T safe_lower = detail::safe_min(static_cast<T>(2)); + + // + // Begin by handling the special cases specified in C99: + // + if(detail::test_is_nan(x)) + { + if(detail::test_is_nan(y)) + return std::complex<T>(x, x); + else if(std::numeric_limits<T>::has_infinity && (y == std::numeric_limits<T>::infinity())) + return std::complex<T>(0, ((z.imag() < 0) ? -half_pi : half_pi)); + else + return std::complex<T>(x, x); + } + else if(detail::test_is_nan(y)) + { + if(x == 0) + return std::complex<T>(x, y); + if(std::numeric_limits<T>::has_infinity && (x == std::numeric_limits<T>::infinity())) + return std::complex<T>(0, y); + else + return std::complex<T>(y, y); + } + else if((x > safe_lower) && (x < safe_upper) && (y > safe_lower) && (y < safe_upper)) + { + + T xx = x*x; + T yy = y*y; + T x2 = x * two; + + /// + // The real part is given by: + // + // real(atanh(z)) == log((1 + x^2 + y^2 + 2x) / (1 + x^2 + y^2 - 2x)) + // + // However, when x is either large (x > 1/E) or very small + // (x < E) then this effectively simplifies + // to log(1), leading to wildly inaccurate results. + // By dividing the above (top and bottom) by (1 + x^2 + y^2) we get: + // + // real(atanh(z)) == log((1 + (2x / (1 + x^2 + y^2))) / (1 - (-2x / (1 + x^2 + y^2)))) + // + // which is much more sensitive to the value of x, when x is not near 1 + // (remember we can compute log(1+x) for small x very accurately). + // + // The cross-over from one method to the other has to be determined + // experimentally, the value used below appears correct to within a + // factor of 2 (and there are larger errors from other parts + // of the input domain anyway). + // + T alpha = two*x / (one + xx + yy); + if(alpha < a_crossover) + { + real = boost::math::log1p(alpha) - boost::math::log1p(-alpha); + } + else + { + T xm1 = x - one; + real = boost::math::log1p(x2 + xx + yy) - std::log(xm1*xm1 + yy); + } + real /= four; + if(z.real() < 0) + real = -real; + + imag = std::atan2((y * two), (one - xx - yy)); + imag /= two; + if(z.imag() < 0) + imag = -imag; + } + else + { + // + // This section handles exception cases that would normally cause + // underflow or overflow in the main formulas. + // + // Begin by working out the real part, we need to approximate + // alpha = 2x / (1 + x^2 + y^2) + // without either overflow or underflow in the squared terms. + // + T alpha = 0; + if(x >= safe_upper) + { + // this is really a test for infinity, + // but we may not have the necessary numeric_limits support: + if((x > (std::numeric_limits<T>::max)()) || (y > (std::numeric_limits<T>::max)())) + { + alpha = 0; + } + else if(y >= safe_upper) + { + // Big x and y: divide alpha through by x*y: + alpha = (two/y) / (x/y + y/x); + } + else if(y > one) + { + // Big x: divide through by x: + alpha = two / (x + y*y/x); + } + else + { + // Big x small y, as above but neglect y^2/x: + alpha = two/x; + } + } + else if(y >= safe_upper) + { + if(x > one) + { + // Big y, medium x, divide through by y: + alpha = (two*x/y) / (y + x*x/y); + } + else + { + // Small x and y, whatever alpha is, it's too small to calculate: + alpha = 0; + } + } + else + { + // one or both of x and y are small, calculate divisor carefully: + T div = one; + if(x > safe_lower) + div += x*x; + if(y > safe_lower) + div += y*y; + alpha = two*x/div; + } + if(alpha < a_crossover) + { + real = boost::math::log1p(alpha) - boost::math::log1p(-alpha); + } + else + { + // We can only get here as a result of small y and medium sized x, + // we can simply neglect the y^2 terms: + BOOST_ASSERT(x >= safe_lower); + BOOST_ASSERT(x <= safe_upper); + //BOOST_ASSERT(y <= safe_lower); + T xm1 = x - one; + real = std::log(1 + two*x + x*x) - std::log(xm1*xm1); + } + + real /= four; + if(z.real() < 0) + real = -real; + + // + // Now handle imaginary part, this is much easier, + // if x or y are large, then the formula: + // atan2(2y, 1 - x^2 - y^2) + // evaluates to +-(PI - theta) where theta is negligible compared to PI. + // + if((x >= safe_upper) || (y >= safe_upper)) + { + imag = pi; + } + else if(x <= safe_lower) + { + // + // If both x and y are small then atan(2y), + // otherwise just x^2 is negligible in the divisor: + // + if(y <= safe_lower) + imag = std::atan2(two*y, one); + else + { + if((y == zero) && (x == zero)) + imag = 0; + else + imag = std::atan2(two*y, one - y*y); + } + } + else + { + // + // y^2 is negligible: + // + if((y == zero) && (x == one)) + imag = 0; + else + imag = std::atan2(two*y, 1 - x*x); + } + imag /= two; + if(z.imag() < 0) + imag = -imag; + } + return std::complex<T>(real, imag); +} + +} } // namespaces + +#endif // BOOST_MATH_COMPLEX_ATANH_INCLUDED diff --git a/Utilities/BGL/boost/math/complex/details.hpp b/Utilities/BGL/boost/math/complex/details.hpp new file mode 100644 index 0000000000000000000000000000000000000000..ebb892048cfdcf24742e89c5fc4e51c604a82ef2 --- /dev/null +++ b/Utilities/BGL/boost/math/complex/details.hpp @@ -0,0 +1,104 @@ +// (C) Copyright John Maddock 2005. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_COMPLEX_DETAILS_INCLUDED +#define BOOST_MATH_COMPLEX_DETAILS_INCLUDED +// +// This header contains all the support code that is common to the +// inverse trig complex functions, it also contains all the includes +// that we need to implement all these functions. +// +#include <boost/config.hpp> +#include <boost/detail/workaround.hpp> +#include <boost/config/no_tr1/complex.hpp> +#include <boost/limits.hpp> +#include <math.h> // isnan where available +#include <boost/config/no_tr1/cmath.hpp> + +#ifdef BOOST_NO_STDC_NAMESPACE +namespace std{ using ::sqrt; } +#endif + +namespace boost{ namespace math{ namespace detail{ + +template <class T> +inline bool test_is_nan(T t) +{ + // Comparisons with Nan's always fail: + return std::numeric_limits<T>::has_infinity && (!(t <= std::numeric_limits<T>::infinity()) || !(t >= -std::numeric_limits<T>::infinity())); +} +#ifdef isnan +template<> inline bool test_is_nan<float>(float t) { return isnan(t); } +template<> inline bool test_is_nan<double>(double t) { return isnan(t); } +template<> inline bool test_is_nan<long double>(long double t) { return isnan(t); } +#endif + +template <class T> +inline T mult_minus_one(const T& t) +{ + return test_is_nan(t) ? t : -t; +} + +template <class T> +inline std::complex<T> mult_i(const std::complex<T>& t) +{ + return std::complex<T>(mult_minus_one(t.imag()), t.real()); +} + +template <class T> +inline std::complex<T> mult_minus_i(const std::complex<T>& t) +{ + return std::complex<T>(t.imag(), mult_minus_one(t.real())); +} + +template <class T> +inline T safe_max(T t) +{ + return std::sqrt((std::numeric_limits<T>::max)()) / t; +} +inline long double safe_max(long double t) +{ + // long double sqrt often returns infinity due to + // insufficient internal precision: + return std::sqrt((std::numeric_limits<double>::max)()) / t; +} +#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) +// workaround for type deduction bug: +inline float safe_max(float t) +{ + return std::sqrt((std::numeric_limits<float>::max)()) / t; +} +inline double safe_max(double t) +{ + return std::sqrt((std::numeric_limits<double>::max)()) / t; +} +#endif +template <class T> +inline T safe_min(T t) +{ + return std::sqrt((std::numeric_limits<T>::min)()) * t; +} +inline long double safe_min(long double t) +{ + // long double sqrt often returns zero due to + // insufficient internal precision: + return std::sqrt((std::numeric_limits<double>::min)()) * t; +} +#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) +// type deduction workaround: +inline double safe_min(double t) +{ + return std::sqrt((std::numeric_limits<double>::min)()) * t; +} +inline float safe_min(float t) +{ + return std::sqrt((std::numeric_limits<float>::min)()) * t; +} +#endif + +} } } // namespaces + +#endif // BOOST_MATH_COMPLEX_DETAILS_INCLUDED + diff --git a/Utilities/BGL/boost/math/complex/fabs.hpp b/Utilities/BGL/boost/math/complex/fabs.hpp new file mode 100644 index 0000000000000000000000000000000000000000..78bb0021a2c6ea31877f63924e5694390fa15214 --- /dev/null +++ b/Utilities/BGL/boost/math/complex/fabs.hpp @@ -0,0 +1,23 @@ +// (C) Copyright John Maddock 2005. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_COMPLEX_FABS_INCLUDED +#define BOOST_MATH_COMPLEX_FABS_INCLUDED + +#ifndef BOOST_MATH_HYPOT_INCLUDED +# include <boost/math/special_functions/hypot.hpp> +#endif + +namespace boost{ namespace math{ + +template<class T> +inline T fabs(const std::complex<T>& z) +{ + return ::boost::math::hypot(z.real(), z.imag()); +} + +} } // namespaces + +#endif // BOOST_MATH_COMPLEX_FABS_INCLUDED diff --git a/Utilities/BGL/boost/math/concepts/distributions.hpp b/Utilities/BGL/boost/math/concepts/distributions.hpp new file mode 100644 index 0000000000000000000000000000000000000000..610c9d58de21e7ee815acbc4d776eda120eb8bde --- /dev/null +++ b/Utilities/BGL/boost/math/concepts/distributions.hpp @@ -0,0 +1,206 @@ +// Copyright John Maddock 2006. +// Use, modification and distribution are subject to 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) + +// distributions.hpp provides definitions of the concept of a distribution +// and non-member accessor functions that must be implemented by all distributions. +// This is used to verify that +// all the features of a distributions have been fully implemented. + +#ifndef BOOST_MATH_DISTRIBUTION_CONCEPT_HPP +#define BOOST_MATH_DISTRIBUTION_CONCEPT_HPP + +#include <boost/math/distributions/complement.hpp> +#ifdef BOOST_MSVC +#pragma warning(push) +#pragma warning(disable: 4100) +#pragma warning(disable: 4510) +#pragma warning(disable: 4610) +#endif +#include <boost/concept_check.hpp> +#ifdef BOOST_MSVC +#pragma warning(pop) +#endif +#include <utility> + +namespace boost{ +namespace math{ + +namespace concepts +{ +// Begin by defining a concept archetype +// for a distribution class: +// +template <class RealType> +class distribution_archetype +{ +public: + typedef RealType value_type; + + distribution_archetype(const distribution_archetype&); // Copy constructible. + distribution_archetype& operator=(const distribution_archetype&); // Assignable. + + // There is no default constructor, + // but we need a way to instantiate the archetype: + static distribution_archetype& get_object() + { + // will never get caled: + return *reinterpret_cast<distribution_archetype*>(0); + } +}; // template <class RealType>class distribution_archetype + +// Non-member accessor functions: +// (This list defines the functions that must be implemented by all distributions). + +template <class RealType> +RealType pdf(const distribution_archetype<RealType>& dist, const RealType& x); + +template <class RealType> +RealType cdf(const distribution_archetype<RealType>& dist, const RealType& x); + +template <class RealType> +RealType quantile(const distribution_archetype<RealType>& dist, const RealType& p); + +template <class RealType> +RealType cdf(const complemented2_type<distribution_archetype<RealType>, RealType>& c); + +template <class RealType> +RealType quantile(const complemented2_type<distribution_archetype<RealType>, RealType>& c); + +template <class RealType> +RealType mean(const distribution_archetype<RealType>& dist); + +template <class RealType> +RealType standard_deviation(const distribution_archetype<RealType>& dist); + +template <class RealType> +RealType variance(const distribution_archetype<RealType>& dist); + +template <class RealType> +RealType hazard(const distribution_archetype<RealType>& dist); + +template <class RealType> +RealType chf(const distribution_archetype<RealType>& dist); +// http://en.wikipedia.org/wiki/Characteristic_function_%28probability_theory%29 + +template <class RealType> +RealType coefficient_of_variation(const distribution_archetype<RealType>& dist); + +template <class RealType> +RealType mode(const distribution_archetype<RealType>& dist); + +template <class RealType> +RealType skewness(const distribution_archetype<RealType>& dist); + +template <class RealType> +RealType kurtosis_excess(const distribution_archetype<RealType>& dist); + +template <class RealType> +RealType kurtosis(const distribution_archetype<RealType>& dist); + +template <class RealType> +RealType median(const distribution_archetype<RealType>& dist); + +template <class RealType> +std::pair<RealType, RealType> range(const distribution_archetype<RealType>& dist); + +template <class RealType> +std::pair<RealType, RealType> support(const distribution_archetype<RealType>& dist); + +// +// Next comes the concept checks for verifying that a class +// fullfils the requirements of a Distribution: +// +template <class Distribution> +struct DistributionConcept +{ + void constraints() + { + function_requires<CopyConstructibleConcept<Distribution> >(); + function_requires<AssignableConcept<Distribution> >(); + + typedef typename Distribution::value_type value_type; + + const Distribution& dist = DistributionConcept<Distribution>::get_object(); + + value_type x = 0; + // The result values are ignored in all these checks. + value_type v = cdf(dist, x); + v = cdf(complement(dist, x)); + v = pdf(dist, x); + v = quantile(dist, x); + v = quantile(complement(dist, x)); + v = mean(dist); + v = mode(dist); + v = standard_deviation(dist); + v = variance(dist); + v = hazard(dist, x); + v = chf(dist, x); + v = coefficient_of_variation(dist); + v = skewness(dist); + v = kurtosis(dist); + v = kurtosis_excess(dist); + v = median(dist); + std::pair<value_type, value_type> pv; + pv = range(dist); + pv = support(dist); + + float f = 1; + v = cdf(dist, f); + v = cdf(complement(dist, f)); + v = pdf(dist, f); + v = quantile(dist, f); + v = quantile(complement(dist, f)); + v = hazard(dist, f); + v = chf(dist, f); + double d = 1; + v = cdf(dist, d); + v = cdf(complement(dist, d)); + v = pdf(dist, d); + v = quantile(dist, d); + v = quantile(complement(dist, d)); + v = hazard(dist, d); + v = chf(dist, d); +#ifndef TEST_MPFR + long double ld = 1; + v = cdf(dist, ld); + v = cdf(complement(dist, ld)); + v = pdf(dist, ld); + v = quantile(dist, ld); + v = quantile(complement(dist, ld)); + v = hazard(dist, ld); + v = chf(dist, ld); +#endif + int i = 1; + v = cdf(dist, i); + v = cdf(complement(dist, i)); + v = pdf(dist, i); + v = quantile(dist, i); + v = quantile(complement(dist, i)); + v = hazard(dist, i); + v = chf(dist, i); + unsigned long li = 1; + v = cdf(dist, li); + v = cdf(complement(dist, li)); + v = pdf(dist, li); + v = quantile(dist, li); + v = quantile(complement(dist, li)); + v = hazard(dist, li); + v = chf(dist, li); + } +private: + static Distribution& get_object() + { + // will never get called: + static char buf[sizeof(Distribution)]; + return * reinterpret_cast<Distribution*>(buf); + } +}; // struct DistributionConcept + +} // namespace concepts +} // namespace math +} // namespace boost + +#endif // BOOST_MATH_DISTRIBUTION_CONCEPT_HPP + diff --git a/Utilities/BGL/boost/math/concepts/real_concept.hpp b/Utilities/BGL/boost/math/concepts/real_concept.hpp new file mode 100644 index 0000000000000000000000000000000000000000..e40aa9db7332cc1e9e4d813187780189e78e8c55 --- /dev/null +++ b/Utilities/BGL/boost/math/concepts/real_concept.hpp @@ -0,0 +1,441 @@ +// Copyright John Maddock 2006. +// Use, modification and distribution are subject to 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) + +// Test real concept. + +// real_concept is an archetype for User defined Real types. + +// This file defines the features, constructors, operators, functions... +// that are essential to use mathematical and statistical functions. +// The template typename "RealType" is used where this type +// (as well as the normal built-in types, float, double & long double) +// can be used. +// That this is the minimum set is confirmed by use as a type +// in tests of all functions & distributions, for example: +// test_spots(0.F); & test_spots(0.); for float and double, but also +// test_spots(boost::math::concepts::real_concept(0.)); +// NTL quad_float type is an example of a type meeting the requirements, +// but note minor additions are needed - see ntl.diff and documentation +// "Using With NTL - a High-Precision Floating-Point Library". + +#ifndef BOOST_MATH_REAL_CONCEPT_HPP +#define BOOST_MATH_REAL_CONCEPT_HPP + +#include <boost/config.hpp> +#include <boost/limits.hpp> +#include <boost/math/special_functions/round.hpp> +#include <boost/math/special_functions/trunc.hpp> +#include <boost/math/special_functions/modf.hpp> +#include <boost/math/tools/precision.hpp> +#include <boost/math/policies/policy.hpp> +#if defined(__SGI_STL_PORT) +# include <boost/math/tools/real_cast.hpp> +#endif +#include <ostream> +#include <istream> +#include <boost/config/no_tr1/cmath.hpp> +#include <math.h> // fmodl + +#if defined(__SGI_STL_PORT) || defined(_RWSTD_VER) || defined(__LIBCOMO__) +# include <cstdio> +#endif + +namespace boost{ namespace math{ + +namespace concepts +{ + +#ifdef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS + typedef double real_concept_base_type; +#else + typedef long double real_concept_base_type; +#endif + +class real_concept +{ +public: + // Constructors: + real_concept() : m_value(0){} + real_concept(char c) : m_value(c){} +#ifndef BOOST_NO_INTRINSIC_WCHAR_T + real_concept(wchar_t c) : m_value(c){} +#endif + real_concept(unsigned char c) : m_value(c){} + real_concept(signed char c) : m_value(c){} + real_concept(unsigned short c) : m_value(c){} + real_concept(short c) : m_value(c){} + real_concept(unsigned int c) : m_value(c){} + real_concept(int c) : m_value(c){} + real_concept(unsigned long c) : m_value(c){} + real_concept(long c) : m_value(c){} +#if defined(__DECCXX) || defined(__SUNPRO_CC) + real_concept(unsigned long long c) : m_value(static_cast<real_concept_base_type>(c)){} + real_concept(long long c) : m_value(static_cast<real_concept_base_type>(c)){} +#elif defined(BOOST_HAS_LONG_LONG) + real_concept(boost::ulong_long_type c) : m_value(static_cast<real_concept_base_type>(c)){} + real_concept(boost::long_long_type c) : m_value(static_cast<real_concept_base_type>(c)){} +#elif defined(BOOST_HAS_MS_INT64) + real_concept(unsigned __int64 c) : m_value(static_cast<real_concept_base_type>(c)){} + real_concept(__int64 c) : m_value(static_cast<real_concept_base_type>(c)){} +#endif + real_concept(float c) : m_value(c){} + real_concept(double c) : m_value(c){} + real_concept(long double c) : m_value(c){} + + // Assignment: + real_concept& operator=(char c) { m_value = c; return *this; } + real_concept& operator=(unsigned char c) { m_value = c; return *this; } + real_concept& operator=(signed char c) { m_value = c; return *this; } +#ifndef BOOST_NO_INTRINSIC_WCHAR_T + real_concept& operator=(wchar_t c) { m_value = c; return *this; } +#endif + real_concept& operator=(short c) { m_value = c; return *this; } + real_concept& operator=(unsigned short c) { m_value = c; return *this; } + real_concept& operator=(int c) { m_value = c; return *this; } + real_concept& operator=(unsigned int c) { m_value = c; return *this; } + real_concept& operator=(long c) { m_value = c; return *this; } + real_concept& operator=(unsigned long c) { m_value = c; return *this; } +#ifdef BOOST_HAS_LONG_LONG + real_concept& operator=(boost::long_long_type c) { m_value = static_cast<real_concept_base_type>(c); return *this; } + real_concept& operator=(boost::ulong_long_type c) { m_value = static_cast<real_concept_base_type>(c); return *this; } +#endif + real_concept& operator=(float c) { m_value = c; return *this; } + real_concept& operator=(double c) { m_value = c; return *this; } + real_concept& operator=(long double c) { m_value = c; return *this; } + + // Access: + real_concept_base_type value()const{ return m_value; } + + // Member arithmetic: + real_concept& operator+=(const real_concept& other) + { m_value += other.value(); return *this; } + real_concept& operator-=(const real_concept& other) + { m_value -= other.value(); return *this; } + real_concept& operator*=(const real_concept& other) + { m_value *= other.value(); return *this; } + real_concept& operator/=(const real_concept& other) + { m_value /= other.value(); return *this; } + real_concept operator-()const + { return -m_value; } + real_concept const& operator+()const + { return *this; } + real_concept& operator++() + { ++m_value; return *this; } + real_concept& operator--() + { --m_value; return *this; } + +private: + real_concept_base_type m_value; +}; + +// Non-member arithmetic: +inline real_concept operator+(const real_concept& a, const real_concept& b) +{ + real_concept result(a); + result += b; + return result; +} +inline real_concept operator-(const real_concept& a, const real_concept& b) +{ + real_concept result(a); + result -= b; + return result; +} +inline real_concept operator*(const real_concept& a, const real_concept& b) +{ + real_concept result(a); + result *= b; + return result; +} +inline real_concept operator/(const real_concept& a, const real_concept& b) +{ + real_concept result(a); + result /= b; + return result; +} + +// Comparison: +inline bool operator == (const real_concept& a, const real_concept& b) +{ return a.value() == b.value(); } +inline bool operator != (const real_concept& a, const real_concept& b) +{ return a.value() != b.value();} +inline bool operator < (const real_concept& a, const real_concept& b) +{ return a.value() < b.value(); } +inline bool operator <= (const real_concept& a, const real_concept& b) +{ return a.value() <= b.value(); } +inline bool operator > (const real_concept& a, const real_concept& b) +{ return a.value() > b.value(); } +inline bool operator >= (const real_concept& a, const real_concept& b) +{ return a.value() >= b.value(); } + +// Non-member functions: +inline real_concept acos(real_concept a) +{ return std::acos(a.value()); } +inline real_concept cos(real_concept a) +{ return std::cos(a.value()); } +inline real_concept asin(real_concept a) +{ return std::asin(a.value()); } +inline real_concept atan(real_concept a) +{ return std::atan(a.value()); } +inline real_concept atan2(real_concept a, real_concept b) +{ return std::atan2(a.value(), b.value()); } +inline real_concept ceil(real_concept a) +{ return std::ceil(a.value()); } +#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS +// I've seen std::fmod(long double) crash on some platforms +// so use fmodl instead: +#ifdef _WIN32_WCE +// +// Ugly workaround for macro fmodl: +// +inline long double call_fmodl(long double a, long double b) +{ return fmodl(a, b); } +inline real_concept fmod(real_concept a, real_concept b) +{ return call_fmodl(a.value(), b.value()); } +#else +inline real_concept fmod(real_concept a, real_concept b) +{ return fmodl(a.value(), b.value()); } +#endif +#endif +inline real_concept cosh(real_concept a) +{ return std::cosh(a.value()); } +inline real_concept exp(real_concept a) +{ return std::exp(a.value()); } +inline real_concept fabs(real_concept a) +{ return std::fabs(a.value()); } +inline real_concept abs(real_concept a) +{ return std::abs(a.value()); } +inline real_concept floor(real_concept a) +{ return std::floor(a.value()); } +inline real_concept modf(real_concept a, real_concept* ipart) +{ + real_concept_base_type ip; + real_concept_base_type result = std::modf(a.value(), &ip); + *ipart = ip; + return result; +} +inline real_concept frexp(real_concept a, int* expon) +{ return std::frexp(a.value(), expon); } +inline real_concept ldexp(real_concept a, int expon) +{ return std::ldexp(a.value(), expon); } +inline real_concept log(real_concept a) +{ return std::log(a.value()); } +inline real_concept log10(real_concept a) +{ return std::log10(a.value()); } +inline real_concept tan(real_concept a) +{ return std::tan(a.value()); } +inline real_concept pow(real_concept a, real_concept b) +{ return std::pow(a.value(), b.value()); } +#if !defined(__SUNPRO_CC) +inline real_concept pow(real_concept a, int b) +{ return std::pow(a.value(), b); } +#else +inline real_concept pow(real_concept a, int b) +{ return std::pow(a.value(), static_cast<real_concept_base_type>(b)); } +#endif +inline real_concept sin(real_concept a) +{ return std::sin(a.value()); } +inline real_concept sinh(real_concept a) +{ return std::sinh(a.value()); } +inline real_concept sqrt(real_concept a) +{ return std::sqrt(a.value()); } +inline real_concept tanh(real_concept a) +{ return std::tanh(a.value()); } + +// +// Conversion and truncation routines: +// +template <class Policy> +inline int iround(const concepts::real_concept& v, const Policy& pol) +{ return boost::math::iround(v.value(), pol); } +inline int iround(const concepts::real_concept& v) +{ return boost::math::iround(v.value(), policies::policy<>()); } +template <class Policy> +inline long lround(const concepts::real_concept& v, const Policy& pol) +{ return boost::math::lround(v.value(), pol); } +inline long lround(const concepts::real_concept& v) +{ return boost::math::lround(v.value(), policies::policy<>()); } + +#ifdef BOOST_HAS_LONG_LONG +template <class Policy> +inline boost::long_long_type llround(const concepts::real_concept& v, const Policy& pol) +{ return boost::math::llround(v.value(), pol); } +inline boost::long_long_type llround(const concepts::real_concept& v) +{ return boost::math::llround(v.value(), policies::policy<>()); } +#endif + +template <class Policy> +inline int itrunc(const concepts::real_concept& v, const Policy& pol) +{ return boost::math::itrunc(v.value(), pol); } +inline int itrunc(const concepts::real_concept& v) +{ return boost::math::itrunc(v.value(), policies::policy<>()); } +template <class Policy> +inline long ltrunc(const concepts::real_concept& v, const Policy& pol) +{ return boost::math::ltrunc(v.value(), pol); } +inline long ltrunc(const concepts::real_concept& v) +{ return boost::math::ltrunc(v.value(), policies::policy<>()); } + +#ifdef BOOST_HAS_LONG_LONG +template <class Policy> +inline boost::long_long_type lltrunc(const concepts::real_concept& v, const Policy& pol) +{ return boost::math::lltrunc(v.value(), pol); } +inline boost::long_long_type lltrunc(const concepts::real_concept& v) +{ return boost::math::lltrunc(v.value(), policies::policy<>()); } +#endif + +// Streaming: +template <class charT, class traits> +inline std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& os, const real_concept& a) +{ + return os << a.value(); +} +template <class charT, class traits> +inline std::basic_istream<charT, traits>& operator>>(std::basic_istream<charT, traits>& is, real_concept& a) +{ +#if defined(BOOST_MSVC) && defined(__SGI_STL_PORT) + // + // STLPort 5.1.4 has a problem reading long doubles from strings, + // see http://sourceforge.net/tracker/index.php?func=detail&aid=1811043&group_id=146814&atid=766244 + // + double v; + is >> v; + a = v; + return is; +#elif defined(__SGI_STL_PORT) || defined(_RWSTD_VER) || defined(__LIBCOMO__) + std::string s; + real_concept_base_type d; + is >> s; + std::sscanf(s.c_str(), "%Lf", &d); + a = d; + return is; +#else + real_concept_base_type v; + is >> v; + a = v; + return is; +#endif +} + +} // namespace concepts + +namespace tools +{ + +template <> +inline concepts::real_concept max_value<concepts::real_concept>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(concepts::real_concept)) +{ + return max_value<concepts::real_concept_base_type>(); +} + +template <> +inline concepts::real_concept min_value<concepts::real_concept>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(concepts::real_concept)) +{ + return min_value<concepts::real_concept_base_type>(); +} + +template <> +inline concepts::real_concept log_max_value<concepts::real_concept>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(concepts::real_concept)) +{ + return log_max_value<concepts::real_concept_base_type>(); +} + +template <> +inline concepts::real_concept log_min_value<concepts::real_concept>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(concepts::real_concept)) +{ + return log_min_value<concepts::real_concept_base_type>(); +} + +template <> +inline concepts::real_concept epsilon<concepts::real_concept>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(concepts::real_concept)) +{ +#ifdef __SUNPRO_CC + return std::numeric_limits<concepts::real_concept_base_type>::epsilon(); +#else + return tools::epsilon<concepts::real_concept_base_type>(); +#endif +} + +template <> +inline int digits<concepts::real_concept>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(concepts::real_concept)) +{ + // Assume number of significand bits is same as real_concept_base_type, + // unless std::numeric_limits<T>::is_specialized to provide digits. + return tools::digits<concepts::real_concept_base_type>(); + // Note that if numeric_limits real concept is NOT specialized to provide digits10 + // (or max_digits10) then the default precision of 6 decimal digits will be used + // by Boost test (giving misleading error messages like + // "difference between {9.79796} and {9.79796} exceeds 5.42101e-19%" + // and by Boost lexical cast and serialization causing loss of accuracy. +} + +} // namespace tools + +#if defined(__SGI_STL_PORT) +// +// We shouldn't really need these type casts any more, but there are some +// STLport iostream bugs we work around by using them.... +// +namespace tools +{ +// real_cast converts from T to integer and narrower floating-point types. + +// Convert from T to integer types. + +template <> +inline unsigned int real_cast<unsigned int, concepts::real_concept>(concepts::real_concept r) +{ + return static_cast<unsigned int>(r.value()); +} + +template <> +inline int real_cast<int, concepts::real_concept>(concepts::real_concept r) +{ + return static_cast<int>(r.value()); +} + +template <> +inline long real_cast<long, concepts::real_concept>(concepts::real_concept r) +{ + return static_cast<long>(r.value()); +} + +// Converts from T to narrower floating-point types, float, double & long double. + +template <> +inline float real_cast<float, concepts::real_concept>(concepts::real_concept r) +{ + return static_cast<float>(r.value()); +} +template <> +inline double real_cast<double, concepts::real_concept>(concepts::real_concept r) +{ + return static_cast<double>(r.value()); +} +template <> +inline long double real_cast<long double, concepts::real_concept>(concepts::real_concept r) +{ + return r.value(); +} + +} // STLPort + +#endif + +#if BOOST_WORKAROUND(BOOST_MSVC, <= 1310) +// +// For some strange reason ADL sometimes fails to find the +// correct overloads, unless we bring these declarations into scope: +// +using concepts::itrunc; +using concepts::iround; + +#endif + +} // namespace math +} // namespace boost + +#endif // BOOST_MATH_REAL_CONCEPT_HPP + + diff --git a/Utilities/BGL/boost/math/concepts/real_type_concept.hpp b/Utilities/BGL/boost/math/concepts/real_type_concept.hpp new file mode 100644 index 0000000000000000000000000000000000000000..308462bffcf722484681b4d13b32521cefb32702 --- /dev/null +++ b/Utilities/BGL/boost/math/concepts/real_type_concept.hpp @@ -0,0 +1,109 @@ +// Copyright John Maddock 2007-8. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_REAL_TYPE_CONCEPT_HPP +#define BOOST_MATH_REAL_TYPE_CONCEPT_HPP + +#ifdef BOOST_MSVC +#pragma warning(push) +#pragma warning(disable: 4100) +#pragma warning(disable: 4510) +#pragma warning(disable: 4610) +#endif +#include <boost/concept_check.hpp> +#ifdef BOOST_MSVC +#pragma warning(pop) +#endif +#include <boost/math/tools/config.hpp> +#include <boost/math/tools/precision.hpp> + + +namespace boost{ namespace math{ namespace concepts{ + +template <class RealType> +struct RealTypeConcept +{ + template <class Other> + void check_binary_ops(Other o) + { + RealType r(o); + r = o; + r -= o; + r += o; + r *= o; + r /= o; + r = r - o; + r = o - r; + r = r + o; + r = o + r; + r = o * r; + r = r * o; + r = r / o; + r = o / r; + bool b; + b = r == o; + b = o == r; + b = r != o; + b = o != r; + b = r <= o; + b = o <= r; + b = r >= o; + b = o >= r; + b = r < o; + b = o < r; + b = r > o; + b = o > r; + } + + void constraints() + { + BOOST_MATH_STD_USING + + RealType r; + check_binary_ops(r); + check_binary_ops(0.5f); + check_binary_ops(0.5); + //check_binary_ops(0.5L); + check_binary_ops(1); + //check_binary_ops(1u); + check_binary_ops(1L); + //check_binary_ops(1uL); +#ifndef BOOST_HAS_LONG_LONG + check_binary_ops(1LL); +#endif + RealType r2 = +r; + r2 = -r; + + r2 = fabs(r); + r2 = abs(r); + r2 = ceil(r); + r2 = floor(r); + r2 = exp(r); + r2 = pow(r, r2); + r2 = sqrt(r); + r2 = log(r); + r2 = cos(r); + r2 = sin(r); + r2 = tan(r); + r2 = asin(r); + r2 = acos(r); + r2 = atan(r); + int i; + r2 = ldexp(r, i); + r2 = frexp(r, &i); + i = boost::math::tools::digits<RealType>(); + r2 = boost::math::tools::max_value<RealType>(); + r2 = boost::math::tools::min_value<RealType>(); + r2 = boost::math::tools::log_max_value<RealType>(); + r2 = boost::math::tools::log_min_value<RealType>(); + r2 = boost::math::tools::epsilon<RealType>(); + } +}; // struct DistributionConcept + + +}}} // namespaces + +#endif + diff --git a/Utilities/BGL/boost/math/concepts/std_real_concept.hpp b/Utilities/BGL/boost/math/concepts/std_real_concept.hpp new file mode 100644 index 0000000000000000000000000000000000000000..6ca84a86399da910494f5dc057b50e444e97bd10 --- /dev/null +++ b/Utilities/BGL/boost/math/concepts/std_real_concept.hpp @@ -0,0 +1,386 @@ +// Copyright John Maddock 2006. +// Use, modification and distribution are subject to 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) + +// std_real_concept is an archetype for built-in Real types. + +// The main purpose in providing this type is to verify +// that std lib functions are found via a using declaration +// bringing those functions into the current scope, and not +// just because they happen to be in global scope. +// +// If ::pow is found rather than std::pow say, then the code +// will silently compile, but truncation of long doubles to +// double will cause a significant loss of precision. +// A template instantiated with std_real_concept will *only* +// compile if it std::whatever is in scope. + +#include <boost/config.hpp> +#include <boost/limits.hpp> +#include <boost/math/policies/policy.hpp> +#include <boost/math/special_functions/math_fwd.hpp> + +#include <ostream> +#include <istream> +#include <boost/config/no_tr1/cmath.hpp> +#include <math.h> // fmodl + +#ifndef BOOST_MATH_STD_REAL_CONCEPT_HPP +#define BOOST_MATH_STD_REAL_CONCEPT_HPP + +namespace boost{ namespace math{ + +namespace concepts +{ + +#ifdef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS + typedef double std_real_concept_base_type; +#else + typedef long double std_real_concept_base_type; +#endif + +class std_real_concept +{ +public: + // Constructors: + std_real_concept() : m_value(0){} + std_real_concept(char c) : m_value(c){} +#ifndef BOOST_NO_INTRINSIC_WCHAR_T + std_real_concept(wchar_t c) : m_value(c){} +#endif + std_real_concept(unsigned char c) : m_value(c){} + std_real_concept(signed char c) : m_value(c){} + std_real_concept(unsigned short c) : m_value(c){} + std_real_concept(short c) : m_value(c){} + std_real_concept(unsigned int c) : m_value(c){} + std_real_concept(int c) : m_value(c){} + std_real_concept(unsigned long c) : m_value(c){} + std_real_concept(long c) : m_value(c){} +#if defined(__DECCXX) || defined(__SUNPRO_CC) + std_real_concept(unsigned long long c) : m_value(static_cast<std_real_concept_base_type>(c)){} + std_real_concept(long long c) : m_value(static_cast<std_real_concept_base_type>(c)){} +#elif defined(BOOST_HAS_LONG_LONG) + std_real_concept(boost::ulong_long_type c) : m_value(static_cast<std_real_concept_base_type>(c)){} + std_real_concept(boost::long_long_type c) : m_value(static_cast<std_real_concept_base_type>(c)){} +#endif + std_real_concept(float c) : m_value(c){} + std_real_concept(double c) : m_value(c){} + std_real_concept(long double c) : m_value(c){} + + // Assignment: + std_real_concept& operator=(char c) { m_value = c; return *this; } + std_real_concept& operator=(unsigned char c) { m_value = c; return *this; } + std_real_concept& operator=(signed char c) { m_value = c; return *this; } +#ifndef BOOST_NO_INTRINSIC_WCHAR_T + std_real_concept& operator=(wchar_t c) { m_value = c; return *this; } +#endif + std_real_concept& operator=(short c) { m_value = c; return *this; } + std_real_concept& operator=(unsigned short c) { m_value = c; return *this; } + std_real_concept& operator=(int c) { m_value = c; return *this; } + std_real_concept& operator=(unsigned int c) { m_value = c; return *this; } + std_real_concept& operator=(long c) { m_value = c; return *this; } + std_real_concept& operator=(unsigned long c) { m_value = c; return *this; } +#if defined(__DECCXX) || defined(__SUNPRO_CC) + std_real_concept& operator=(unsigned long long c) { m_value = static_cast<std_real_concept_base_type>(c); return *this; } + std_real_concept& operator=(long long c) { m_value = static_cast<std_real_concept_base_type>(c); return *this; } +#elif defined(BOOST_HAS_LONG_LONG) + std_real_concept& operator=(boost::long_long_type c) { m_value = static_cast<std_real_concept_base_type>(c); return *this; } + std_real_concept& operator=(boost::ulong_long_type c) { m_value = static_cast<std_real_concept_base_type>(c); return *this; } +#endif + std_real_concept& operator=(float c) { m_value = c; return *this; } + std_real_concept& operator=(double c) { m_value = c; return *this; } + std_real_concept& operator=(long double c) { m_value = c; return *this; } + + // Access: + std_real_concept_base_type value()const{ return m_value; } + + // Member arithmetic: + std_real_concept& operator+=(const std_real_concept& other) + { m_value += other.value(); return *this; } + std_real_concept& operator-=(const std_real_concept& other) + { m_value -= other.value(); return *this; } + std_real_concept& operator*=(const std_real_concept& other) + { m_value *= other.value(); return *this; } + std_real_concept& operator/=(const std_real_concept& other) + { m_value /= other.value(); return *this; } + std_real_concept operator-()const + { return -m_value; } + std_real_concept const& operator+()const + { return *this; } + +private: + std_real_concept_base_type m_value; +}; + +// Non-member arithmetic: +inline std_real_concept operator+(const std_real_concept& a, const std_real_concept& b) +{ + std_real_concept result(a); + result += b; + return result; +} +inline std_real_concept operator-(const std_real_concept& a, const std_real_concept& b) +{ + std_real_concept result(a); + result -= b; + return result; +} +inline std_real_concept operator*(const std_real_concept& a, const std_real_concept& b) +{ + std_real_concept result(a); + result *= b; + return result; +} +inline std_real_concept operator/(const std_real_concept& a, const std_real_concept& b) +{ + std_real_concept result(a); + result /= b; + return result; +} + +// Comparison: +inline bool operator == (const std_real_concept& a, const std_real_concept& b) +{ return a.value() == b.value(); } +inline bool operator != (const std_real_concept& a, const std_real_concept& b) +{ return a.value() != b.value();} +inline bool operator < (const std_real_concept& a, const std_real_concept& b) +{ return a.value() < b.value(); } +inline bool operator <= (const std_real_concept& a, const std_real_concept& b) +{ return a.value() <= b.value(); } +inline bool operator > (const std_real_concept& a, const std_real_concept& b) +{ return a.value() > b.value(); } +inline bool operator >= (const std_real_concept& a, const std_real_concept& b) +{ return a.value() >= b.value(); } + +} // namespace concepts +} // namespace math +} // namespace boost + +namespace std{ + +// Non-member functions: +inline boost::math::concepts::std_real_concept acos(boost::math::concepts::std_real_concept a) +{ return std::acos(a.value()); } +inline boost::math::concepts::std_real_concept cos(boost::math::concepts::std_real_concept a) +{ return std::cos(a.value()); } +inline boost::math::concepts::std_real_concept asin(boost::math::concepts::std_real_concept a) +{ return std::asin(a.value()); } +inline boost::math::concepts::std_real_concept atan(boost::math::concepts::std_real_concept a) +{ return std::atan(a.value()); } +inline boost::math::concepts::std_real_concept atan2(boost::math::concepts::std_real_concept a, boost::math::concepts::std_real_concept b) +{ return std::atan2(a.value(), b.value()); } +inline boost::math::concepts::std_real_concept ceil(boost::math::concepts::std_real_concept a) +{ return std::ceil(a.value()); } +#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS +inline boost::math::concepts::std_real_concept fmod(boost::math::concepts::std_real_concept a, boost::math::concepts::std_real_concept b) +{ return fmodl(a.value(), b.value()); } +#else +inline boost::math::concepts::std_real_concept fmod(boost::math::concepts::std_real_concept a, boost::math::concepts::std_real_concept b) +{ return std::fmod(a.value(), b.value()); } +#endif +inline boost::math::concepts::std_real_concept cosh(boost::math::concepts::std_real_concept a) +{ return std::cosh(a.value()); } +inline boost::math::concepts::std_real_concept exp(boost::math::concepts::std_real_concept a) +{ return std::exp(a.value()); } +inline boost::math::concepts::std_real_concept fabs(boost::math::concepts::std_real_concept a) +{ return std::fabs(a.value()); } +inline boost::math::concepts::std_real_concept abs(boost::math::concepts::std_real_concept a) +{ return std::abs(a.value()); } +inline boost::math::concepts::std_real_concept floor(boost::math::concepts::std_real_concept a) +{ return std::floor(a.value()); } +inline boost::math::concepts::std_real_concept modf(boost::math::concepts::std_real_concept a, boost::math::concepts::std_real_concept* ipart) +{ + boost::math::concepts::std_real_concept_base_type ip; + boost::math::concepts::std_real_concept_base_type result = std::modf(a.value(), &ip); + *ipart = ip; + return result; +} +inline boost::math::concepts::std_real_concept frexp(boost::math::concepts::std_real_concept a, int* expon) +{ return std::frexp(a.value(), expon); } +inline boost::math::concepts::std_real_concept ldexp(boost::math::concepts::std_real_concept a, int expon) +{ return std::ldexp(a.value(), expon); } +inline boost::math::concepts::std_real_concept log(boost::math::concepts::std_real_concept a) +{ return std::log(a.value()); } +inline boost::math::concepts::std_real_concept log10(boost::math::concepts::std_real_concept a) +{ return std::log10(a.value()); } +inline boost::math::concepts::std_real_concept tan(boost::math::concepts::std_real_concept a) +{ return std::tan(a.value()); } +inline boost::math::concepts::std_real_concept pow(boost::math::concepts::std_real_concept a, boost::math::concepts::std_real_concept b) +{ return std::pow(a.value(), b.value()); } +#if !defined(__SUNPRO_CC) +inline boost::math::concepts::std_real_concept pow(boost::math::concepts::std_real_concept a, int b) +{ return std::pow(a.value(), b); } +#else +inline boost::math::concepts::std_real_concept pow(boost::math::concepts::std_real_concept a, int b) +{ return std::pow(a.value(), static_cast<long double>(b)); } +#endif +inline boost::math::concepts::std_real_concept sin(boost::math::concepts::std_real_concept a) +{ return std::sin(a.value()); } +inline boost::math::concepts::std_real_concept sinh(boost::math::concepts::std_real_concept a) +{ return std::sinh(a.value()); } +inline boost::math::concepts::std_real_concept sqrt(boost::math::concepts::std_real_concept a) +{ return std::sqrt(a.value()); } +inline boost::math::concepts::std_real_concept tanh(boost::math::concepts::std_real_concept a) +{ return std::tanh(a.value()); } + +} // namespace std + +#include <boost/math/special_functions/round.hpp> +#include <boost/math/special_functions/trunc.hpp> +#include <boost/math/special_functions/modf.hpp> +#include <boost/math/tools/precision.hpp> + +namespace boost{ namespace math{ namespace concepts{ + +// +// Conversion and truncation routines: +// +template <class Policy> +inline int iround(const concepts::std_real_concept& v, const Policy& pol) +{ + return boost::math::iround(v.value(), pol); +} +inline int iround(const concepts::std_real_concept& v) +{ + return boost::math::iround(v.value(), policies::policy<>()); +} + +template <class Policy> +inline long lround(const concepts::std_real_concept& v, const Policy& pol) +{ + return boost::math::lround(v.value(), pol); +} +inline long lround(const concepts::std_real_concept& v) +{ + return boost::math::lround(v.value(), policies::policy<>()); +} + +#ifdef BOOST_HAS_LONG_LONG + +template <class Policy> +inline boost::long_long_type llround(const concepts::std_real_concept& v, const Policy& pol) +{ + return boost::math::llround(v.value(), pol); +} +inline boost::long_long_type llround(const concepts::std_real_concept& v) +{ + return boost::math::llround(v.value(), policies::policy<>()); +} + +#endif + +template <class Policy> +inline int itrunc(const concepts::std_real_concept& v, const Policy& pol) +{ + return boost::math::itrunc(v.value(), pol); +} +inline int itrunc(const concepts::std_real_concept& v) +{ + return boost::math::itrunc(v.value(), policies::policy<>()); +} + +template <class Policy> +inline long ltrunc(const concepts::std_real_concept& v, const Policy& pol) +{ + return boost::math::ltrunc(v.value(), pol); +} +inline long ltrunc(const concepts::std_real_concept& v) +{ + return boost::math::ltrunc(v.value(), policies::policy<>()); +} + +#ifdef BOOST_HAS_LONG_LONG + +template <class Policy> +inline boost::long_long_type lltrunc(const concepts::std_real_concept& v, const Policy& pol) +{ + return boost::math::lltrunc(v.value(), pol); +} +inline boost::long_long_type lltrunc(const concepts::std_real_concept& v) +{ + return boost::math::lltrunc(v.value(), policies::policy<>()); +} + +#endif + +// Streaming: +template <class charT, class traits> +inline std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& os, const std_real_concept& a) +{ + return os << a.value(); +} +template <class charT, class traits> +inline std::basic_istream<charT, traits>& operator>>(std::basic_istream<charT, traits>& is, std_real_concept& a) +{ + std_real_concept_base_type v; + is >> v; + a = v; + return is; +} + +} // namespace concepts +}} + +#include <boost/math/tools/precision.hpp> + +namespace boost{ namespace math{ +namespace tools +{ + +template <> +inline concepts::std_real_concept max_value<concepts::std_real_concept>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(concepts::std_real_concept)) +{ + return max_value<concepts::std_real_concept_base_type>(); +} + +template <> +inline concepts::std_real_concept min_value<concepts::std_real_concept>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(concepts::std_real_concept)) +{ + return min_value<concepts::std_real_concept_base_type>(); +} + +template <> +inline concepts::std_real_concept log_max_value<concepts::std_real_concept>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(concepts::std_real_concept)) +{ + return log_max_value<concepts::std_real_concept_base_type>(); +} + +template <> +inline concepts::std_real_concept log_min_value<concepts::std_real_concept>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(concepts::std_real_concept)) +{ + return log_min_value<concepts::std_real_concept_base_type>(); +} + +template <> +inline concepts::std_real_concept epsilon(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(concepts::std_real_concept)) +{ + return tools::epsilon<concepts::std_real_concept_base_type>(); +} + +template <> +inline int digits<concepts::std_real_concept>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(concepts::std_real_concept)) +{ // Assume number of significand bits is same as std_real_concept_base_type, + // unless std::numeric_limits<T>::is_specialized to provide digits. + return digits<concepts::std_real_concept_base_type>(); +} + +} // namespace tools + +#if BOOST_WORKAROUND(BOOST_MSVC, <= 1310) +using concepts::itrunc; +using concepts::ltrunc; +using concepts::lltrunc; +using concepts::iround; +using concepts::lround; +using concepts::llround; +#endif + +} // namespace math +} // namespace boost + +#endif // BOOST_MATH_STD_REAL_CONCEPT_HPP + + + + diff --git a/Utilities/BGL/boost/math/constants/constants.hpp b/Utilities/BGL/boost/math/constants/constants.hpp new file mode 100644 index 0000000000000000000000000000000000000000..1f5423a8772a5a725ec02df6c337933aacfe3084 --- /dev/null +++ b/Utilities/BGL/boost/math/constants/constants.hpp @@ -0,0 +1,75 @@ +// Copyright John Maddock 2005-2006. +// Copyright Paul A. Bristow 2006-7. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_CONSTANTS_CONSTANTS_INCLUDED +#define BOOST_MATH_CONSTANTS_CONSTANTS_INCLUDED + +#include <boost/math/tools/config.hpp> +#ifdef BOOST_MSVC +#pragma warning(push) +#pragma warning(disable: 4127 4701) +#endif +#include <boost/lexical_cast.hpp> +#ifdef BOOST_MSVC +#pragma warning(pop) +#endif + +namespace boost{ namespace math +{ + namespace constants + { + // To permit other calculations at about 100 decimal digits with NTL::RR type, + // it is obviously necessary to define constants to this accuracy. + + // However, some compilers do not accept decimal digits strings as long as this. + // So the constant is split into two parts, with the 1st containing at least + // long double precision, and the 2nd zero if not needed or known. + // The 3rd part permits an exponent to be provided if necessary (use zero if none) - + // the other two parameters may only contain decimal digits (and sign and decimal point), + // and may NOT include an exponent like 1.234E99. + // The second digit string is only used if T is a User-Defined Type, + // when the constant is converted to a long string literal and lexical_casted to type T. + // (This is necessary because you can't use a numeric constant + // since even a long double might not have enough digits). + + + #define BOOST_DEFINE_MATH_CONSTANT(name, x, y, exp)\ + template <class T> inline T name(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(T))\ + {\ + static const T result = ::boost::lexical_cast<T>(BOOST_STRINGIZE(BOOST_JOIN(BOOST_JOIN(x, y), BOOST_JOIN(e, exp))));\ + return result;\ + }\ + template <> inline float name<float>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(float))\ + { return BOOST_JOIN(BOOST_JOIN(x, BOOST_JOIN(e, exp)), F); }\ + template <> inline double name<double>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(double))\ + { return BOOST_JOIN(x, BOOST_JOIN(e, exp)); }\ + template <> inline long double name<long double>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(long double))\ + { return BOOST_JOIN(BOOST_JOIN(x, BOOST_JOIN(e, exp)), L); } + + BOOST_DEFINE_MATH_CONSTANT(pi, 3.141592653589793238462643383279502884197169399375105820974944, 59230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196, 0) + BOOST_DEFINE_MATH_CONSTANT(root_pi, 1.7724538509055160272981674833411451827975, 0, 0) + BOOST_DEFINE_MATH_CONSTANT(root_half_pi, 1.253314137315500251207882642405522626503, 0, 0) + BOOST_DEFINE_MATH_CONSTANT(root_two_pi, 2.506628274631000502415765284811045253007, 0, 0) + BOOST_DEFINE_MATH_CONSTANT(root_ln_four, 1.1774100225154746910115693264596996377473856893858205385225257565000, 2658854698492680841813836877081, 0) + BOOST_DEFINE_MATH_CONSTANT(e, 2.7182818284590452353602874713526624977572470936999595749669676, 27724076630353547594571382178525166427427466391932003059921817413596629043572900334295260595630738132328627943490763233829880753195251019011, 0) + BOOST_DEFINE_MATH_CONSTANT(half, 0.5, 0, 0) + BOOST_DEFINE_MATH_CONSTANT(euler, 0.577215664901532860606512090082402431042159335939923598805, 76723488486, 0) + BOOST_DEFINE_MATH_CONSTANT(root_two, 1.414213562373095048801688724209698078569671875376948073, 17667973799073247846210703885038753432764157273501384623091229702492483605585073721264412149709993583141322266592750559275579995050115278206, 0) + BOOST_DEFINE_MATH_CONSTANT(ln_two, 0.693147180559945309417232121458176568075500134360255254, 120680009493393621969694715605863326996418687, 0) + BOOST_DEFINE_MATH_CONSTANT(ln_ln_two, -0.36651292058166432701243915823266946945426344783710526305367771367056, 16153193527385494558228566989083583025230453648347655663425171940646634, 0) + BOOST_DEFINE_MATH_CONSTANT(third, 0.3333333333333333333333333333333333333333333333333333333333333333333333, 3333333333333333333333333333333333333333333333333333333333333333333333333, 0) + BOOST_DEFINE_MATH_CONSTANT(twothirds, 0.66666666666666666666666666666666666666666666666666666666666666666666, 66666666666666666666666666666666666666666666666666666666666666666666667, 0) + BOOST_DEFINE_MATH_CONSTANT(pi_minus_three, 0.141592653589793238462643383279502884197169399375105820974944, 59230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196, 0) + BOOST_DEFINE_MATH_CONSTANT(four_minus_pi, 0.85840734641020676153735661672049711580283060062489417902505540769218359, 0, 0) + BOOST_DEFINE_MATH_CONSTANT(pow23_four_minus_pi, 0.79531676737159754434839533505680658072763917332771320544530223438582161, 0, 0) + BOOST_DEFINE_MATH_CONSTANT(exp_minus_half, 0.6065306597126334236037995349911804534419181354871869556828921587350565194137, 484239986476115079894560, 0) + + + } // namespace constants +} // namespace math +} // namespace boost + +#endif // BOOST_MATH_CONSTANTS_CONSTANTS_INCLUDED diff --git a/Utilities/BGL/boost/math/distributions.hpp b/Utilities/BGL/boost/math/distributions.hpp new file mode 100644 index 0000000000000000000000000000000000000000..342da5e7d39cf8e6e4b509170a258948d0e44aa5 --- /dev/null +++ b/Utilities/BGL/boost/math/distributions.hpp @@ -0,0 +1,46 @@ +// Copyright John Maddock 2006, 2007. +// Copyright Paul A. Bristow 2006, 2007, 2009. + +// Use, modification and distribution are subject to 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) + +// This file includes *all* the distributions. +// this may be useful if many are used +// - to avoid including each distribution individually. + +#ifndef BOOST_MATH_DISTRIBUTIONS_HPP +#define BOOST_MATH_DISTRIBUTIONS_HPP + +#include <boost/math/distributions/bernoulli.hpp> +#include <boost/math/distributions/beta.hpp> +#include <boost/math/distributions/binomial.hpp> +#include <boost/math/distributions/cauchy.hpp> +#include <boost/math/distributions/chi_squared.hpp> +#include <boost/math/distributions/complement.hpp> +#include <boost/math/distributions/exponential.hpp> +#include <boost/math/distributions/extreme_value.hpp> +#include <boost/math/distributions/fisher_f.hpp> +#include <boost/math/distributions/gamma.hpp> +#include <boost/math/distributions/hypergeometric.hpp> +#include <boost/math/distributions/laplace.hpp> +#include <boost/math/distributions/logistic.hpp> +#include <boost/math/distributions/lognormal.hpp> +#include <boost/math/distributions/negative_binomial.hpp> +#include <boost/math/distributions/non_central_chi_squared.hpp> +#include <boost/math/distributions/non_central_beta.hpp> +#include <boost/math/distributions/non_central_f.hpp> +#include <boost/math/distributions/non_central_t.hpp> +#include <boost/math/distributions/normal.hpp> +#include <boost/math/distributions/pareto.hpp> +#include <boost/math/distributions/poisson.hpp> +#include <boost/math/distributions/rayleigh.hpp> +#include <boost/math/distributions/students_t.hpp> +#include <boost/math/distributions/triangular.hpp> +#include <boost/math/distributions/uniform.hpp> +#include <boost/math/distributions/weibull.hpp> +#include <boost/math/distributions/find_scale.hpp> +#include <boost/math/distributions/find_location.hpp> + +#endif // BOOST_MATH_DISTRIBUTIONS_HPP + diff --git a/Utilities/BGL/boost/math/distributions/bernoulli.hpp b/Utilities/BGL/boost/math/distributions/bernoulli.hpp new file mode 100644 index 0000000000000000000000000000000000000000..ea9321d6a30e9d408e81976796a9af8c25880d89 --- /dev/null +++ b/Utilities/BGL/boost/math/distributions/bernoulli.hpp @@ -0,0 +1,325 @@ +// boost\math\distributions\bernoulli.hpp + +// Copyright John Maddock 2006. +// Copyright Paul A. Bristow 2007. + +// Use, modification and distribution are subject to 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) + +// http://en.wikipedia.org/wiki/bernoulli_distribution +// http://mathworld.wolfram.com/BernoulliDistribution.html + +// bernoulli distribution is the discrete probability distribution of +// the number (k) of successes, in a single Bernoulli trials. +// It is a version of the binomial distribution when n = 1. + +// But note that the bernoulli distribution +// (like others including the poisson, binomial & negative binomial) +// is strictly defined as a discrete function: only integral values of k are envisaged. +// However because of the method of calculation using a continuous gamma function, +// it is convenient to treat it as if a continous function, +// and permit non-integral values of k. +// To enforce the strict mathematical model, users should use floor or ceil functions +// on k outside this function to ensure that k is integral. + +#ifndef BOOST_MATH_SPECIAL_BERNOULLI_HPP +#define BOOST_MATH_SPECIAL_BERNOULLI_HPP + +#include <boost/math/distributions/fwd.hpp> +#include <boost/math/tools/config.hpp> +#include <boost/math/distributions/complement.hpp> // complements +#include <boost/math/distributions/detail/common_error_handling.hpp> // error checks +#include <boost/math/special_functions/fpclassify.hpp> // isnan. + +#include <utility> + +namespace boost +{ + namespace math + { + namespace bernoulli_detail + { + // Common error checking routines for bernoulli distribution functions: + template <class RealType, class Policy> + inline bool check_success_fraction(const char* function, const RealType& p, RealType* result, const Policy& /* pol */) + { + if(!(boost::math::isfinite)(p) || (p < 0) || (p > 1)) + { + *result = policies::raise_domain_error<RealType>( + function, + "Success fraction argument is %1%, but must be >= 0 and <= 1 !", p, Policy()); + return false; + } + return true; + } + template <class RealType, class Policy> + inline bool check_dist(const char* function, const RealType& p, RealType* result, const Policy& /* pol */) + { + return check_success_fraction(function, p, result, Policy()); + } + template <class RealType, class Policy> + inline bool check_dist_and_k(const char* function, const RealType& p, RealType k, RealType* result, const Policy& pol) + { + if(check_dist(function, p, result, Policy()) == false) + { + return false; + } + if(!(boost::math::isfinite)(k) || !((k == 0) || (k == 1))) + { + *result = policies::raise_domain_error<RealType>( + function, + "Number of successes argument is %1%, but must be 0 or 1 !", k, pol); + return false; + } + return true; + } + template <class RealType, class Policy> + inline bool check_dist_and_prob(const char* function, RealType p, RealType prob, RealType* result, const Policy& /* pol */) + { + if(check_dist(function, p, result, Policy()) && detail::check_probability(function, prob, result, Policy()) == false) + { + return false; + } + return true; + } + } // namespace bernoulli_detail + + + template <class RealType = double, class Policy = policies::policy<> > + class bernoulli_distribution + { + public: + typedef RealType value_type; + typedef Policy policy_type; + + bernoulli_distribution(RealType p = 0.5) : m_p(p) + { // Default probability = half suits 'fair' coin tossing + // where probability of heads == probability of tails. + RealType result; // of checks. + bernoulli_detail::check_dist( + "boost::math::bernoulli_distribution<%1%>::bernoulli_distribution", + m_p, + &result, Policy()); + } // bernoulli_distribution constructor. + + RealType success_fraction() const + { // Probability. + return m_p; + } + + private: + RealType m_p; // success_fraction + }; // template <class RealType> class bernoulli_distribution + + typedef bernoulli_distribution<double> bernoulli; + + template <class RealType, class Policy> + inline const std::pair<RealType, RealType> range(const bernoulli_distribution<RealType, Policy>& /* dist */) + { // Range of permissible values for random variable k = {0, 1}. + using boost::math::tools::max_value; + return std::pair<RealType, RealType>(0, 1); + } + + template <class RealType, class Policy> + inline const std::pair<RealType, RealType> support(const bernoulli_distribution<RealType, Policy>& /* dist */) + { // Range of supported values for random variable k = {0, 1}. + // This is range where cdf rises from 0 to 1, and outside it, the pdf is zero. + return std::pair<RealType, RealType>(0, 1); + } + + template <class RealType, class Policy> + inline RealType mean(const bernoulli_distribution<RealType, Policy>& dist) + { // Mean of bernoulli distribution = p (n = 1). + return dist.success_fraction(); + } // mean + + // Rely on dereived_accessors quantile(half) + //template <class RealType> + //inline RealType median(const bernoulli_distribution<RealType, Policy>& dist) + //{ // Median of bernoulli distribution is not defined. + // return tools::domain_error<RealType>(BOOST_CURRENT_FUNCTION, "Median is not implemented, result is %1%!", std::numeric_limits<RealType>::quiet_NaN()); + //} // median + + template <class RealType, class Policy> + inline RealType variance(const bernoulli_distribution<RealType, Policy>& dist) + { // Variance of bernoulli distribution =p * q. + return dist.success_fraction() * (1 - dist.success_fraction()); + } // variance + + template <class RealType, class Policy> + RealType pdf(const bernoulli_distribution<RealType, Policy>& dist, const RealType& k) + { // Probability Density/Mass Function. + BOOST_FPU_EXCEPTION_GUARD + // Error check: + RealType result; // of checks. + if(false == bernoulli_detail::check_dist_and_k( + "boost::math::pdf(bernoulli_distribution<%1%>, %1%)", + dist.success_fraction(), // 0 to 1 + k, // 0 or 1 + &result, Policy())) + { + return result; + } + // Assume k is integral. + if (k == 0) + { + return 1 - dist.success_fraction(); // 1 - p + } + else // k == 1 + { + return dist.success_fraction(); // p + } + } // pdf + + template <class RealType, class Policy> + inline RealType cdf(const bernoulli_distribution<RealType, Policy>& dist, const RealType& k) + { // Cumulative Distribution Function Bernoulli. + RealType p = dist.success_fraction(); + // Error check: + RealType result; + if(false == bernoulli_detail::check_dist_and_k( + "boost::math::cdf(bernoulli_distribution<%1%>, %1%)", + p, + k, + &result, Policy())) + { + return result; + } + if (k == 0) + { + return 1 - p; + } + else + { // k == 1 + return 1; + } + } // bernoulli cdf + + template <class RealType, class Policy> + inline RealType cdf(const complemented2_type<bernoulli_distribution<RealType, Policy>, RealType>& c) + { // Complemented Cumulative Distribution Function bernoulli. + RealType const& k = c.param; + bernoulli_distribution<RealType, Policy> const& dist = c.dist; + RealType p = dist.success_fraction(); + // Error checks: + RealType result; + if(false == bernoulli_detail::check_dist_and_k( + "boost::math::cdf(bernoulli_distribution<%1%>, %1%)", + p, + k, + &result, Policy())) + { + return result; + } + if (k == 0) + { + return p; + } + else + { // k == 1 + return 0; + } + } // bernoulli cdf complement + + template <class RealType, class Policy> + inline RealType quantile(const bernoulli_distribution<RealType, Policy>& dist, const RealType& p) + { // Quantile or Percent Point Bernoulli function. + // Return the number of expected successes k either 0 or 1. + // for a given probability p. + + RealType result; // of error checks: + if(false == bernoulli_detail::check_dist_and_prob( + "boost::math::quantile(bernoulli_distribution<%1%>, %1%)", + dist.success_fraction(), + p, + &result, Policy())) + { + return result; + } + if (p <= (1 - dist.success_fraction())) + { // p <= pdf(dist, 0) == cdf(dist, 0) + return 0; + } + else + { + return 1; + } + } // quantile + + template <class RealType, class Policy> + inline RealType quantile(const complemented2_type<bernoulli_distribution<RealType, Policy>, RealType>& c) + { // Quantile or Percent Point bernoulli function. + // Return the number of expected successes k for a given + // complement of the probability q. + // + // Error checks: + RealType q = c.param; + const bernoulli_distribution<RealType, Policy>& dist = c.dist; + RealType result; + if(false == bernoulli_detail::check_dist_and_prob( + "boost::math::quantile(bernoulli_distribution<%1%>, %1%)", + dist.success_fraction(), + q, + &result, Policy())) + { + return result; + } + + if (q <= 1 - dist.success_fraction()) + { // // q <= cdf(complement(dist, 0)) == pdf(dist, 0) + return 1; + } + else + { + return 0; + } + } // quantile complemented. + + template <class RealType, class Policy> + inline RealType mode(const bernoulli_distribution<RealType, Policy>& dist) + { + return static_cast<RealType>((dist.success_fraction() <= 0.5) ? 0 : 1); // p = 0.5 can be 0 or 1 + } + + template <class RealType, class Policy> + inline RealType skewness(const bernoulli_distribution<RealType, Policy>& dist) + { + BOOST_MATH_STD_USING; // Aid ADL for sqrt. + RealType p = dist.success_fraction(); + return (1 - 2 * p) / sqrt(p * (1 - p)); + } + + template <class RealType, class Policy> + inline RealType kurtosis_excess(const bernoulli_distribution<RealType, Policy>& dist) + { + RealType p = dist.success_fraction(); + // Note Wolfram says this is kurtosis in text, but gamma2 is the kurtosis excess, + // and Wikipedia also says this is the kurtosis excess formula. + // return (6 * p * p - 6 * p + 1) / (p * (1 - p)); + // But Wolfram kurtosis article gives this simpler formula for kurtosis excess: + return 1 / (1 - p) + 1/p -6; + } + + template <class RealType, class Policy> + inline RealType kurtosis(const bernoulli_distribution<RealType, Policy>& dist) + { + RealType p = dist.success_fraction(); + return 1 / (1 - p) + 1/p -6 + 3; + // Simpler than: + // return (6 * p * p - 6 * p + 1) / (p * (1 - p)) + 3; + } + + } // namespace math +} // namespace boost + +// This include must be at the end, *after* the accessors +// for this distribution have been defined, in order to +// keep compilers that support two-phase lookup happy. +#include <boost/math/distributions/detail/derived_accessors.hpp> + +#endif // BOOST_MATH_SPECIAL_BERNOULLI_HPP + + + diff --git a/Utilities/BGL/boost/math/distributions/beta.hpp b/Utilities/BGL/boost/math/distributions/beta.hpp new file mode 100644 index 0000000000000000000000000000000000000000..c757df45138f22cb955d295a561d1d3b418d48fd --- /dev/null +++ b/Utilities/BGL/boost/math/distributions/beta.hpp @@ -0,0 +1,544 @@ +// boost\math\distributions\beta.hpp + +// Copyright John Maddock 2006. +// Copyright Paul A. Bristow 2006. + +// Use, modification and distribution are subject to 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) + +// http://en.wikipedia.org/wiki/Beta_distribution +// http://www.itl.nist.gov/div898/handbook/eda/section3/eda366h.htm +// http://mathworld.wolfram.com/BetaDistribution.html + +// The Beta Distribution is a continuous probability distribution. +// The beta distribution is used to model events which are constrained to take place +// within an interval defined by maxima and minima, +// so is used extensively in PERT and other project management systems +// to describe the time to completion. +// The cdf of the beta distribution is used as a convenient way +// of obtaining the sum over a set of binomial outcomes. +// The beta distribution is also used in Bayesian statistics. + +#ifndef BOOST_MATH_DIST_BETA_HPP +#define BOOST_MATH_DIST_BETA_HPP + +#include <boost/math/distributions/fwd.hpp> +#include <boost/math/special_functions/beta.hpp> // for beta. +#include <boost/math/distributions/complement.hpp> // complements. +#include <boost/math/distributions/detail/common_error_handling.hpp> // error checks +#include <boost/math/special_functions/fpclassify.hpp> // isnan. +#include <boost/math/tools/roots.hpp> // for root finding. + +#if defined (BOOST_MSVC) +# pragma warning(push) +# pragma warning(disable: 4702) // unreachable code +// in domain_error_imp in error_handling +#endif + +#include <utility> + +namespace boost +{ + namespace math + { + namespace beta_detail + { + // Common error checking routines for beta distribution functions: + template <class RealType, class Policy> + inline bool check_alpha(const char* function, const RealType& alpha, RealType* result, const Policy& pol) + { + if(!(boost::math::isfinite)(alpha) || (alpha <= 0)) + { + *result = policies::raise_domain_error<RealType>( + function, + "Alpha argument is %1%, but must be > 0 !", alpha, pol); + return false; + } + return true; + } // bool check_alpha + + template <class RealType, class Policy> + inline bool check_beta(const char* function, const RealType& beta, RealType* result, const Policy& pol) + { + if(!(boost::math::isfinite)(beta) || (beta <= 0)) + { + *result = policies::raise_domain_error<RealType>( + function, + "Beta argument is %1%, but must be > 0 !", beta, pol); + return false; + } + return true; + } // bool check_beta + + template <class RealType, class Policy> + inline bool check_prob(const char* function, const RealType& p, RealType* result, const Policy& pol) + { + if((p < 0) || (p > 1) || !(boost::math::isfinite)(p)) + { + *result = policies::raise_domain_error<RealType>( + function, + "Probability argument is %1%, but must be >= 0 and <= 1 !", p, pol); + return false; + } + return true; + } // bool check_prob + + template <class RealType, class Policy> + inline bool check_x(const char* function, const RealType& x, RealType* result, const Policy& pol) + { + if(!(boost::math::isfinite)(x) || (x < 0) || (x > 1)) + { + *result = policies::raise_domain_error<RealType>( + function, + "x argument is %1%, but must be >= 0 and <= 1 !", x, pol); + return false; + } + return true; + } // bool check_x + + template <class RealType, class Policy> + inline bool check_dist(const char* function, const RealType& alpha, const RealType& beta, RealType* result, const Policy& pol) + { // Check both alpha and beta. + return check_alpha(function, alpha, result, pol) + && check_beta(function, beta, result, pol); + } // bool check_dist + + template <class RealType, class Policy> + inline bool check_dist_and_x(const char* function, const RealType& alpha, const RealType& beta, RealType x, RealType* result, const Policy& pol) + { + return check_dist(function, alpha, beta, result, pol) + && check_x(function, x, result, pol); + } // bool check_dist_and_x + + template <class RealType, class Policy> + inline bool check_dist_and_prob(const char* function, const RealType& alpha, const RealType& beta, RealType p, RealType* result, const Policy& pol) + { + return check_dist(function, alpha, beta, result, pol) + && check_prob(function, p, result, pol); + } // bool check_dist_and_prob + + template <class RealType, class Policy> + inline bool check_mean(const char* function, const RealType& mean, RealType* result, const Policy& pol) + { + if(!(boost::math::isfinite)(mean) || (mean <= 0)) + { + *result = policies::raise_domain_error<RealType>( + function, + "mean argument is %1%, but must be > 0 !", mean, pol); + return false; + } + return true; + } // bool check_mean + template <class RealType, class Policy> + inline bool check_variance(const char* function, const RealType& variance, RealType* result, const Policy& pol) + { + if(!(boost::math::isfinite)(variance) || (variance <= 0)) + { + *result = policies::raise_domain_error<RealType>( + function, + "variance argument is %1%, but must be > 0 !", variance, pol); + return false; + } + return true; + } // bool check_variance + } // namespace beta_detail + + // typedef beta_distribution<double> beta; + // is deliberately NOT included to avoid a name clash with the beta function. + // Use beta_distribution<> mybeta(...) to construct type double. + + template <class RealType = double, class Policy = policies::policy<> > + class beta_distribution + { + public: + typedef RealType value_type; + typedef Policy policy_type; + + beta_distribution(RealType alpha = 1, RealType beta = 1) : m_alpha(alpha), m_beta(beta) + { + RealType result; + beta_detail::check_dist( + "boost::math::beta_distribution<%1%>::beta_distribution", + m_alpha, + m_beta, + &result, Policy()); + } // beta_distribution constructor. + // Accessor functions: + RealType alpha() const + { + return m_alpha; + } + RealType beta() const + { // . + return m_beta; + } + + // Estimation of the alpha & beta parameters. + // http://en.wikipedia.org/wiki/Beta_distribution + // gives formulae in section on parameter estimation. + // Also NIST EDA page 3 & 4 give the same. + // http://www.itl.nist.gov/div898/handbook/eda/section3/eda366h.htm + // http://www.epi.ucdavis.edu/diagnostictests/betabuster.html + + static RealType find_alpha( + RealType mean, // Expected value of mean. + RealType variance) // Expected value of variance. + { + static const char* function = "boost::math::beta_distribution<%1%>::find_alpha"; + RealType result; // of error checks. + if(false == + beta_detail::check_mean( + function, mean, &result, Policy()) + && + beta_detail::check_variance( + function, variance, &result, Policy()) + ) + { + return result; + } + return mean * (( (mean * (1 - mean)) / variance)- 1); + } // RealType find_alpha + + static RealType find_beta( + RealType mean, // Expected value of mean. + RealType variance) // Expected value of variance. + { + static const char* function = "boost::math::beta_distribution<%1%>::find_beta"; + RealType result; // of error checks. + if(false == + beta_detail::check_mean( + function, mean, &result, Policy()) + && + beta_detail::check_variance( + function, variance, &result, Policy()) + ) + { + return result; + } + return (1 - mean) * (((mean * (1 - mean)) /variance)-1); + } // RealType find_beta + + // Estimate alpha & beta from either alpha or beta, and x and probability. + // Uses for these parameter estimators are unclear. + + static RealType find_alpha( + RealType beta, // from beta. + RealType x, // x. + RealType probability) // cdf + { + static const char* function = "boost::math::beta_distribution<%1%>::find_alpha"; + RealType result; // of error checks. + if(false == + beta_detail::check_prob( + function, probability, &result, Policy()) + && + beta_detail::check_beta( + function, beta, &result, Policy()) + && + beta_detail::check_x( + function, x, &result, Policy()) + ) + { + return result; + } + return ibeta_inva(beta, x, probability, Policy()); + } // RealType find_alpha(beta, a, probability) + + static RealType find_beta( + // ibeta_invb(T b, T x, T p); (alpha, x, cdf,) + RealType alpha, // alpha. + RealType x, // probability x. + RealType probability) // probability cdf. + { + static const char* function = "boost::math::beta_distribution<%1%>::find_beta"; + RealType result; // of error checks. + if(false == + beta_detail::check_prob( + function, probability, &result, Policy()) + && + beta_detail::check_alpha( + function, alpha, &result, Policy()) + && + beta_detail::check_x( + function, x, &result, Policy()) + ) + { + return result; + } + return ibeta_invb(alpha, x, probability, Policy()); + } // RealType find_beta(alpha, x, probability) + + private: + RealType m_alpha; // Two parameters of the beta distribution. + RealType m_beta; + }; // template <class RealType, class Policy> class beta_distribution + + template <class RealType, class Policy> + inline const std::pair<RealType, RealType> range(const beta_distribution<RealType, Policy>& /* dist */) + { // Range of permissible values for random variable x. + using boost::math::tools::max_value; + return std::pair<RealType, RealType>(0, 1); + } + + template <class RealType, class Policy> + inline const std::pair<RealType, RealType> support(const beta_distribution<RealType, Policy>& /* dist */) + { // Range of supported values for random variable x. + // This is range where cdf rises from 0 to 1, and outside it, the pdf is zero. + return std::pair<RealType, RealType>(0, 1); + } + + template <class RealType, class Policy> + inline RealType mean(const beta_distribution<RealType, Policy>& dist) + { // Mean of beta distribution = np. + return dist.alpha() / (dist.alpha() + dist.beta()); + } // mean + + template <class RealType, class Policy> + inline RealType variance(const beta_distribution<RealType, Policy>& dist) + { // Variance of beta distribution = np(1-p). + RealType a = dist.alpha(); + RealType b = dist.beta(); + return (a * b) / ((a + b ) * (a + b) * (a + b + 1)); + } // variance + + template <class RealType, class Policy> + inline RealType mode(const beta_distribution<RealType, Policy>& dist) + { + static const char* function = "boost::math::mode(beta_distribution<%1%> const&)"; + + RealType result; + if ((dist.alpha() <= 1)) + { + result = policies::raise_domain_error<RealType>( + function, + "mode undefined for alpha = %1%, must be > 1!", dist.alpha(), Policy()); + return result; + } + + if ((dist.beta() <= 1)) + { + result = policies::raise_domain_error<RealType>( + function, + "mode undefined for beta = %1%, must be > 1!", dist.beta(), Policy()); + return result; + } + RealType a = dist.alpha(); + RealType b = dist.beta(); + return (a-1) / (a + b - 2); + } // mode + + //template <class RealType, class Policy> + //inline RealType median(const beta_distribution<RealType, Policy>& dist) + //{ // Median of beta distribution is not defined. + // return tools::domain_error<RealType>(function, "Median is not implemented, result is %1%!", std::numeric_limits<RealType>::quiet_NaN()); + //} // median + + //But WILL be provided by the derived accessor as quantile(0.5). + + template <class RealType, class Policy> + inline RealType skewness(const beta_distribution<RealType, Policy>& dist) + { + BOOST_MATH_STD_USING // ADL of std functions. + RealType a = dist.alpha(); + RealType b = dist.beta(); + return (2 * (b-a) * sqrt(a + b + 1)) / ((a + b + 2) * sqrt(a * b)); + } // skewness + + template <class RealType, class Policy> + inline RealType kurtosis_excess(const beta_distribution<RealType, Policy>& dist) + { + RealType a = dist.alpha(); + RealType b = dist.beta(); + RealType a_2 = a * a; + RealType n = 6 * (a_2 * a - a_2 * (2 * b - 1) + b * b * (b + 1) - 2 * a * b * (b + 2)); + RealType d = a * b * (a + b + 2) * (a + b + 3); + return n / d; + } // kurtosis_excess + + template <class RealType, class Policy> + inline RealType kurtosis(const beta_distribution<RealType, Policy>& dist) + { + return 3 + kurtosis_excess(dist); + } // kurtosis + + template <class RealType, class Policy> + inline RealType pdf(const beta_distribution<RealType, Policy>& dist, const RealType& x) + { // Probability Density/Mass Function. + BOOST_FPU_EXCEPTION_GUARD + + static const char* function = "boost::math::pdf(beta_distribution<%1%> const&, %1%)"; + + BOOST_MATH_STD_USING // for ADL of std functions + + RealType a = dist.alpha(); + RealType b = dist.beta(); + + // Argument checks: + RealType result; + if(false == beta_detail::check_dist_and_x( + function, + a, b, x, + &result, Policy())) + { + return result; + } + using boost::math::beta; + return ibeta_derivative(a, b, x, Policy()); + } // pdf + + template <class RealType, class Policy> + inline RealType cdf(const beta_distribution<RealType, Policy>& dist, const RealType& x) + { // Cumulative Distribution Function beta. + BOOST_MATH_STD_USING // for ADL of std functions + + static const char* function = "boost::math::cdf(beta_distribution<%1%> const&, %1%)"; + + RealType a = dist.alpha(); + RealType b = dist.beta(); + + // Argument checks: + RealType result; + if(false == beta_detail::check_dist_and_x( + function, + a, b, x, + &result, Policy())) + { + return result; + } + // Special cases: + if (x == 0) + { + return 0; + } + else if (x == 1) + { + return 1; + } + return ibeta(a, b, x, Policy()); + } // beta cdf + + template <class RealType, class Policy> + inline RealType cdf(const complemented2_type<beta_distribution<RealType, Policy>, RealType>& c) + { // Complemented Cumulative Distribution Function beta. + + BOOST_MATH_STD_USING // for ADL of std functions + + static const char* function = "boost::math::cdf(beta_distribution<%1%> const&, %1%)"; + + RealType const& x = c.param; + beta_distribution<RealType, Policy> const& dist = c.dist; + RealType a = dist.alpha(); + RealType b = dist.beta(); + + // Argument checks: + RealType result; + if(false == beta_detail::check_dist_and_x( + function, + a, b, x, + &result, Policy())) + { + return result; + } + if (x == 0) + { + return 1; + } + else if (x == 1) + { + return 0; + } + // Calculate cdf beta using the incomplete beta function. + // Use of ibeta here prevents cancellation errors in calculating + // 1 - x if x is very small, perhaps smaller than machine epsilon. + return ibetac(a, b, x, Policy()); + } // beta cdf + + template <class RealType, class Policy> + inline RealType quantile(const beta_distribution<RealType, Policy>& dist, const RealType& p) + { // Quantile or Percent Point beta function or + // Inverse Cumulative probability distribution function CDF. + // Return x (0 <= x <= 1), + // for a given probability p (0 <= p <= 1). + // These functions take a probability as an argument + // and return a value such that the probability that a random variable x + // will be less than or equal to that value + // is whatever probability you supplied as an argument. + + static const char* function = "boost::math::quantile(beta_distribution<%1%> const&, %1%)"; + + RealType result; // of argument checks: + RealType a = dist.alpha(); + RealType b = dist.beta(); + if(false == beta_detail::check_dist_and_prob( + function, + a, b, p, + &result, Policy())) + { + return result; + } + // Special cases: + if (p == 0) + { + return 0; + } + if (p == 1) + { + return 1; + } + return ibeta_inv(a, b, p, static_cast<RealType*>(0), Policy()); + } // quantile + + template <class RealType, class Policy> + inline RealType quantile(const complemented2_type<beta_distribution<RealType, Policy>, RealType>& c) + { // Complement Quantile or Percent Point beta function . + // Return the number of expected x for a given + // complement of the probability q. + + static const char* function = "boost::math::quantile(beta_distribution<%1%> const&, %1%)"; + + // + // Error checks: + RealType q = c.param; + const beta_distribution<RealType, Policy>& dist = c.dist; + RealType result; + RealType a = dist.alpha(); + RealType b = dist.beta(); + if(false == beta_detail::check_dist_and_prob( + function, + a, + b, + q, + &result, Policy())) + { + return result; + } + // Special cases: + if(q == 1) + { + return 0; + } + if(q == 0) + { + return 1; + } + + return ibetac_inv(a, b, q, static_cast<RealType*>(0), Policy()); + } // Quantile Complement + + } // namespace math +} // namespace boost + +// This include must be at the end, *after* the accessors +// for this distribution have been defined, in order to +// keep compilers that support two-phase lookup happy. +#include <boost/math/distributions/detail/derived_accessors.hpp> + +#if defined (BOOST_MSVC) +# pragma warning(pop) +#endif + +#endif // BOOST_MATH_DIST_BETA_HPP + + diff --git a/Utilities/BGL/boost/math/distributions/binomial.hpp b/Utilities/BGL/boost/math/distributions/binomial.hpp new file mode 100644 index 0000000000000000000000000000000000000000..4b1dee01db10c3f332b23fd7b823312248bbb4ee --- /dev/null +++ b/Utilities/BGL/boost/math/distributions/binomial.hpp @@ -0,0 +1,724 @@ +// boost\math\distributions\binomial.hpp + +// Copyright John Maddock 2006. +// Copyright Paul A. Bristow 2007. + +// Use, modification and distribution are subject to 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) + +// http://en.wikipedia.org/wiki/binomial_distribution + +// Binomial distribution is the discrete probability distribution of +// the number (k) of successes, in a sequence of +// n independent (yes or no, success or failure) Bernoulli trials. + +// It expresses the probability of a number of events occurring in a fixed time +// if these events occur with a known average rate (probability of success), +// and are independent of the time since the last event. + +// The number of cars that pass through a certain point on a road during a given period of time. +// The number of spelling mistakes a secretary makes while typing a single page. +// The number of phone calls at a call center per minute. +// The number of times a web server is accessed per minute. +// The number of light bulbs that burn out in a certain amount of time. +// The number of roadkill found per unit length of road + +// http://en.wikipedia.org/wiki/binomial_distribution + +// Given a sample of N measured values k[i], +// we wish to estimate the value of the parameter x (mean) +// of the binomial population from which the sample was drawn. +// To calculate the maximum likelihood value = 1/N sum i = 1 to N of k[i] + +// Also may want a function for EXACTLY k. + +// And probability that there are EXACTLY k occurrences is +// exp(-x) * pow(x, k) / factorial(k) +// where x is expected occurrences (mean) during the given interval. +// For example, if events occur, on average, every 4 min, +// and we are interested in number of events occurring in 10 min, +// then x = 10/4 = 2.5 + +// http://www.itl.nist.gov/div898/handbook/eda/section3/eda366i.htm + +// The binomial distribution is used when there are +// exactly two mutually exclusive outcomes of a trial. +// These outcomes are appropriately labeled "success" and "failure". +// The binomial distribution is used to obtain +// the probability of observing x successes in N trials, +// with the probability of success on a single trial denoted by p. +// The binomial distribution assumes that p is fixed for all trials. + +// P(x, p, n) = n!/(x! * (n-x)!) * p^x * (1-p)^(n-x) + +// http://mathworld.wolfram.com/BinomialCoefficient.html + +// The binomial coefficient (n; k) is the number of ways of picking +// k unordered outcomes from n possibilities, +// also known as a combination or combinatorial number. +// The symbols _nC_k and (n; k) are used to denote a binomial coefficient, +// and are sometimes read as "n choose k." +// (n; k) therefore gives the number of k-subsets possible out of a set of n distinct items. + +// For example: +// The 2-subsets of {1,2,3,4} are the six pairs {1,2}, {1,3}, {1,4}, {2,3}, {2,4}, and {3,4}, so (4; 2)==6. + +// http://functions.wolfram.com/GammaBetaErf/Binomial/ for evaluation. + +// But note that the binomial distribution +// (like others including the poisson, negative binomial & Bernoulli) +// is strictly defined as a discrete function: only integral values of k are envisaged. +// However because of the method of calculation using a continuous gamma function, +// it is convenient to treat it as if a continous function, +// and permit non-integral values of k. +// To enforce the strict mathematical model, users should use floor or ceil functions +// on k outside this function to ensure that k is integral. + +#ifndef BOOST_MATH_SPECIAL_BINOMIAL_HPP +#define BOOST_MATH_SPECIAL_BINOMIAL_HPP + +#include <boost/math/distributions/fwd.hpp> +#include <boost/math/special_functions/beta.hpp> // for incomplete beta. +#include <boost/math/distributions/complement.hpp> // complements +#include <boost/math/distributions/detail/common_error_handling.hpp> // error checks +#include <boost/math/distributions/detail/inv_discrete_quantile.hpp> // error checks +#include <boost/math/special_functions/fpclassify.hpp> // isnan. +#include <boost/math/tools/roots.hpp> // for root finding. + +#include <utility> + +namespace boost +{ + namespace math + { + + template <class RealType, class Policy> + class binomial_distribution; + + namespace binomial_detail{ + // common error checking routines for binomial distribution functions: + template <class RealType, class Policy> + inline bool check_N(const char* function, const RealType& N, RealType* result, const Policy& pol) + { + if((N < 0) || !(boost::math::isfinite)(N)) + { + *result = policies::raise_domain_error<RealType>( + function, + "Number of Trials argument is %1%, but must be >= 0 !", N, pol); + return false; + } + return true; + } + template <class RealType, class Policy> + inline bool check_success_fraction(const char* function, const RealType& p, RealType* result, const Policy& pol) + { + if((p < 0) || (p > 1) || !(boost::math::isfinite)(p)) + { + *result = policies::raise_domain_error<RealType>( + function, + "Success fraction argument is %1%, but must be >= 0 and <= 1 !", p, pol); + return false; + } + return true; + } + template <class RealType, class Policy> + inline bool check_dist(const char* function, const RealType& N, const RealType& p, RealType* result, const Policy& pol) + { + return check_success_fraction( + function, p, result, pol) + && check_N( + function, N, result, pol); + } + template <class RealType, class Policy> + inline bool check_dist_and_k(const char* function, const RealType& N, const RealType& p, RealType k, RealType* result, const Policy& pol) + { + if(check_dist(function, N, p, result, pol) == false) + return false; + if((k < 0) || !(boost::math::isfinite)(k)) + { + *result = policies::raise_domain_error<RealType>( + function, + "Number of Successes argument is %1%, but must be >= 0 !", k, pol); + return false; + } + if(k > N) + { + *result = policies::raise_domain_error<RealType>( + function, + "Number of Successes argument is %1%, but must be <= Number of Trials !", k, pol); + return false; + } + return true; + } + template <class RealType, class Policy> + inline bool check_dist_and_prob(const char* function, const RealType& N, RealType p, RealType prob, RealType* result, const Policy& pol) + { + if(check_dist(function, N, p, result, pol) && detail::check_probability(function, prob, result, pol) == false) + return false; + return true; + } + + template <class T, class Policy> + T inverse_binomial_cornish_fisher(T n, T sf, T p, T q, const Policy& pol) + { + BOOST_MATH_STD_USING + // mean: + T m = n * sf; + // standard deviation: + T sigma = sqrt(n * sf * (1 - sf)); + // skewness + T sk = (1 - 2 * sf) / sigma; + // kurtosis: + // T k = (1 - 6 * sf * (1 - sf) ) / (n * sf * (1 - sf)); + // Get the inverse of a std normal distribution: + T x = boost::math::erfc_inv(p > q ? 2 * q : 2 * p, pol) * constants::root_two<T>(); + // Set the sign: + if(p < 0.5) + x = -x; + T x2 = x * x; + // w is correction term due to skewness + T w = x + sk * (x2 - 1) / 6; + /* + // Add on correction due to kurtosis. + // Disabled for now, seems to make things worse? + // + if(n >= 10) + w += k * x * (x2 - 3) / 24 + sk * sk * x * (2 * x2 - 5) / -36; + */ + w = m + sigma * w; + if(w < tools::min_value<T>()) + return sqrt(tools::min_value<T>()); + if(w > n) + return n; + return w; + } + + template <class RealType, class Policy> + RealType quantile_imp(const binomial_distribution<RealType, Policy>& dist, const RealType& p, const RealType& q) + { // Quantile or Percent Point Binomial function. + // Return the number of expected successes k, + // for a given probability p. + // + // Error checks: + BOOST_MATH_STD_USING // ADL of std names + RealType result; + RealType trials = dist.trials(); + RealType success_fraction = dist.success_fraction(); + if(false == binomial_detail::check_dist_and_prob( + "boost::math::quantile(binomial_distribution<%1%> const&, %1%)", + trials, + success_fraction, + p, + &result, Policy())) + { + return result; + } + + // Special cases: + // + if(p == 0) + { // There may actually be no answer to this question, + // since the probability of zero successes may be non-zero, + // but zero is the best we can do: + return 0; + } + if(p == 1) + { // Probability of n or fewer successes is always one, + // so n is the most sensible answer here: + return trials; + } + if (p <= pow(1 - success_fraction, trials)) + { // p <= pdf(dist, 0) == cdf(dist, 0) + return 0; // So the only reasonable result is zero. + } // And root finder would fail otherwise. + + // Solve for quantile numerically: + // + RealType guess = binomial_detail::inverse_binomial_cornish_fisher(trials, success_fraction, p, q, Policy()); + RealType factor = 8; + if(trials > 100) + factor = 1.01f; // guess is pretty accurate + else if((trials > 10) && (trials - 1 > guess) && (guess > 3)) + factor = 1.15f; // less accurate but OK. + else if(trials < 10) + { + // pretty inaccurate guess in this area: + if(guess > trials / 64) + { + guess = trials / 4; + factor = 2; + } + else + guess = trials / 1024; + } + else + factor = 2; // trials largish, but in far tails. + + typedef typename Policy::discrete_quantile_type discrete_quantile_type; + boost::uintmax_t max_iter = policies::get_max_root_iterations<Policy>(); + return detail::inverse_discrete_quantile( + dist, + p, + q, + guess, + factor, + RealType(1), + discrete_quantile_type(), + max_iter); + } // quantile + + } + + template <class RealType = double, class Policy = policies::policy<> > + class binomial_distribution + { + public: + typedef RealType value_type; + typedef Policy policy_type; + + binomial_distribution(RealType n = 1, RealType p = 0.5) : m_n(n), m_p(p) + { // Default n = 1 is the Bernoulli distribution + // with equal probability of 'heads' or 'tails. + RealType r; + binomial_detail::check_dist( + "boost::math::binomial_distribution<%1%>::binomial_distribution", + m_n, + m_p, + &r, Policy()); + } // binomial_distribution constructor. + + RealType success_fraction() const + { // Probability. + return m_p; + } + RealType trials() const + { // Total number of trials. + return m_n; + } + + enum interval_type{ + clopper_pearson_exact_interval, + jeffreys_prior_interval + }; + + // + // Estimation of the success fraction parameter. + // The best estimate is actually simply successes/trials, + // these functions are used + // to obtain confidence intervals for the success fraction. + // + static RealType find_lower_bound_on_p( + RealType trials, + RealType successes, + RealType probability, + interval_type t = clopper_pearson_exact_interval) + { + static const char* function = "boost::math::binomial_distribution<%1%>::find_lower_bound_on_p"; + // Error checks: + RealType result; + if(false == binomial_detail::check_dist_and_k( + function, trials, RealType(0), successes, &result, Policy()) + && + binomial_detail::check_dist_and_prob( + function, trials, RealType(0), probability, &result, Policy())) + { return result; } + + if(successes == 0) + return 0; + + // NOTE!!! The Clopper Pearson formula uses "successes" not + // "successes+1" as usual to get the lower bound, + // see http://www.itl.nist.gov/div898/handbook/prc/section2/prc241.htm + return (t == clopper_pearson_exact_interval) ? ibeta_inv(successes, trials - successes + 1, probability, static_cast<RealType*>(0), Policy()) + : ibeta_inv(successes + 0.5f, trials - successes + 0.5f, probability, static_cast<RealType*>(0), Policy()); + } + static RealType find_upper_bound_on_p( + RealType trials, + RealType successes, + RealType probability, + interval_type t = clopper_pearson_exact_interval) + { + static const char* function = "boost::math::binomial_distribution<%1%>::find_upper_bound_on_p"; + // Error checks: + RealType result; + if(false == binomial_detail::check_dist_and_k( + function, trials, RealType(0), successes, &result, Policy()) + && + binomial_detail::check_dist_and_prob( + function, trials, RealType(0), probability, &result, Policy())) + { return result; } + + if(trials == successes) + return 1; + + return (t == clopper_pearson_exact_interval) ? ibetac_inv(successes + 1, trials - successes, probability, static_cast<RealType*>(0), Policy()) + : ibetac_inv(successes + 0.5f, trials - successes + 0.5f, probability, static_cast<RealType*>(0), Policy()); + } + // Estimate number of trials parameter: + // + // "How many trials do I need to be P% sure of seeing k events?" + // or + // "How many trials can I have to be P% sure of seeing fewer than k events?" + // + static RealType find_minimum_number_of_trials( + RealType k, // number of events + RealType p, // success fraction + RealType alpha) // risk level + { + static const char* function = "boost::math::binomial_distribution<%1%>::find_minimum_number_of_trials"; + // Error checks: + RealType result; + if(false == binomial_detail::check_dist_and_k( + function, k, p, k, &result, Policy()) + && + binomial_detail::check_dist_and_prob( + function, k, p, alpha, &result, Policy())) + { return result; } + + result = ibetac_invb(k + 1, p, alpha, Policy()); // returns n - k + return result + k; + } + + static RealType find_maximum_number_of_trials( + RealType k, // number of events + RealType p, // success fraction + RealType alpha) // risk level + { + static const char* function = "boost::math::binomial_distribution<%1%>::find_maximum_number_of_trials"; + // Error checks: + RealType result; + if(false == binomial_detail::check_dist_and_k( + function, k, p, k, &result, Policy()) + && + binomial_detail::check_dist_and_prob( + function, k, p, alpha, &result, Policy())) + { return result; } + + result = ibeta_invb(k + 1, p, alpha, Policy()); // returns n - k + return result + k; + } + + private: + RealType m_n; // Not sure if this shouldn't be an int? + RealType m_p; // success_fraction + }; // template <class RealType, class Policy> class binomial_distribution + + typedef binomial_distribution<> binomial; + // typedef binomial_distribution<double> binomial; + // IS now included since no longer a name clash with function binomial. + //typedef binomial_distribution<double> binomial; // Reserved name of type double. + + template <class RealType, class Policy> + const std::pair<RealType, RealType> range(const binomial_distribution<RealType, Policy>& dist) + { // Range of permissible values for random variable k. + using boost::math::tools::max_value; + return std::pair<RealType, RealType>(static_cast<RealType>(0), dist.trials()); + } + + template <class RealType, class Policy> + const std::pair<RealType, RealType> support(const binomial_distribution<RealType, Policy>& dist) + { // Range of supported values for random variable k. + // This is range where cdf rises from 0 to 1, and outside it, the pdf is zero. + return std::pair<RealType, RealType>(0, dist.trials()); + } + + template <class RealType, class Policy> + inline RealType mean(const binomial_distribution<RealType, Policy>& dist) + { // Mean of Binomial distribution = np. + return dist.trials() * dist.success_fraction(); + } // mean + + template <class RealType, class Policy> + inline RealType variance(const binomial_distribution<RealType, Policy>& dist) + { // Variance of Binomial distribution = np(1-p). + return dist.trials() * dist.success_fraction() * (1 - dist.success_fraction()); + } // variance + + template <class RealType, class Policy> + RealType pdf(const binomial_distribution<RealType, Policy>& dist, const RealType& k) + { // Probability Density/Mass Function. + BOOST_FPU_EXCEPTION_GUARD + + BOOST_MATH_STD_USING // for ADL of std functions + + RealType n = dist.trials(); + + // Error check: + RealType result; + if(false == binomial_detail::check_dist_and_k( + "boost::math::pdf(binomial_distribution<%1%> const&, %1%)", + n, + dist.success_fraction(), + k, + &result, Policy())) + { + return result; + } + + // Special cases of success_fraction, regardless of k successes and regardless of n trials. + if (dist.success_fraction() == 0) + { // probability of zero successes is 1: + return static_cast<RealType>(k == 0 ? 1 : 0); + } + if (dist.success_fraction() == 1) + { // probability of n successes is 1: + return static_cast<RealType>(k == n ? 1 : 0); + } + // k argument may be integral, signed, or unsigned, or floating point. + // If necessary, it has already been promoted from an integral type. + if (n == 0) + { + return 1; // Probability = 1 = certainty. + } + if (k == 0) + { // binomial coeffic (n 0) = 1, + // n ^ 0 = 1 + return pow(1 - dist.success_fraction(), n); + } + if (k == n) + { // binomial coeffic (n n) = 1, + // n ^ 0 = 1 + return pow(dist.success_fraction(), k); // * pow((1 - dist.success_fraction()), (n - k)) = 1 + } + + // Probability of getting exactly k successes + // if C(n, k) is the binomial coefficient then: + // + // f(k; n,p) = C(n, k) * p^k * (1-p)^(n-k) + // = (n!/(k!(n-k)!)) * p^k * (1-p)^(n-k) + // = (tgamma(n+1) / (tgamma(k+1)*tgamma(n-k+1))) * p^k * (1-p)^(n-k) + // = p^k (1-p)^(n-k) / (beta(k+1, n-k+1) * (n+1)) + // = ibeta_derivative(k+1, n-k+1, p) / (n+1) + // + using boost::math::ibeta_derivative; // a, b, x + return ibeta_derivative(k+1, n-k+1, dist.success_fraction(), Policy()) / (n+1); + + } // pdf + + template <class RealType, class Policy> + inline RealType cdf(const binomial_distribution<RealType, Policy>& dist, const RealType& k) + { // Cumulative Distribution Function Binomial. + // The random variate k is the number of successes in n trials. + // k argument may be integral, signed, or unsigned, or floating point. + // If necessary, it has already been promoted from an integral type. + + // Returns the sum of the terms 0 through k of the Binomial Probability Density/Mass: + // + // i=k + // -- ( n ) i n-i + // > | | p (1-p) + // -- ( i ) + // i=0 + + // The terms are not summed directly instead + // the incomplete beta integral is employed, + // according to the formula: + // P = I[1-p]( n-k, k+1). + // = 1 - I[p](k + 1, n - k) + + BOOST_MATH_STD_USING // for ADL of std functions + + RealType n = dist.trials(); + RealType p = dist.success_fraction(); + + // Error check: + RealType result; + if(false == binomial_detail::check_dist_and_k( + "boost::math::cdf(binomial_distribution<%1%> const&, %1%)", + n, + p, + k, + &result, Policy())) + { + return result; + } + if (k == n) + { + return 1; + } + + // Special cases, regardless of k. + if (p == 0) + { // This need explanation: + // the pdf is zero for all cases except when k == 0. + // For zero p the probability of zero successes is one. + // Therefore the cdf is always 1: + // the probability of k or *fewer* successes is always 1 + // if there are never any successes! + return 1; + } + if (p == 1) + { // This is correct but needs explanation: + // when k = 1 + // all the cdf and pdf values are zero *except* when k == n, + // and that case has been handled above already. + return 0; + } + // + // P = I[1-p](n - k, k + 1) + // = 1 - I[p](k + 1, n - k) + // Use of ibetac here prevents cancellation errors in calculating + // 1-p if p is very small, perhaps smaller than machine epsilon. + // + // Note that we do not use a finite sum here, since the incomplete + // beta uses a finite sum internally for integer arguments, so + // we'll just let it take care of the necessary logic. + // + return ibetac(k + 1, n - k, p, Policy()); + } // binomial cdf + + template <class RealType, class Policy> + inline RealType cdf(const complemented2_type<binomial_distribution<RealType, Policy>, RealType>& c) + { // Complemented Cumulative Distribution Function Binomial. + // The random variate k is the number of successes in n trials. + // k argument may be integral, signed, or unsigned, or floating point. + // If necessary, it has already been promoted from an integral type. + + // Returns the sum of the terms k+1 through n of the Binomial Probability Density/Mass: + // + // i=n + // -- ( n ) i n-i + // > | | p (1-p) + // -- ( i ) + // i=k+1 + + // The terms are not summed directly instead + // the incomplete beta integral is employed, + // according to the formula: + // Q = 1 -I[1-p]( n-k, k+1). + // = I[p](k + 1, n - k) + + BOOST_MATH_STD_USING // for ADL of std functions + + RealType const& k = c.param; + binomial_distribution<RealType, Policy> const& dist = c.dist; + RealType n = dist.trials(); + RealType p = dist.success_fraction(); + + // Error checks: + RealType result; + if(false == binomial_detail::check_dist_and_k( + "boost::math::cdf(binomial_distribution<%1%> const&, %1%)", + n, + p, + k, + &result, Policy())) + { + return result; + } + + if (k == n) + { // Probability of greater than n successes is necessarily zero: + return 0; + } + + // Special cases, regardless of k. + if (p == 0) + { + // This need explanation: the pdf is zero for all + // cases except when k == 0. For zero p the probability + // of zero successes is one. Therefore the cdf is always + // 1: the probability of *more than* k successes is always 0 + // if there are never any successes! + return 0; + } + if (p == 1) + { + // This needs explanation, when p = 1 + // we always have n successes, so the probability + // of more than k successes is 1 as long as k < n. + // The k == n case has already been handled above. + return 1; + } + // + // Calculate cdf binomial using the incomplete beta function. + // Q = 1 -I[1-p](n - k, k + 1) + // = I[p](k + 1, n - k) + // Use of ibeta here prevents cancellation errors in calculating + // 1-p if p is very small, perhaps smaller than machine epsilon. + // + // Note that we do not use a finite sum here, since the incomplete + // beta uses a finite sum internally for integer arguments, so + // we'll just let it take care of the necessary logic. + // + return ibeta(k + 1, n - k, p, Policy()); + } // binomial cdf + + template <class RealType, class Policy> + inline RealType quantile(const binomial_distribution<RealType, Policy>& dist, const RealType& p) + { + return binomial_detail::quantile_imp(dist, p, RealType(1-p)); + } // quantile + + template <class RealType, class Policy> + RealType quantile(const complemented2_type<binomial_distribution<RealType, Policy>, RealType>& c) + { + return binomial_detail::quantile_imp(c.dist, RealType(1-c.param), c.param); + } // quantile + + template <class RealType, class Policy> + inline RealType mode(const binomial_distribution<RealType, Policy>& dist) + { + BOOST_MATH_STD_USING // ADL of std functions. + RealType p = dist.success_fraction(); + RealType n = dist.trials(); + return floor(p * (n + 1)); + } + + template <class RealType, class Policy> + inline RealType median(const binomial_distribution<RealType, Policy>& dist) + { // Bounds for the median of the negative binomial distribution + // VAN DE VEN R. ; WEBER N. C. ; + // Univ. Sydney, school mathematics statistics, Sydney N.S.W. 2006, AUSTRALIE + // Metrika (Metrika) ISSN 0026-1335 CODEN MTRKA8 + // 1993, vol. 40, no3-4, pp. 185-189 (4 ref.) + + // Bounds for median and 50 percetage point of binomial and negative binomial distribution + // Metrika, ISSN 0026-1335 (Print) 1435-926X (Online) + // Volume 41, Number 1 / December, 1994, DOI 10.1007/BF01895303 + BOOST_MATH_STD_USING // ADL of std functions. + RealType p = dist.success_fraction(); + RealType n = dist.trials(); + // Wikipedia says one of floor(np) -1, floor (np), floor(np) +1 + return floor(p * n); // Chose the middle value. + } + + template <class RealType, class Policy> + inline RealType skewness(const binomial_distribution<RealType, Policy>& dist) + { + BOOST_MATH_STD_USING // ADL of std functions. + RealType p = dist.success_fraction(); + RealType n = dist.trials(); + return (1 - 2 * p) / sqrt(n * p * (1 - p)); + } + + template <class RealType, class Policy> + inline RealType kurtosis(const binomial_distribution<RealType, Policy>& dist) + { + RealType p = dist.success_fraction(); + RealType n = dist.trials(); + return 3 - 6 / n + 1 / (n * p * (1 - p)); + } + + template <class RealType, class Policy> + inline RealType kurtosis_excess(const binomial_distribution<RealType, Policy>& dist) + { + RealType p = dist.success_fraction(); + RealType q = 1 - p; + RealType n = dist.trials(); + return (1 - 6 * p * q) / (n * p * q); + } + + } // namespace math + } // namespace boost + +// This include must be at the end, *after* the accessors +// for this distribution have been defined, in order to +// keep compilers that support two-phase lookup happy. +#include <boost/math/distributions/detail/derived_accessors.hpp> + +#endif // BOOST_MATH_SPECIAL_BINOMIAL_HPP + + diff --git a/Utilities/BGL/boost/math/distributions/cauchy.hpp b/Utilities/BGL/boost/math/distributions/cauchy.hpp new file mode 100644 index 0000000000000000000000000000000000000000..36b4ccbf478fe7860a2b140e34ed444e2b853dea --- /dev/null +++ b/Utilities/BGL/boost/math/distributions/cauchy.hpp @@ -0,0 +1,347 @@ +// Copyright John Maddock 2006, 2007. +// Copyright Paul A. Bristow 2007. + +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_STATS_CAUCHY_HPP +#define BOOST_STATS_CAUCHY_HPP + +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable : 4127) // conditional expression is constant +#endif + +#include <boost/math/distributions/fwd.hpp> +#include <boost/math/constants/constants.hpp> +#include <boost/math/distributions/complement.hpp> +#include <boost/math/distributions/detail/common_error_handling.hpp> +#include <boost/config/no_tr1/cmath.hpp> + +#include <utility> + +namespace boost{ namespace math +{ + +template <class RealType, class Policy> +class cauchy_distribution; + +namespace detail +{ + +template <class RealType, class Policy> +RealType cdf_imp(const cauchy_distribution<RealType, Policy>& dist, const RealType& x, bool complement) +{ + // + // This calculates the cdf of the Cauchy distribution and/or its complement. + // + // The usual formula for the Cauchy cdf is: + // + // cdf = 0.5 + atan(x)/pi + // + // But that suffers from cancellation error as x -> -INF. + // + // Recall that for x < 0: + // + // atan(x) = -pi/2 - atan(1/x) + // + // Substituting into the above we get: + // + // CDF = -atan(1/x) ; x < 0 + // + // So the proceedure is to calculate the cdf for -fabs(x) + // using the above formula, and then subtract from 1 when required + // to get the result. + // + BOOST_MATH_STD_USING // for ADL of std functions + static const char* function = "boost::math::cdf(cauchy<%1%>&, %1%)"; + RealType result; + RealType location = dist.location(); + RealType scale = dist.scale(); + if(false == detail::check_location(function, location, &result, Policy())) + { + return result; + } + if(false == detail::check_scale(function, scale, &result, Policy())) + { + return result; + } + if(std::numeric_limits<RealType>::has_infinity && x == std::numeric_limits<RealType>::infinity()) + { // cdf +infinity is unity. + return static_cast<RealType>((complement) ? 0 : 1); + } + if(std::numeric_limits<RealType>::has_infinity && x == -std::numeric_limits<RealType>::infinity()) + { // cdf -infinity is zero. + return static_cast<RealType>((complement) ? 1 : 0); + } + if(false == detail::check_x(function, x, &result, Policy())) + { // Catches x == NaN + return result; + } + RealType mx = -fabs((x - location) / scale); // scale is > 0 + if(mx > -tools::epsilon<RealType>() / 8) + { // special case first: x extremely close to location. + return 0.5; + } + result = -atan(1 / mx) / constants::pi<RealType>(); + return (((x > location) != complement) ? 1 - result : result); +} // cdf + +template <class RealType, class Policy> +RealType quantile_imp( + const cauchy_distribution<RealType, Policy>& dist, + const RealType& p, + bool complement) +{ + // This routine implements the quantile for the Cauchy distribution, + // the value p may be the probability, or its complement if complement=true. + // + // The procedure first performs argument reduction on p to avoid error + // when calculating the tangent, then calulates the distance from the + // mid-point of the distribution. This is either added or subtracted + // from the location parameter depending on whether `complement` is true. + // + static const char* function = "boost::math::quantile(cauchy<%1%>&, %1%)"; + BOOST_MATH_STD_USING // for ADL of std functions + + RealType result; + RealType location = dist.location(); + RealType scale = dist.scale(); + if(false == detail::check_location(function, location, &result, Policy())) + { + return result; + } + if(false == detail::check_scale(function, scale, &result, Policy())) + { + return result; + } + if(false == detail::check_probability(function, p, &result, Policy())) + { + return result; + } + // Special cases: + if(p == 1) + { + return (complement ? -1 : 1) * policies::raise_overflow_error<RealType>(function, 0, Policy()); + } + if(p == 0) + { + return (complement ? 1 : -1) * policies::raise_overflow_error<RealType>(function, 0, Policy()); + } + + RealType P = p - floor(p); // argument reduction of p: + if(P > 0.5) + { + P = P - 1; + } + if(P == 0.5) // special case: + { + return location; + } + result = -scale / tan(constants::pi<RealType>() * P); + return complement ? RealType(location - result) : RealType(location + result); +} // quantile + +} // namespace detail + +template <class RealType = double, class Policy = policies::policy<> > +class cauchy_distribution +{ +public: + typedef RealType value_type; + typedef Policy policy_type; + + cauchy_distribution(RealType location = 0, RealType scale = 1) + : m_a(location), m_hg(scale) + { + static const char* function = "boost::math::cauchy_distribution<%1%>::cauchy_distribution"; + RealType result; + detail::check_location(function, location, &result, Policy()); + detail::check_scale(function, scale, &result, Policy()); + } // cauchy_distribution + + RealType location()const + { + return m_a; + } + RealType scale()const + { + return m_hg; + } + +private: + RealType m_a; // The location, this is the median of the distribution. + RealType m_hg; // The scale )or shape), this is the half width at half height. +}; + +typedef cauchy_distribution<double> cauchy; + +template <class RealType, class Policy> +inline const std::pair<RealType, RealType> range(const cauchy_distribution<RealType, Policy>&) +{ // Range of permissible values for random variable x. + using boost::math::tools::max_value; + return std::pair<RealType, RealType>(-max_value<RealType>(), max_value<RealType>()); // - to + infinity. +} + +template <class RealType, class Policy> +inline const std::pair<RealType, RealType> support(const cauchy_distribution<RealType, Policy>& ) +{ // Range of supported values for random variable x. + // This is range where cdf rises from 0 to 1, and outside it, the pdf is zero. + return std::pair<RealType, RealType>(-tools::max_value<RealType>(), tools::max_value<RealType>()); // - to + infinity. +} + +template <class RealType, class Policy> +inline RealType pdf(const cauchy_distribution<RealType, Policy>& dist, const RealType& x) +{ + BOOST_MATH_STD_USING // for ADL of std functions + + static const char* function = "boost::math::pdf(cauchy<%1%>&, %1%)"; + RealType result; + RealType location = dist.location(); + RealType scale = dist.scale(); + if(false == detail::check_scale("boost::math::pdf(cauchy<%1%>&, %1%)", scale, &result, Policy())) + { + return result; + } + if(false == detail::check_location("boost::math::pdf(cauchy<%1%>&, %1%)", location, &result, Policy())) + { + return result; + } + if((boost::math::isinf)(x)) + { + return 0; // pdf + and - infinity is zero. + } + // These produce MSVC 4127 warnings, so the above used instead. + //if(std::numeric_limits<RealType>::has_infinity && abs(x) == std::numeric_limits<RealType>::infinity()) + //{ // pdf + and - infinity is zero. + // return 0; + //} + + if(false == detail::check_x(function, x, &result, Policy())) + { // Catches x = NaN + return result; + } + + RealType xs = (x - location) / scale; + result = 1 / (constants::pi<RealType>() * scale * (1 + xs * xs)); + return result; +} // pdf + +template <class RealType, class Policy> +inline RealType cdf(const cauchy_distribution<RealType, Policy>& dist, const RealType& x) +{ + return detail::cdf_imp(dist, x, false); +} // cdf + +template <class RealType, class Policy> +inline RealType quantile(const cauchy_distribution<RealType, Policy>& dist, const RealType& p) +{ + return detail::quantile_imp(dist, p, false); +} // quantile + +template <class RealType, class Policy> +inline RealType cdf(const complemented2_type<cauchy_distribution<RealType, Policy>, RealType>& c) +{ + return detail::cdf_imp(c.dist, c.param, true); +} // cdf complement + +template <class RealType, class Policy> +inline RealType quantile(const complemented2_type<cauchy_distribution<RealType, Policy>, RealType>& c) +{ + return detail::quantile_imp(c.dist, c.param, true); +} // quantile complement + +template <class RealType, class Policy> +inline RealType mean(const cauchy_distribution<RealType, Policy>&) +{ // There is no mean: + typedef typename Policy::assert_undefined_type assert_type; + BOOST_STATIC_ASSERT(assert_type::value == 0); + + return policies::raise_domain_error<RealType>( + "boost::math::mean(cauchy<%1%>&)", + "The Cauchy distribution does not have a mean: " + "the only possible return value is %1%.", + std::numeric_limits<RealType>::quiet_NaN(), Policy()); +} + +template <class RealType, class Policy> +inline RealType variance(const cauchy_distribution<RealType, Policy>& /*dist*/) +{ + // There is no variance: + typedef typename Policy::assert_undefined_type assert_type; + BOOST_STATIC_ASSERT(assert_type::value == 0); + + return policies::raise_domain_error<RealType>( + "boost::math::variance(cauchy<%1%>&)", + "The Cauchy distribution does not have a variance: " + "the only possible return value is %1%.", + std::numeric_limits<RealType>::quiet_NaN(), Policy()); +} + +template <class RealType, class Policy> +inline RealType mode(const cauchy_distribution<RealType, Policy>& dist) +{ + return dist.location(); +} + +template <class RealType, class Policy> +inline RealType median(const cauchy_distribution<RealType, Policy>& dist) +{ + return dist.location(); +} +template <class RealType, class Policy> +inline RealType skewness(const cauchy_distribution<RealType, Policy>& /*dist*/) +{ + // There is no skewness: + typedef typename Policy::assert_undefined_type assert_type; + BOOST_STATIC_ASSERT(assert_type::value == 0); + + return policies::raise_domain_error<RealType>( + "boost::math::skewness(cauchy<%1%>&)", + "The Cauchy distribution does not have a skewness: " + "the only possible return value is %1%.", + std::numeric_limits<RealType>::quiet_NaN(), Policy()); // infinity? +} + +template <class RealType, class Policy> +inline RealType kurtosis(const cauchy_distribution<RealType, Policy>& /*dist*/) +{ + // There is no kurtosis: + typedef typename Policy::assert_undefined_type assert_type; + BOOST_STATIC_ASSERT(assert_type::value == 0); + + return policies::raise_domain_error<RealType>( + "boost::math::kurtosis(cauchy<%1%>&)", + "The Cauchy distribution does not have a kurtosis: " + "the only possible return value is %1%.", + std::numeric_limits<RealType>::quiet_NaN(), Policy()); +} + +template <class RealType, class Policy> +inline RealType kurtosis_excess(const cauchy_distribution<RealType, Policy>& /*dist*/) +{ + // There is no kurtosis excess: + typedef typename Policy::assert_undefined_type assert_type; + BOOST_STATIC_ASSERT(assert_type::value == 0); + + return policies::raise_domain_error<RealType>( + "boost::math::kurtosis_excess(cauchy<%1%>&)", + "The Cauchy distribution does not have a kurtosis: " + "the only possible return value is %1%.", + std::numeric_limits<RealType>::quiet_NaN(), Policy()); +} + +} // namespace math +} // namespace boost + +#ifdef _MSC_VER +#pragma warning(pop) +#endif + +// This include must be at the end, *after* the accessors +// for this distribution have been defined, in order to +// keep compilers that support two-phase lookup happy. +#include <boost/math/distributions/detail/derived_accessors.hpp> + +#endif // BOOST_STATS_CAUCHY_HPP diff --git a/Utilities/BGL/boost/math/distributions/chi_squared.hpp b/Utilities/BGL/boost/math/distributions/chi_squared.hpp new file mode 100644 index 0000000000000000000000000000000000000000..4334065361712a1d0d4662afac0bac5793f2eda4 --- /dev/null +++ b/Utilities/BGL/boost/math/distributions/chi_squared.hpp @@ -0,0 +1,338 @@ +// Copyright John Maddock 2006, 2007. +// Copyright Paul A. Bristow 2008. + +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_DISTRIBUTIONS_CHI_SQUARED_HPP +#define BOOST_MATH_DISTRIBUTIONS_CHI_SQUARED_HPP + +#include <boost/math/distributions/fwd.hpp> +#include <boost/math/special_functions/gamma.hpp> // for incomplete beta. +#include <boost/math/distributions/complement.hpp> // complements +#include <boost/math/distributions/detail/common_error_handling.hpp> // error checks +#include <boost/math/special_functions/fpclassify.hpp> + +#include <utility> + +namespace boost{ namespace math{ + +template <class RealType = double, class Policy = policies::policy<> > +class chi_squared_distribution +{ +public: + typedef RealType value_type; + typedef Policy policy_type; + + chi_squared_distribution(RealType i) : m_df(i) + { + RealType result; + detail::check_df( + "boost::math::chi_squared_distribution<%1%>::chi_squared_distribution", m_df, &result, Policy()); + } // chi_squared_distribution + + RealType degrees_of_freedom()const + { + return m_df; + } + + // Parameter estimation: + static RealType find_degrees_of_freedom( + RealType difference_from_variance, + RealType alpha, + RealType beta, + RealType variance, + RealType hint = 100); + +private: + // + // Data member: + // + RealType m_df; // degrees of freedom are a real number. +}; // class chi_squared_distribution + +typedef chi_squared_distribution<double> chi_squared; + +template <class RealType, class Policy> +inline const std::pair<RealType, RealType> range(const chi_squared_distribution<RealType, Policy>& /*dist*/) +{ // Range of permissible values for random variable x. + using boost::math::tools::max_value; + return std::pair<RealType, RealType>(0, max_value<RealType>()); // 0 to + infinity. +} + +template <class RealType, class Policy> +inline const std::pair<RealType, RealType> support(const chi_squared_distribution<RealType, Policy>& /*dist*/) +{ // Range of supported values for random variable x. + // This is range where cdf rises from 0 to 1, and outside it, the pdf is zero. + return std::pair<RealType, RealType>(0, tools::max_value<RealType>()); // 0 to + infinity. +} + +template <class RealType, class Policy> +RealType pdf(const chi_squared_distribution<RealType, Policy>& dist, const RealType& chi_square) +{ + BOOST_MATH_STD_USING // for ADL of std functions + RealType degrees_of_freedom = dist.degrees_of_freedom(); + // Error check: + RealType error_result; + + static const char* function = "boost::math::pdf(const chi_squared_distribution<%1%>&, %1%)"; + + if(false == detail::check_df( + function, degrees_of_freedom, &error_result, Policy())) + return error_result; + + if((chi_square < 0) || !(boost::math::isfinite)(chi_square)) + { + return policies::raise_domain_error<RealType>( + function, "Chi Square parameter was %1%, but must be > 0 !", chi_square, Policy()); + } + + if(chi_square == 0) + { + // Handle special cases: + if(degrees_of_freedom < 2) + { + return policies::raise_overflow_error<RealType>( + function, 0, Policy()); + } + else if(degrees_of_freedom == 2) + { + return 0.5f; + } + else + { + return 0; + } + } + + return gamma_p_derivative(degrees_of_freedom / 2, chi_square / 2, Policy()) / 2; +} // pdf + +template <class RealType, class Policy> +inline RealType cdf(const chi_squared_distribution<RealType, Policy>& dist, const RealType& chi_square) +{ + RealType degrees_of_freedom = dist.degrees_of_freedom(); + // Error check: + RealType error_result; + static const char* function = "boost::math::cdf(const chi_squared_distribution<%1%>&, %1%)"; + + if(false == detail::check_df( + function, degrees_of_freedom, &error_result, Policy())) + return error_result; + + if((chi_square < 0) || !(boost::math::isfinite)(chi_square)) + { + return policies::raise_domain_error<RealType>( + function, "Chi Square parameter was %1%, but must be > 0 !", chi_square, Policy()); + } + + return boost::math::gamma_p(degrees_of_freedom / 2, chi_square / 2, Policy()); +} // cdf + +template <class RealType, class Policy> +inline RealType quantile(const chi_squared_distribution<RealType, Policy>& dist, const RealType& p) +{ + RealType degrees_of_freedom = dist.degrees_of_freedom(); + static const char* function = "boost::math::quantile(const chi_squared_distribution<%1%>&, %1%)"; + // Error check: + RealType error_result; + if(false == detail::check_df( + function, degrees_of_freedom, &error_result, Policy()) + && detail::check_probability( + function, p, &error_result, Policy())) + return error_result; + + return 2 * boost::math::gamma_p_inv(degrees_of_freedom / 2, p, Policy()); +} // quantile + +template <class RealType, class Policy> +inline RealType cdf(const complemented2_type<chi_squared_distribution<RealType, Policy>, RealType>& c) +{ + RealType const& degrees_of_freedom = c.dist.degrees_of_freedom(); + RealType const& chi_square = c.param; + static const char* function = "boost::math::cdf(const chi_squared_distribution<%1%>&, %1%)"; + // Error check: + RealType error_result; + if(false == detail::check_df( + function, degrees_of_freedom, &error_result, Policy())) + return error_result; + + if((chi_square < 0) || !(boost::math::isfinite)(chi_square)) + { + return policies::raise_domain_error<RealType>( + function, "Chi Square parameter was %1%, but must be > 0 !", chi_square, Policy()); + } + + return boost::math::gamma_q(degrees_of_freedom / 2, chi_square / 2, Policy()); +} + +template <class RealType, class Policy> +inline RealType quantile(const complemented2_type<chi_squared_distribution<RealType, Policy>, RealType>& c) +{ + RealType const& degrees_of_freedom = c.dist.degrees_of_freedom(); + RealType const& q = c.param; + static const char* function = "boost::math::quantile(const chi_squared_distribution<%1%>&, %1%)"; + // Error check: + RealType error_result; + if(false == detail::check_df( + function, degrees_of_freedom, &error_result, Policy()) + && detail::check_probability( + function, q, &error_result, Policy())) + return error_result; + + return 2 * boost::math::gamma_q_inv(degrees_of_freedom / 2, q, Policy()); +} + +template <class RealType, class Policy> +inline RealType mean(const chi_squared_distribution<RealType, Policy>& dist) +{ // Mean of Chi-Squared distribution = v. + return dist.degrees_of_freedom(); +} // mean + +template <class RealType, class Policy> +inline RealType variance(const chi_squared_distribution<RealType, Policy>& dist) +{ // Variance of Chi-Squared distribution = 2v. + return 2 * dist.degrees_of_freedom(); +} // variance + +template <class RealType, class Policy> +inline RealType mode(const chi_squared_distribution<RealType, Policy>& dist) +{ + RealType df = dist.degrees_of_freedom(); + static const char* function = "boost::math::mode(const chi_squared_distribution<%1%>&)"; + // Most sources only define mode for df >= 2, + // but for 0 <= df <= 2, the pdf maximum actually occurs at random variate = 0; + // So one could extend the definition of mode thus: + //if(df < 0) + //{ + // return policies::raise_domain_error<RealType>( + // function, + // "Chi-Squared distribution only has a mode for degrees of freedom >= 0, but got degrees of freedom = %1%.", + // df, Policy()); + //} + //return (df <= 2) ? 0 : df - 2; + + if(df < 2) + return policies::raise_domain_error<RealType>( + function, + "Chi-Squared distribution only has a mode for degrees of freedom >= 2, but got degrees of freedom = %1%.", + df, Policy()); + return df - 2; +} + +//template <class RealType, class Policy> +//inline RealType median(const chi_squared_distribution<RealType, Policy>& dist) +//{ // Median is given by Quantile[dist, 1/2] +// RealType df = dist.degrees_of_freedom(); +// if(df <= 1) +// return tools::domain_error<RealType>( +// BOOST_CURRENT_FUNCTION, +// "The Chi-Squared distribution only has a mode for degrees of freedom >= 2, but got degrees of freedom = %1%.", +// df); +// return df - RealType(2)/3; +//} +// Now implemented via quantile(half) in derived accessors. + +template <class RealType, class Policy> +inline RealType skewness(const chi_squared_distribution<RealType, Policy>& dist) +{ + BOOST_MATH_STD_USING // For ADL + RealType df = dist.degrees_of_freedom(); + return sqrt (8 / df); // == 2 * sqrt(2 / df); +} + +template <class RealType, class Policy> +inline RealType kurtosis(const chi_squared_distribution<RealType, Policy>& dist) +{ + RealType df = dist.degrees_of_freedom(); + return 3 + 12 / df; +} + +template <class RealType, class Policy> +inline RealType kurtosis_excess(const chi_squared_distribution<RealType, Policy>& dist) +{ + RealType df = dist.degrees_of_freedom(); + return 12 / df; +} + +// +// Parameter estimation comes last: +// +namespace detail +{ + +template <class RealType, class Policy> +struct df_estimator +{ + df_estimator(RealType a, RealType b, RealType variance, RealType delta) + : alpha(a), beta(b), ratio(delta/variance) {} + + RealType operator()(const RealType& df) + { + if(df <= tools::min_value<RealType>()) + return 1; + chi_squared_distribution<RealType, Policy> cs(df); + + RealType result; + if(ratio > 0) + { + RealType r = 1 + ratio; + result = cdf(cs, quantile(complement(cs, alpha)) / r) - beta; + } + else + { + RealType r = 1 + ratio; + result = cdf(complement(cs, quantile(cs, alpha) / r)) - beta; + } + return result; + } +private: + RealType alpha, beta, ratio; +}; + +} // namespace detail + +template <class RealType, class Policy> +RealType chi_squared_distribution<RealType, Policy>::find_degrees_of_freedom( + RealType difference_from_variance, + RealType alpha, + RealType beta, + RealType variance, + RealType hint) +{ + static const char* function = "boost::math::chi_squared_distribution<%1%>::find_degrees_of_freedom(%1%,%1%,%1%,%1%,%1%)"; + // Check for domain errors: + RealType error_result; + if(false == detail::check_probability( + function, alpha, &error_result, Policy()) + && detail::check_probability(function, beta, &error_result, Policy())) + return error_result; + + if(hint <= 0) + hint = 1; + + detail::df_estimator<RealType, Policy> f(alpha, beta, variance, difference_from_variance); + tools::eps_tolerance<RealType> tol(policies::digits<RealType, Policy>()); + boost::uintmax_t max_iter = policies::get_max_root_iterations<Policy>(); + std::pair<RealType, RealType> r = tools::bracket_and_solve_root(f, hint, RealType(2), false, tol, max_iter, Policy()); + RealType result = r.first + (r.second - r.first) / 2; + if(max_iter >= policies::get_max_root_iterations<Policy>()) + { + policies::raise_evaluation_error<RealType>(function, "Unable to locate solution in a reasonable time:" + " either there is no answer to how many degrees of freedom are required" + " or the answer is infinite. Current best guess is %1%", result, Policy()); + } + return result; +} + +} // namespace math +} // namespace boost + +// This include must be at the end, *after* the accessors +// for this distribution have been defined, in order to +// keep compilers that support two-phase lookup happy. +#include <boost/math/distributions/detail/derived_accessors.hpp> + +#endif // BOOST_MATH_DISTRIBUTIONS_CHI_SQUARED_HPP diff --git a/Utilities/BGL/boost/math/distributions/complement.hpp b/Utilities/BGL/boost/math/distributions/complement.hpp new file mode 100644 index 0000000000000000000000000000000000000000..0d5508c9827e6ca361700cdeb49bbdba2bdeab90 --- /dev/null +++ b/Utilities/BGL/boost/math/distributions/complement.hpp @@ -0,0 +1,195 @@ +// (C) Copyright John Maddock 2006. +// (C) Copyright Paul A. Bristow 2006. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_STATS_COMPLEMENT_HPP +#define BOOST_STATS_COMPLEMENT_HPP + +// +// This code really defines our own tuple type. +// It would be nice to reuse std::tr1::tuple +// while retaining our own type safety, but it's +// not clear if that's possible. In any case this +// code is *very* lightweight. +// +namespace boost{ namespace math{ + +template <class Dist, class RealType> +struct complemented2_type +{ + complemented2_type( + const Dist& d, + const RealType& p1) + : dist(d), + param(p1) {} + + const Dist& dist; + const RealType& param; + +private: + complemented2_type& operator=(const complemented2_type&); +}; + +template <class Dist, class RealType1, class RealType2> +struct complemented3_type +{ + complemented3_type( + const Dist& d, + const RealType1& p1, + const RealType2& p2) + : dist(d), + param1(p1), + param2(p2) {} + + const Dist& dist; + const RealType1& param1; + const RealType2& param2; +private: + complemented3_type& operator=(const complemented3_type&); +}; + +template <class Dist, class RealType1, class RealType2, class RealType3> +struct complemented4_type +{ + complemented4_type( + const Dist& d, + const RealType1& p1, + const RealType2& p2, + const RealType3& p3) + : dist(d), + param1(p1), + param2(p2), + param3(p3) {} + + const Dist& dist; + const RealType1& param1; + const RealType2& param2; + const RealType3& param3; +private: + complemented4_type& operator=(const complemented4_type&); +}; + +template <class Dist, class RealType1, class RealType2, class RealType3, class RealType4> +struct complemented5_type +{ + complemented5_type( + const Dist& d, + const RealType1& p1, + const RealType2& p2, + const RealType3& p3, + const RealType4& p4) + : dist(d), + param1(p1), + param2(p2), + param3(p3), + param4(p4) {} + + const Dist& dist; + const RealType1& param1; + const RealType2& param2; + const RealType3& param3; + const RealType4& param4; +private: + complemented5_type& operator=(const complemented5_type&); +}; + +template <class Dist, class RealType1, class RealType2, class RealType3, class RealType4, class RealType5> +struct complemented6_type +{ + complemented6_type( + const Dist& d, + const RealType1& p1, + const RealType2& p2, + const RealType3& p3, + const RealType4& p4, + const RealType5& p5) + : dist(d), + param1(p1), + param2(p2), + param3(p3), + param4(p4), + param5(p5) {} + + const Dist& dist; + const RealType1& param1; + const RealType2& param2; + const RealType3& param3; + const RealType4& param4; + const RealType5& param5; +private: + complemented6_type& operator=(const complemented6_type&); +}; + +template <class Dist, class RealType1, class RealType2, class RealType3, class RealType4, class RealType5, class RealType6> +struct complemented7_type +{ + complemented7_type( + const Dist& d, + const RealType1& p1, + const RealType2& p2, + const RealType3& p3, + const RealType4& p4, + const RealType5& p5, + const RealType6& p6) + : dist(d), + param1(p1), + param2(p2), + param3(p3), + param4(p4), + param5(p5), + param6(p6) {} + + const Dist& dist; + const RealType1& param1; + const RealType2& param2; + const RealType3& param3; + const RealType4& param4; + const RealType5& param5; + const RealType6& param6; +private: + complemented7_type& operator=(const complemented7_type&); +}; + +template <class Dist, class RealType> +inline complemented2_type<Dist, RealType> complement(const Dist& d, const RealType& r) +{ + return complemented2_type<Dist, RealType>(d, r); +} + +template <class Dist, class RealType1, class RealType2> +inline complemented3_type<Dist, RealType1, RealType2> complement(const Dist& d, const RealType1& r1, const RealType2& r2) +{ + return complemented3_type<Dist, RealType1, RealType2>(d, r1, r2); +} + +template <class Dist, class RealType1, class RealType2, class RealType3> +inline complemented4_type<Dist, RealType1, RealType2, RealType3> complement(const Dist& d, const RealType1& r1, const RealType2& r2, const RealType3& r3) +{ + return complemented4_type<Dist, RealType1, RealType2, RealType3>(d, r1, r2, r3); +} + +template <class Dist, class RealType1, class RealType2, class RealType3, class RealType4> +inline complemented5_type<Dist, RealType1, RealType2, RealType3, RealType4> complement(const Dist& d, const RealType1& r1, const RealType2& r2, const RealType3& r3, const RealType4& r4) +{ + return complemented5_type<Dist, RealType1, RealType2, RealType3, RealType4>(d, r1, r2, r3, r4); +} + +template <class Dist, class RealType1, class RealType2, class RealType3, class RealType4, class RealType5> +inline complemented6_type<Dist, RealType1, RealType2, RealType3, RealType4, RealType5> complement(const Dist& d, const RealType1& r1, const RealType2& r2, const RealType3& r3, const RealType4& r4, const RealType5& r5) +{ + return complemented6_type<Dist, RealType1, RealType2, RealType3, RealType4, RealType5>(d, r1, r2, r3, r4, r5); +} + +template <class Dist, class RealType1, class RealType2, class RealType3, class RealType4, class RealType5, class RealType6> +inline complemented7_type<Dist, RealType1, RealType2, RealType3, RealType4, RealType5, RealType6> complement(const Dist& d, const RealType1& r1, const RealType2& r2, const RealType3& r3, const RealType4& r4, const RealType5& r5, const RealType6& r6) +{ + return complemented7_type<Dist, RealType1, RealType2, RealType3, RealType4, RealType5, RealType6>(d, r1, r2, r3, r4, r5, r6); +} + +} // namespace math +} // namespace boost + +#endif // BOOST_STATS_COMPLEMENT_HPP + diff --git a/Utilities/BGL/boost/math/distributions/detail/common_error_handling.hpp b/Utilities/BGL/boost/math/distributions/detail/common_error_handling.hpp new file mode 100644 index 0000000000000000000000000000000000000000..950920b5e50e4773f6748fa06c15f400c7481dc4 --- /dev/null +++ b/Utilities/BGL/boost/math/distributions/detail/common_error_handling.hpp @@ -0,0 +1,157 @@ +// Copyright John Maddock 2006, 2007. +// Copyright Paul A. Bristow 2006, 2007. + +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_DISTRIBUTIONS_COMMON_ERROR_HANDLING_HPP +#define BOOST_MATH_DISTRIBUTIONS_COMMON_ERROR_HANDLING_HPP + +#include <boost/math/policies/error_handling.hpp> +#include <boost/math/special_functions/fpclassify.hpp> +// using boost::math::isfinite; + +namespace boost{ namespace math{ namespace detail +{ + +template <class RealType, class Policy> +inline bool check_probability(const char* function, RealType const& prob, RealType* result, const Policy& pol) +{ + if((prob < 0) || (prob > 1) || !(boost::math::isfinite)(prob)) + { + *result = policies::raise_domain_error<RealType>( + function, + "Probability argument is %1%, but must be >= 0 and <= 1 !", prob, pol); + return false; + } + return true; +} + +template <class RealType, class Policy> +inline bool check_df(const char* function, RealType const& df, RealType* result, const Policy& pol) +{ + if((df <= 0) || !(boost::math::isfinite)(df)) + { + *result = policies::raise_domain_error<RealType>( + function, + "Degrees of freedom argument is %1%, but must be > 0 !", df, pol); + return false; + } + return true; +} + +template <class RealType, class Policy> +inline bool check_scale( + const char* function, + RealType scale, + RealType* result, + const Policy& pol) +{ + if((scale <= 0) || !(boost::math::isfinite)(scale)) + { // Assume scale == 0 is NOT valid for any distribution. + *result = policies::raise_domain_error<RealType>( + function, + "Scale parameter is %1%, but must be > 0 !", scale, pol); + return false; + } + return true; +} + +template <class RealType, class Policy> +inline bool check_location( + const char* function, + RealType location, + RealType* result, + const Policy& pol) +{ + if(!(boost::math::isfinite)(location)) + { + *result = policies::raise_domain_error<RealType>( + function, + "Location parameter is %1%, but must be finite!", location, pol); + return false; + } + return true; +} + +template <class RealType, class Policy> +inline bool check_x( + const char* function, + RealType x, + RealType* result, + const Policy& pol) +{ + if(!(boost::math::isfinite)(x)) + { + *result = policies::raise_domain_error<RealType>( + function, + "Random variate x is %1%, but must be finite!", x, pol); + return false; + } + return true; + // Note that this test catches both infinity and NaN. + // Some special cases permit x to be infinite, so these must be tested 1st, + // leaving this test to catch any NaNs. see Normal and cauchy for example. +} + +template <class RealType, class Policy> +inline bool check_positive_x( + const char* function, + RealType x, + RealType* result, + const Policy& pol) +{ + if(!(boost::math::isfinite)(x) || (x < 0)) + { + *result = policies::raise_domain_error<RealType>( + function, + "Random variate x is %1%, but must be finite and >= 0!", x, pol); + return false; + } + return true; + // Note that this test catches both infinity and NaN. + // Some special cases permit x to be infinite, so these must be tested 1st, + // leaving this test to catch any NaNs. see Normal and cauchy for example. +} + +template <class RealType, class Policy> +inline bool check_non_centrality( + const char* function, + RealType ncp, + RealType* result, + const Policy& pol) +{ + if((ncp < 0) || !(boost::math::isfinite)(ncp)) + { // Assume scale == 0 is NOT valid for any distribution. + *result = policies::raise_domain_error<RealType>( + function, + "Non centrality parameter is %1%, but must be > 0 !", ncp, pol); + return false; + } + return true; +} + +template <class RealType, class Policy> +inline bool check_finite( + const char* function, + RealType x, + RealType* result, + const Policy& pol) +{ + if(!(boost::math::isfinite)(x)) + { // Assume scale == 0 is NOT valid for any distribution. + *result = policies::raise_domain_error<RealType>( + function, + "Parameter is %1%, but must be finite !", x, pol); + return false; + } + return true; +} + +} // namespace detail +} // namespace math +} // namespace boost + +#endif // BOOST_MATH_DISTRIBUTIONS_COMMON_ERROR_HANDLING_HPP diff --git a/Utilities/BGL/boost/math/distributions/detail/derived_accessors.hpp b/Utilities/BGL/boost/math/distributions/detail/derived_accessors.hpp new file mode 100644 index 0000000000000000000000000000000000000000..ef5f895d5a8a798d10f9d8d764ff42f5ece69021 --- /dev/null +++ b/Utilities/BGL/boost/math/distributions/detail/derived_accessors.hpp @@ -0,0 +1,163 @@ +// Copyright John Maddock 2006. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_STATS_DERIVED_HPP +#define BOOST_STATS_DERIVED_HPP + +// This file implements various common properties of distributions +// that can be implemented in terms of other properties: +// variance OR standard deviation (see note below), +// hazard, cumulative hazard (chf), coefficient_of_variation. +// +// Note that while both variance and standard_deviation are provided +// here, each distribution MUST SPECIALIZE AT LEAST ONE OF THESE +// otherwise these two versions will just call each other over and over +// until stack space runs out ... + +// Of course there may be more efficient means of implementing these +// that are specific to a particular distribution, but these generic +// versions give these properties "for free" with most distributions. +// +// In order to make use of this header, it must be included AT THE END +// of the distribution header, AFTER the distribution and its core +// property accessors have been defined: this is so that compilers +// that implement 2-phase lookup and early-type-checking of templates +// can find the definitions refered to herein. +// + +#include <boost/type_traits/is_same.hpp> +#include <boost/static_assert.hpp> + +#ifdef BOOST_MSVC +# pragma warning(push) +# pragma warning(disable: 4723) // potential divide by 0 +// Suppressing spurious warning in coefficient_of_variation +#endif + +namespace boost{ namespace math{ + +template <class Distribution> +typename Distribution::value_type variance(const Distribution& dist); + +template <class Distribution> +inline typename Distribution::value_type standard_deviation(const Distribution& dist) +{ + BOOST_MATH_STD_USING // ADL of sqrt. + return sqrt(variance(dist)); +} + +template <class Distribution> +inline typename Distribution::value_type variance(const Distribution& dist) +{ + typename Distribution::value_type result = standard_deviation(dist); + return result * result; +} + +template <class Distribution, class RealType> +inline typename Distribution::value_type hazard(const Distribution& dist, const RealType& x) +{ // hazard function + // http://www.itl.nist.gov/div898/handbook/eda/section3/eda362.htm#HAZ + typedef typename Distribution::value_type value_type; + typedef typename Distribution::policy_type policy_type; + value_type p = cdf(complement(dist, x)); + value_type d = pdf(dist, x); + if(d > p * tools::max_value<value_type>()) + return policies::raise_overflow_error<value_type>( + "boost::math::hazard(const Distribution&, %1%)", 0, policy_type()); + if(d == 0) + { + // This protects against 0/0, but is it the right thing to do? + return 0; + } + return d / p; +} + +template <class Distribution, class RealType> +inline typename Distribution::value_type chf(const Distribution& dist, const RealType& x) +{ // cumulative hazard function. + // http://www.itl.nist.gov/div898/handbook/eda/section3/eda362.htm#HAZ + BOOST_MATH_STD_USING + return -log(cdf(complement(dist, x))); +} + +template <class Distribution> +inline typename Distribution::value_type coefficient_of_variation(const Distribution& dist) +{ + typedef typename Distribution::value_type value_type; + typedef typename Distribution::policy_type policy_type; + + using std::abs; + + value_type m = mean(dist); + value_type d = standard_deviation(dist); + if((abs(m) < 1) && (d > abs(m) * tools::max_value<value_type>())) + { // Checks too that m is not zero, + return policies::raise_overflow_error<value_type>("boost::math::coefficient_of_variation(const Distribution&, %1%)", 0, policy_type()); + } + return d / m; // so MSVC warning on zerodivide is spurious, and suppressed. +} +// +// Next follow overloads of some of the standard accessors with mixed +// argument types. We just use a typecast to forward on to the "real" +// implementation with all arguments of the same type: +// +template <class Distribution, class RealType> +inline typename Distribution::value_type pdf(const Distribution& dist, const RealType& x) +{ + typedef typename Distribution::value_type value_type; + return pdf(dist, static_cast<value_type>(x)); +} +template <class Distribution, class RealType> +inline typename Distribution::value_type cdf(const Distribution& dist, const RealType& x) +{ + typedef typename Distribution::value_type value_type; + return cdf(dist, static_cast<value_type>(x)); +} +template <class Distribution, class RealType> +inline typename Distribution::value_type quantile(const Distribution& dist, const RealType& x) +{ + typedef typename Distribution::value_type value_type; + return quantile(dist, static_cast<value_type>(x)); +} +/* +template <class Distribution, class RealType> +inline typename Distribution::value_type chf(const Distribution& dist, const RealType& x) +{ + typedef typename Distribution::value_type value_type; + return chf(dist, static_cast<value_type>(x)); +} +*/ +template <class Distribution, class RealType> +inline typename Distribution::value_type cdf(const complemented2_type<Distribution, RealType>& c) +{ + typedef typename Distribution::value_type value_type; + return cdf(complement(c.dist, static_cast<value_type>(c.param))); +} + +template <class Distribution, class RealType> +inline typename Distribution::value_type quantile(const complemented2_type<Distribution, RealType>& c) +{ + typedef typename Distribution::value_type value_type; + return quantile(complement(c.dist, static_cast<value_type>(c.param))); +} + +template <class Dist> +inline typename Dist::value_type median(const Dist& d) +{ // median - default definition for those distributions for which a + // simple closed form is not known, + // and for which a domain_error and/or NaN generating function is NOT defined. + typedef typename Dist::value_type value_type; + return quantile(d, static_cast<value_type>(0.5f)); +} + +} // namespace math +} // namespace boost + + +#ifdef BOOST_MSVC +# pragma warning(pop) +#endif + +#endif // BOOST_STATS_DERIVED_HPP diff --git a/Utilities/BGL/boost/math/distributions/detail/generic_mode.hpp b/Utilities/BGL/boost/math/distributions/detail/generic_mode.hpp new file mode 100644 index 0000000000000000000000000000000000000000..bf77a833935f563d009bb4e0ccadc39b18be505e --- /dev/null +++ b/Utilities/BGL/boost/math/distributions/detail/generic_mode.hpp @@ -0,0 +1,149 @@ +// Copyright John Maddock 2008. + +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_DISTRIBUTIONS_DETAIL_MODE_HPP +#define BOOST_MATH_DISTRIBUTIONS_DETAIL_MODE_HPP + +#include <boost/math/tools/minima.hpp> // function minimization for mode +#include <boost/math/policies/error_handling.hpp> +#include <boost/math/distributions/fwd.hpp> + +namespace boost{ namespace math{ namespace detail{ + +template <class Dist> +struct pdf_minimizer +{ + pdf_minimizer(const Dist& d) + : dist(d) {} + + typename Dist::value_type operator()(const typename Dist::value_type& x) + { + return -pdf(dist, x); + } +private: + Dist dist; +}; + +template <class Dist> +typename Dist::value_type generic_find_mode(const Dist& dist, typename Dist::value_type guess, const char* function, typename Dist::value_type step = 0) +{ + BOOST_MATH_STD_USING + typedef typename Dist::value_type value_type; + typedef typename Dist::policy_type policy_type; + // + // Need to begin by bracketing the maxima of the PDF: + // + value_type maxval; + value_type upper_bound = guess; + value_type lower_bound; + value_type v = pdf(dist, guess); + if(v == 0) + { + // + // Oops we don't know how to handle this, or even in which + // direction we should move in, treat as an evaluation error: + // + policies::raise_evaluation_error( + function, + "Could not locate a starting location for the search for the mode, original guess was %1%", guess, policy_type()); + } + do + { + maxval = v; + if(step != 0) + upper_bound += step; + else + upper_bound *= 2; + v = pdf(dist, upper_bound); + }while(maxval < v); + + lower_bound = upper_bound; + do + { + maxval = v; + if(step != 0) + lower_bound -= step; + else + lower_bound /= 2; + v = pdf(dist, lower_bound); + }while(maxval < v); + + boost::uintmax_t max_iter = policies::get_max_root_iterations<policy_type>(); + + value_type result = tools::brent_find_minima( + pdf_minimizer<Dist>(dist), + lower_bound, + upper_bound, + policies::digits<value_type, policy_type>(), + max_iter).first; + if(max_iter >= policies::get_max_root_iterations<policy_type>()) + { + return policies::raise_evaluation_error<value_type>( + function, + "Unable to locate solution in a reasonable time:" + " either there is no answer to the mode of the distribution" + " or the answer is infinite. Current best guess is %1%", result, policy_type()); + } + return result; +} +// +// As above,but confined to the interval [0,1]: +// +template <class Dist> +typename Dist::value_type generic_find_mode_01(const Dist& dist, typename Dist::value_type guess, const char* function) +{ + BOOST_MATH_STD_USING + typedef typename Dist::value_type value_type; + typedef typename Dist::policy_type policy_type; + // + // Need to begin by bracketing the maxima of the PDF: + // + value_type maxval; + value_type upper_bound = guess; + value_type lower_bound; + value_type v = pdf(dist, guess); + do + { + maxval = v; + upper_bound = 1 - (1 - upper_bound) / 2; + if(upper_bound == 1) + return 1; + v = pdf(dist, upper_bound); + }while(maxval < v); + + lower_bound = upper_bound; + do + { + maxval = v; + lower_bound /= 2; + if(lower_bound < tools::min_value<value_type>()) + return 0; + v = pdf(dist, lower_bound); + }while(maxval < v); + + boost::uintmax_t max_iter = policies::get_max_root_iterations<policy_type>(); + + value_type result = tools::brent_find_minima( + pdf_minimizer<Dist>(dist), + lower_bound, + upper_bound, + policies::digits<value_type, policy_type>(), + max_iter).first; + if(max_iter >= policies::get_max_root_iterations<policy_type>()) + { + return policies::raise_evaluation_error<value_type>( + function, + "Unable to locate solution in a reasonable time:" + " either there is no answer to the mode of the distribution" + " or the answer is infinite. Current best guess is %1%", result, policy_type()); + } + return result; +} + +}}} // namespaces + +#endif // BOOST_MATH_DISTRIBUTIONS_DETAIL_MODE_HPP diff --git a/Utilities/BGL/boost/math/distributions/detail/generic_quantile.hpp b/Utilities/BGL/boost/math/distributions/detail/generic_quantile.hpp new file mode 100644 index 0000000000000000000000000000000000000000..fe8e3c6a9c55639a571d96b2f66a5fe900527119 --- /dev/null +++ b/Utilities/BGL/boost/math/distributions/detail/generic_quantile.hpp @@ -0,0 +1,91 @@ +// Copyright John Maddock 2008. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_DISTIBUTIONS_DETAIL_GENERIC_QUANTILE_HPP +#define BOOST_MATH_DISTIBUTIONS_DETAIL_GENERIC_QUANTILE_HPP + +namespace boost{ namespace math{ namespace detail{ + +template <class Dist> +struct generic_quantile_finder +{ + typedef typename Dist::value_type value_type; + typedef typename Dist::policy_type policy_type; + + generic_quantile_finder(const Dist& d, value_type t, bool c) + : dist(d), target(t), comp(c) {} + + value_type operator()(const value_type& x) + { + return comp ? + target - cdf(complement(dist, x)) + : cdf(dist, x) - target; + } + +private: + Dist dist; + value_type target; + bool comp; +}; + +template <class T, class Policy> +inline T check_range_result(const T& x, const Policy& pol, const char* function) +{ + if((x >= 0) && (x < tools::min_value<T>())) + return policies::raise_underflow_error<T>(function, 0, pol); + if(x <= -tools::max_value<T>()) + return -policies::raise_overflow_error<T>(function, 0, pol); + if(x >= tools::max_value<T>()) + return policies::raise_overflow_error<T>(function, 0, pol); + return x; +} + +template <class Dist> +typename Dist::value_type generic_quantile(const Dist& dist, const typename Dist::value_type& p, const typename Dist::value_type& guess, bool comp, const char* function) +{ + typedef typename Dist::value_type value_type; + typedef typename Dist::policy_type policy_type; + typedef typename policies::normalise< + policy_type, + policies::promote_float<false>, + policies::promote_double<false>, + policies::discrete_quantile<>, + policies::assert_undefined<> >::type forwarding_policy; + + // + // Special cases first: + // + if(p == 0) + { + return comp + ? check_range_result(range(dist).second, forwarding_policy(), function) + : check_range_result(range(dist).first, forwarding_policy(), function); + } + if(p == 1) + { + return !comp + ? check_range_result(range(dist).second, forwarding_policy(), function) + : check_range_result(range(dist).first, forwarding_policy(), function); + } + + generic_quantile_finder<Dist> f(dist, p, comp); + tools::eps_tolerance<value_type> tol(policies::digits<value_type, forwarding_policy>() - 3); + boost::uintmax_t max_iter = policies::get_max_root_iterations<forwarding_policy>(); + std::pair<value_type, value_type> ir = tools::bracket_and_solve_root( + f, guess, value_type(2), true, tol, max_iter, forwarding_policy()); + value_type result = ir.first + (ir.second - ir.first) / 2; + if(max_iter >= policies::get_max_root_iterations<forwarding_policy>()) + { + policies::raise_evaluation_error<value_type>(function, "Unable to locate solution in a reasonable time:" + " either there is no answer to quantile" + " or the answer is infinite. Current best guess is %1%", result, forwarding_policy()); + } + return result; +} + +}}} // namespaces + +#endif // BOOST_MATH_DISTIBUTIONS_DETAIL_GENERIC_QUANTILE_HPP + diff --git a/Utilities/BGL/boost/math/distributions/detail/hypergeometric_cdf.hpp b/Utilities/BGL/boost/math/distributions/detail/hypergeometric_cdf.hpp new file mode 100644 index 0000000000000000000000000000000000000000..edf829ba7169b6f4fb4ccf267da3a61271017a9c --- /dev/null +++ b/Utilities/BGL/boost/math/distributions/detail/hypergeometric_cdf.hpp @@ -0,0 +1,100 @@ +// Copyright 2008 John Maddock +// +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_DISTRIBUTIONS_DETAIL_HG_CDF_HPP +#define BOOST_MATH_DISTRIBUTIONS_DETAIL_HG_CDF_HPP + +#include <boost/math/policies/error_handling.hpp> +#include <boost/math/distributions/detail/hypergeometric_pdf.hpp> + +namespace boost{ namespace math{ namespace detail{ + + template <class T, class Policy> + T hypergeometric_cdf_imp(unsigned x, unsigned r, unsigned n, unsigned N, bool invert, const Policy& pol) + { +#ifdef BOOST_MSVC +# pragma warning(push) +# pragma warning(disable:4267) +#endif + BOOST_MATH_STD_USING + T result = 0; + T mode = floor(T(r + 1) * T(n + 1) / (N + 2)); + if(x < mode) + { + result = hypergeometric_pdf<T>(x, r, n, N, pol); + T diff = result; + unsigned lower_limit = static_cast<unsigned>((std::max)(0, (int)(n + r) - (int)(N))); + while(diff > (invert ? T(1) : result) * tools::epsilon<T>()) + { + diff = T(x) * T((N + x) - n - r) * diff / (T(1 + n - x) * T(1 + r - x)); + result += diff; + BOOST_MATH_INSTRUMENT_VARIABLE(x); + BOOST_MATH_INSTRUMENT_VARIABLE(diff); + BOOST_MATH_INSTRUMENT_VARIABLE(result); + if(x == lower_limit) + break; + --x; + } + } + else + { + invert = !invert; + unsigned upper_limit = (std::min)(r, n); + if(x != upper_limit) + { + ++x; + result = hypergeometric_pdf<T>(x, r, n, N, pol); + T diff = result; + while((x <= upper_limit) && (diff > (invert ? T(1) : result) * tools::epsilon<T>())) + { + diff = T(n - x) * T(r - x) * diff / (T(x + 1) * T((N + x + 1) - n - r)); + result += diff; + ++x; + BOOST_MATH_INSTRUMENT_VARIABLE(x); + BOOST_MATH_INSTRUMENT_VARIABLE(diff); + BOOST_MATH_INSTRUMENT_VARIABLE(result); + } + } + } + if(invert) + result = 1 - result; + return result; +#ifdef BOOST_MSVC +# pragma warning(pop) +#endif + } + + template <class T, class Policy> + inline T hypergeometric_cdf(unsigned x, unsigned r, unsigned n, unsigned N, bool invert, const Policy&) + { + BOOST_FPU_EXCEPTION_GUARD + typedef typename tools::promote_args<T>::type result_type; + typedef typename policies::evaluation<result_type, Policy>::type value_type; + typedef typename policies::normalise< + Policy, + policies::promote_float<false>, + policies::promote_double<false>, + policies::discrete_quantile<>, + policies::assert_undefined<> >::type forwarding_policy; + + value_type result; + result = detail::hypergeometric_cdf_imp<value_type>(x, r, n, N, invert, forwarding_policy()); + if(result > 1) + { + result = 1; + } + if(result < 0) + { + result = 0; + } + return policies::checked_narrowing_cast<result_type, forwarding_policy>(result, "boost::math::hypergeometric_cdf<%1%>(%1%,%1%,%1%,%1%)"); + } + +}}} // namespaces + +#endif + diff --git a/Utilities/BGL/boost/math/distributions/detail/hypergeometric_pdf.hpp b/Utilities/BGL/boost/math/distributions/detail/hypergeometric_pdf.hpp new file mode 100644 index 0000000000000000000000000000000000000000..dea88053e35180d3193fcefad5af1aee3d0cc696 --- /dev/null +++ b/Utilities/BGL/boost/math/distributions/detail/hypergeometric_pdf.hpp @@ -0,0 +1,432 @@ +// Copyright 2008 Gautam Sewani +// Copyright 2008 John Maddock +// +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_DISTRIBUTIONS_DETAIL_HG_PDF_HPP +#define BOOST_MATH_DISTRIBUTIONS_DETAIL_HG_PDF_HPP + +#include <boost/math/constants/constants.hpp> +#include <boost/math/special_functions/lanczos.hpp> +#include <boost/math/special_functions/gamma.hpp> +#include <boost/math/special_functions/pow.hpp> +#include <boost/math/special_functions/prime.hpp> +#include <boost/math/policies/error_handling.hpp> + +namespace boost{ namespace math{ namespace detail{ + +template <class T, class Func> +void bubble_down_one(T* first, T* last, Func f) +{ + using std::swap; + T* next = first; + ++next; + while((next != last) && (!f(*first, *next))) + { + swap(*first, *next); + ++first; + ++next; + } +} + +template <class T> +struct sort_functor +{ + sort_functor(const T* exponents) : m_exponents(exponents){} + bool operator()(int i, int j) + { + return m_exponents[i] > m_exponents[j]; + } +private: + const T* m_exponents; +}; + +template <class T, class Lanczos, class Policy> +T hypergeometric_pdf_lanczos_imp(T /*dummy*/, unsigned x, unsigned r, unsigned n, unsigned N, const Lanczos&, const Policy&) +{ + BOOST_MATH_STD_USING + + T bases[9] = { + T(n) + Lanczos::g() + 0.5f, + T(r) + Lanczos::g() + 0.5f, + T(N - n) + Lanczos::g() + 0.5f, + T(N - r) + Lanczos::g() + 0.5f, + 1 / (T(N) + Lanczos::g() + 0.5f), + 1 / (T(x) + Lanczos::g() + 0.5f), + 1 / (T(n - x) + Lanczos::g() + 0.5f), + 1 / (T(r - x) + Lanczos::g() + 0.5f), + 1 / (T(N - n - r + x) + Lanczos::g() + 0.5f) + }; + T exponents[9] = { + n + 0.5f, + r + 0.5f, + N - n + 0.5f, + N - r + 0.5f, + N + 0.5f, + x + 0.5f, + n - x + 0.5f, + r - x + 0.5f, + N - n - r + x + 0.5f + }; + int base_e_factors[9] = { + -1, -1, -1, -1, 1, 1, 1, 1, 1 + }; + int sorted_indexes[9] = { + 0, 1, 2, 3, 4, 5, 6, 7, 8 + }; + std::sort(sorted_indexes, sorted_indexes + 9, sort_functor<T>(exponents)); + + do{ + exponents[sorted_indexes[0]] -= exponents[sorted_indexes[1]]; + bases[sorted_indexes[1]] *= bases[sorted_indexes[0]]; + if((bases[sorted_indexes[1]] < tools::min_value<T>()) && (exponents[sorted_indexes[1]] != 0)) + { + return 0; + } + base_e_factors[sorted_indexes[1]] += base_e_factors[sorted_indexes[0]]; + bubble_down_one(sorted_indexes, sorted_indexes + 9, sort_functor<T>(exponents)); + }while(exponents[sorted_indexes[1]] > 1); + + // + // Combine equal powers: + // + int j = 8; + while(exponents[sorted_indexes[j]] == 0) --j; + while(j) + { + while(j && (exponents[sorted_indexes[j-1]] == exponents[sorted_indexes[j]])) + { + bases[sorted_indexes[j-1]] *= bases[sorted_indexes[j]]; + exponents[sorted_indexes[j]] = 0; + base_e_factors[sorted_indexes[j-1]] += base_e_factors[sorted_indexes[j]]; + bubble_down_one(sorted_indexes + j, sorted_indexes + 9, sort_functor<T>(exponents)); + --j; + } + --j; + } + +#ifdef BOOST_MATH_INSTRUMENT + BOOST_MATH_INSTRUMENT_FPU + for(unsigned i = 0; i < 9; ++i) + { + BOOST_MATH_INSTRUMENT_VARIABLE(i); + BOOST_MATH_INSTRUMENT_VARIABLE(bases[i]); + BOOST_MATH_INSTRUMENT_VARIABLE(exponents[i]); + BOOST_MATH_INSTRUMENT_VARIABLE(base_e_factors[i]); + BOOST_MATH_INSTRUMENT_VARIABLE(sorted_indexes[i]); + } +#endif + + T result; + BOOST_MATH_INSTRUMENT_VARIABLE(bases[sorted_indexes[0]] * exp(static_cast<T>(base_e_factors[sorted_indexes[0]]))); + BOOST_MATH_INSTRUMENT_VARIABLE(exponents[sorted_indexes[0]]); + { + BOOST_FPU_EXCEPTION_GUARD + result = pow(bases[sorted_indexes[0]] * exp(static_cast<T>(base_e_factors[sorted_indexes[0]])), exponents[sorted_indexes[0]]); + } + BOOST_MATH_INSTRUMENT_VARIABLE(result); + for(unsigned i = 1; (i < 9) && (exponents[sorted_indexes[i]] > 0); ++i) + { + BOOST_FPU_EXCEPTION_GUARD + if(result < tools::min_value<T>()) + return 0; // short circuit further evaluation + if(exponents[sorted_indexes[i]] == 1) + result *= bases[sorted_indexes[i]] * exp(static_cast<T>(base_e_factors[sorted_indexes[i]])); + else if(exponents[sorted_indexes[i]] == 0.5f) + result *= sqrt(bases[sorted_indexes[i]] * exp(static_cast<T>(base_e_factors[sorted_indexes[i]]))); + else + result *= pow(bases[sorted_indexes[i]] * exp(static_cast<T>(base_e_factors[sorted_indexes[i]])), exponents[sorted_indexes[i]]); + + BOOST_MATH_INSTRUMENT_VARIABLE(result); + } + + result *= Lanczos::lanczos_sum_expG_scaled(static_cast<T>(n + 1)) + * Lanczos::lanczos_sum_expG_scaled(static_cast<T>(r + 1)) + * Lanczos::lanczos_sum_expG_scaled(static_cast<T>(N - n + 1)) + * Lanczos::lanczos_sum_expG_scaled(static_cast<T>(N - r + 1)) + / + ( Lanczos::lanczos_sum_expG_scaled(static_cast<T>(N + 1)) + * Lanczos::lanczos_sum_expG_scaled(static_cast<T>(x + 1)) + * Lanczos::lanczos_sum_expG_scaled(static_cast<T>(n - x + 1)) + * Lanczos::lanczos_sum_expG_scaled(static_cast<T>(r - x + 1)) + * Lanczos::lanczos_sum_expG_scaled(static_cast<T>(N - n - r + x + 1))); + + BOOST_MATH_INSTRUMENT_VARIABLE(result); + return result; +} + +template <class T, class Policy> +T hypergeometric_pdf_lanczos_imp(T /*dummy*/, unsigned x, unsigned r, unsigned n, unsigned N, const boost::math::lanczos::undefined_lanczos&, const Policy& pol) +{ + BOOST_MATH_STD_USING + return exp( + boost::math::lgamma(T(n + 1), pol) + + boost::math::lgamma(T(r + 1), pol) + + boost::math::lgamma(T(N - n + 1), pol) + + boost::math::lgamma(T(N - r + 1), pol) + - boost::math::lgamma(T(N + 1), pol) + - boost::math::lgamma(T(x + 1), pol) + - boost::math::lgamma(T(n - x + 1), pol) + - boost::math::lgamma(T(r - x + 1), pol) + - boost::math::lgamma(T(N - n - r + x + 1), pol)); +} + +template <class T> +inline T integer_power(const T& x, int ex) +{ + if(ex < 0) + return 1 / integer_power(x, -ex); + switch(ex) + { + case 0: + return 1; + case 1: + return x; + case 2: + return x * x; + case 3: + return x * x * x; + case 4: + return boost::math::pow<4>(x); + case 5: + return boost::math::pow<5>(x); + case 6: + return boost::math::pow<6>(x); + case 7: + return boost::math::pow<7>(x); + case 8: + return boost::math::pow<8>(x); + } + BOOST_MATH_STD_USING +#ifdef __SUNPRO_CC + return pow(x, T(ex)); +#else + return pow(x, ex); +#endif +} +template <class T> +struct hypergeometric_pdf_prime_loop_result_entry +{ + T value; + const hypergeometric_pdf_prime_loop_result_entry* next; +}; + +#ifdef BOOST_MSVC +#pragma warning(push) +#pragma warning(disable:4510 4512 4610) +#endif + +struct hypergeometric_pdf_prime_loop_data +{ + const unsigned x; + const unsigned r; + const unsigned n; + const unsigned N; + unsigned prime_index; + unsigned current_prime; +}; + +#ifdef BOOST_MSVC +#pragma warning(pop) +#endif + +template <class T> +T hypergeometric_pdf_prime_loop_imp(hypergeometric_pdf_prime_loop_data& data, hypergeometric_pdf_prime_loop_result_entry<T>& result) +{ + while(data.current_prime <= data.N) + { + unsigned base = data.current_prime; + int prime_powers = 0; + while(base <= data.N) + { + prime_powers += data.n / base; + prime_powers += data.r / base; + prime_powers += (data.N - data.n) / base; + prime_powers += (data.N - data.r) / base; + prime_powers -= data.N / base; + prime_powers -= data.x / base; + prime_powers -= (data.n - data.x) / base; + prime_powers -= (data.r - data.x) / base; + prime_powers -= (data.N - data.n - data.r + data.x) / base; + base *= data.current_prime; + } + if(prime_powers) + { + T p = integer_power<T>(data.current_prime, prime_powers); + if((p > 1) && (tools::max_value<T>() / p < result.value)) + { + // + // The next calculation would overflow, use recursion + // to sidestep the issue: + // + hypergeometric_pdf_prime_loop_result_entry<T> t = { p, &result }; + data.current_prime = prime(++data.prime_index); + return hypergeometric_pdf_prime_loop_imp<T>(data, t); + } + if((p < 1) && (tools::min_value<T>() / p > result.value)) + { + // + // The next calculation would underflow, use recursion + // to sidestep the issue: + // + hypergeometric_pdf_prime_loop_result_entry<T> t = { p, &result }; + data.current_prime = prime(++data.prime_index); + return hypergeometric_pdf_prime_loop_imp<T>(data, t); + } + result.value *= p; + } + data.current_prime = prime(++data.prime_index); + } + // + // When we get to here we have run out of prime factors, + // the overall result is the product of all the partial + // results we have accumulated on the stack so far, these + // are in a linked list starting with "data.head" and ending + // with "result". + // + // All that remains is to multiply them together, taking + // care not to overflow or underflow. + // + // Enumerate partial results >= 1 in variable i + // and partial results < 1 in variable j: + // + hypergeometric_pdf_prime_loop_result_entry<T> const *i, *j; + i = &result; + while(i && i->value < 1) + i = i->next; + j = &result; + while(j && j->value >= 1) + j = j->next; + + T prod = 1; + + while(i || j) + { + while(i && ((prod <= 1) || (j == 0))) + { + prod *= i->value; + i = i->next; + while(i && i->value < 1) + i = i->next; + } + while(j && ((prod >= 1) || (i == 0))) + { + prod *= j->value; + j = j->next; + while(j && j->value >= 1) + j = j->next; + } + } + + return prod; +} + +template <class T, class Policy> +inline T hypergeometric_pdf_prime_imp(unsigned x, unsigned r, unsigned n, unsigned N, const Policy&) +{ + hypergeometric_pdf_prime_loop_result_entry<T> result = { 1 }; + hypergeometric_pdf_prime_loop_data data = { x, r, n, N, 0, prime(0) }; + return hypergeometric_pdf_prime_loop_imp<T>(data, result); +} + +template <class T, class Policy> +T hypergeometric_pdf_factorial_imp(unsigned x, unsigned r, unsigned n, unsigned N, const Policy&) +{ + BOOST_MATH_STD_USING + BOOST_ASSERT(N < boost::math::max_factorial<T>::value); + T result = boost::math::unchecked_factorial<T>(n); + T num[3] = { + boost::math::unchecked_factorial<T>(r), + boost::math::unchecked_factorial<T>(N - n), + boost::math::unchecked_factorial<T>(N - r) + }; + T denom[5] = { + boost::math::unchecked_factorial<T>(N), + boost::math::unchecked_factorial<T>(x), + boost::math::unchecked_factorial<T>(n - x), + boost::math::unchecked_factorial<T>(r - x), + boost::math::unchecked_factorial<T>(N - n - r + x) + }; + int i = 0; + int j = 0; + while((i < 3) || (j < 5)) + { + while((j < 5) && ((result >= 1) || (i >= 3))) + { + result /= denom[j]; + ++j; + } + while((i < 3) && ((result <= 1) || (j >= 5))) + { + result *= num[i]; + ++i; + } + } + return result; +} + + +template <class T, class Policy> +inline typename tools::promote_args<T>::type + hypergeometric_pdf(unsigned x, unsigned r, unsigned n, unsigned N, const Policy&) +{ + BOOST_FPU_EXCEPTION_GUARD + typedef typename tools::promote_args<T>::type result_type; + typedef typename policies::evaluation<result_type, Policy>::type value_type; + typedef typename lanczos::lanczos<value_type, Policy>::type evaluation_type; + typedef typename policies::normalise< + Policy, + policies::promote_float<false>, + policies::promote_double<false>, + policies::discrete_quantile<>, + policies::assert_undefined<> >::type forwarding_policy; + + value_type result; + if(N <= boost::math::max_factorial<value_type>::value) + { + // + // If N is small enough then we can evaluate the PDF via the factorials + // directly: table lookup of the factorials gives the best performance + // of the methods available: + // + result = detail::hypergeometric_pdf_factorial_imp<value_type>(x, r, n, N, forwarding_policy()); + } + else if(N <= boost::math::prime(boost::math::max_prime - 1)) + { + // + // If N is no larger than the largest prime number in our lookup table + // (104729) then we can use prime factorisation to evaluate the PDF, + // this is slow but accurate: + // + result = detail::hypergeometric_pdf_prime_imp<value_type>(x, r, n, N, forwarding_policy()); + } + else + { + // + // Catch all case - use the lanczos approximation - where available - + // to evaluate the ratio of factorials. This is reasonably fast + // (almost as quick as using logarithmic evaluation in terms of lgamma) + // but only a few digits better in accuracy than using lgamma: + // + result = detail::hypergeometric_pdf_lanczos_imp(value_type(), x, r, n, N, evaluation_type(), forwarding_policy()); + } + + if(result > 1) + { + result = 1; + } + if(result < 0) + { + result = 0; + } + + return policies::checked_narrowing_cast<result_type, forwarding_policy>(result, "boost::math::hypergeometric_pdf<%1%>(%1%,%1%,%1%,%1%)"); +} + +}}} // namespaces + +#endif + diff --git a/Utilities/BGL/boost/math/distributions/detail/hypergeometric_quantile.hpp b/Utilities/BGL/boost/math/distributions/detail/hypergeometric_quantile.hpp new file mode 100644 index 0000000000000000000000000000000000000000..19c0d7a0273ed1b63b7a899b6865a294017ba325 --- /dev/null +++ b/Utilities/BGL/boost/math/distributions/detail/hypergeometric_quantile.hpp @@ -0,0 +1,199 @@ +// Copyright 2008 John Maddock +// +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_DISTRIBUTIONS_DETAIL_HG_QUANTILE_HPP +#define BOOST_MATH_DISTRIBUTIONS_DETAIL_HG_QUANTILE_HPP + +#include <boost/math/policies/error_handling.hpp> +#include <boost/math/distributions/detail/hypergeometric_pdf.hpp> + +namespace boost{ namespace math{ namespace detail{ + +template <class T> +inline unsigned round_x_from_p(unsigned x, T p, T cum, T fudge_factor, unsigned lbound, unsigned /*ubound*/, const policies::discrete_quantile<policies::integer_round_down>&) +{ + if((p < cum * fudge_factor) && (x != lbound)) + { + BOOST_MATH_INSTRUMENT_VARIABLE(x-1); + return --x; + } + return x; +} + +template <class T> +inline unsigned round_x_from_p(unsigned x, T p, T cum, T fudge_factor, unsigned /*lbound*/, unsigned ubound, const policies::discrete_quantile<policies::integer_round_up>&) +{ + if((cum < p * fudge_factor) && (x != ubound)) + { + BOOST_MATH_INSTRUMENT_VARIABLE(x+1); + return ++x; + } + return x; +} + +template <class T> +inline unsigned round_x_from_p(unsigned x, T p, T cum, T fudge_factor, unsigned lbound, unsigned ubound, const policies::discrete_quantile<policies::integer_round_inwards>&) +{ + if(p >= 0.5) + return round_x_from_p(x, p, cum, fudge_factor, lbound, ubound, policies::discrete_quantile<policies::integer_round_down>()); + return round_x_from_p(x, p, cum, fudge_factor, lbound, ubound, policies::discrete_quantile<policies::integer_round_up>()); +} + +template <class T> +inline unsigned round_x_from_p(unsigned x, T p, T cum, T fudge_factor, unsigned lbound, unsigned ubound, const policies::discrete_quantile<policies::integer_round_outwards>&) +{ + if(p >= 0.5) + return round_x_from_p(x, p, cum, fudge_factor, lbound, ubound, policies::discrete_quantile<policies::integer_round_up>()); + return round_x_from_p(x, p, cum, fudge_factor, lbound, ubound, policies::discrete_quantile<policies::integer_round_down>()); +} + +template <class T> +inline unsigned round_x_from_p(unsigned x, T /*p*/, T /*cum*/, T /*fudge_factor*/, unsigned /*lbound*/, unsigned /*ubound*/, const policies::discrete_quantile<policies::integer_round_nearest>&) +{ + return x; +} + +template <class T> +inline unsigned round_x_from_q(unsigned x, T q, T cum, T fudge_factor, unsigned lbound, unsigned /*ubound*/, const policies::discrete_quantile<policies::integer_round_down>&) +{ + if((q * fudge_factor > cum) && (x != lbound)) + { + BOOST_MATH_INSTRUMENT_VARIABLE(x-1); + return --x; + } + return x; +} + +template <class T> +inline unsigned round_x_from_q(unsigned x, T q, T cum, T fudge_factor, unsigned /*lbound*/, unsigned ubound, const policies::discrete_quantile<policies::integer_round_up>&) +{ + if((q < cum * fudge_factor) && (x != ubound)) + { + BOOST_MATH_INSTRUMENT_VARIABLE(x+1); + return ++x; + } + return x; +} + +template <class T> +inline unsigned round_x_from_q(unsigned x, T q, T cum, T fudge_factor, unsigned lbound, unsigned ubound, const policies::discrete_quantile<policies::integer_round_inwards>&) +{ + if(q < 0.5) + return round_x_from_q(x, q, cum, fudge_factor, lbound, ubound, policies::discrete_quantile<policies::integer_round_down>()); + return round_x_from_q(x, q, cum, fudge_factor, lbound, ubound, policies::discrete_quantile<policies::integer_round_up>()); +} + +template <class T> +inline unsigned round_x_from_q(unsigned x, T q, T cum, T fudge_factor, unsigned lbound, unsigned ubound, const policies::discrete_quantile<policies::integer_round_outwards>&) +{ + if(q >= 0.5) + return round_x_from_q(x, q, cum, fudge_factor, lbound, ubound, policies::discrete_quantile<policies::integer_round_down>()); + return round_x_from_q(x, q, cum, fudge_factor, lbound, ubound, policies::discrete_quantile<policies::integer_round_up>()); +} + +template <class T> +inline unsigned round_x_from_q(unsigned x, T /*q*/, T /*cum*/, T /*fudge_factor*/, unsigned /*lbound*/, unsigned /*ubound*/, const policies::discrete_quantile<policies::integer_round_nearest>&) +{ + return x; +} + +template <class T, class Policy> +unsigned hypergeometric_quantile_imp(T p, T q, unsigned r, unsigned n, unsigned N, const Policy& pol) +{ +#ifdef BOOST_MSVC +# pragma warning(push) +# pragma warning(disable:4267) +#endif + typedef typename Policy::discrete_quantile_type discrete_quantile_type; + BOOST_MATH_STD_USING + BOOST_FPU_EXCEPTION_GUARD + T result; + T fudge_factor = 1 + tools::epsilon<T>() * ((N <= boost::math::prime(boost::math::max_prime - 1)) ? 50 : 2 * N); + unsigned base = static_cast<unsigned>((std::max)(0, (int)(n + r) - (int)(N))); + unsigned lim = (std::min)(r, n); + + BOOST_MATH_INSTRUMENT_VARIABLE(p); + BOOST_MATH_INSTRUMENT_VARIABLE(q); + BOOST_MATH_INSTRUMENT_VARIABLE(r); + BOOST_MATH_INSTRUMENT_VARIABLE(n); + BOOST_MATH_INSTRUMENT_VARIABLE(N); + BOOST_MATH_INSTRUMENT_VARIABLE(fudge_factor); + BOOST_MATH_INSTRUMENT_VARIABLE(base); + BOOST_MATH_INSTRUMENT_VARIABLE(lim); + + if(p <= 0.5) + { + unsigned x = base; + result = hypergeometric_pdf<T>(x, r, n, N, pol); + T diff = result; + while(result < p) + { + diff = (diff > tools::min_value<T>() * 8) + ? T(n - x) * T(r - x) * diff / (T(x + 1) * T(N + x + 1 - n - r)) + : hypergeometric_pdf<T>(x + 1, r, n, N, pol); + if(result + diff / 2 > p) + break; + ++x; + result += diff; +#ifdef BOOST_MATH_INSTRUMENT + if(diff != 0) + { + BOOST_MATH_INSTRUMENT_VARIABLE(x); + BOOST_MATH_INSTRUMENT_VARIABLE(diff); + BOOST_MATH_INSTRUMENT_VARIABLE(result); + } +#endif + } + return round_x_from_p(x, p, result, fudge_factor, base, lim, discrete_quantile_type()); + } + else + { + unsigned x = lim; + result = 0; + T diff = hypergeometric_pdf<T>(x, r, n, N, pol); + while(result + diff / 2 < q) + { + result += diff; + diff = (diff > tools::min_value<T>() * 8) + ? x * T(N + x - n - r) * diff / (T(1 + n - x) * T(1 + r - x)) + : hypergeometric_pdf<T>(x - 1, r, n, N, pol); + --x; +#ifdef BOOST_MATH_INSTRUMENT + if(diff != 0) + { + BOOST_MATH_INSTRUMENT_VARIABLE(x); + BOOST_MATH_INSTRUMENT_VARIABLE(diff); + BOOST_MATH_INSTRUMENT_VARIABLE(result); + } +#endif + } + return round_x_from_q(x, q, result, fudge_factor, base, lim, discrete_quantile_type()); + } +#ifdef BOOST_MSVC +# pragma warning(pop) +#endif +} + +template <class T, class Policy> +inline unsigned hypergeometric_quantile(T p, T q, unsigned r, unsigned n, unsigned N, const Policy&) +{ + BOOST_FPU_EXCEPTION_GUARD + typedef typename tools::promote_args<T>::type result_type; + typedef typename policies::evaluation<result_type, Policy>::type value_type; + typedef typename policies::normalise< + Policy, + policies::promote_float<false>, + policies::promote_double<false>, + policies::assert_undefined<> >::type forwarding_policy; + + return detail::hypergeometric_quantile_imp<value_type>(p, q, r, n, N, forwarding_policy()); +} + +}}} // namespaces + +#endif + diff --git a/Utilities/BGL/boost/math/distributions/detail/inv_discrete_quantile.hpp b/Utilities/BGL/boost/math/distributions/detail/inv_discrete_quantile.hpp new file mode 100644 index 0000000000000000000000000000000000000000..1f2c9373f01d6ad99c23e05483cb3761e106b27f --- /dev/null +++ b/Utilities/BGL/boost/math/distributions/detail/inv_discrete_quantile.hpp @@ -0,0 +1,481 @@ +// Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_DISTRIBUTIONS_DETAIL_INV_DISCRETE_QUANTILE +#define BOOST_MATH_DISTRIBUTIONS_DETAIL_INV_DISCRETE_QUANTILE + +#include <algorithm> + +namespace boost{ namespace math{ namespace detail{ + +// +// Functor for root finding algorithm: +// +template <class Dist> +struct distribution_quantile_finder +{ + typedef typename Dist::value_type value_type; + typedef typename Dist::policy_type policy_type; + + distribution_quantile_finder(const Dist d, value_type p, value_type q) + : dist(d), target(p < q ? p : q), comp(p < q ? false : true) {} + + value_type operator()(value_type const& x) + { + return comp ? target - cdf(complement(dist, x)) : cdf(dist, x) - target; + } + +private: + Dist dist; + value_type target; + bool comp; +}; +// +// The purpose of adjust_bounds, is to toggle the last bit of the +// range so that both ends round to the same integer, if possible. +// If they do both round the same then we terminate the search +// for the root *very* quickly when finding an integer result. +// At the point that this function is called we know that "a" is +// below the root and "b" above it, so this change can not result +// in the root no longer being bracketed. +// +template <class Real, class Tol> +void adjust_bounds(Real& /* a */, Real& /* b */, Tol const& /* tol */){} + +template <class Real> +void adjust_bounds(Real& /* a */, Real& b, tools::equal_floor const& /* tol */) +{ + BOOST_MATH_STD_USING + b -= tools::epsilon<Real>() * b; +} + +template <class Real> +void adjust_bounds(Real& a, Real& /* b */, tools::equal_ceil const& /* tol */) +{ + BOOST_MATH_STD_USING + a += tools::epsilon<Real>() * a; +} + +template <class Real> +void adjust_bounds(Real& a, Real& b, tools::equal_nearest_integer const& /* tol */) +{ + BOOST_MATH_STD_USING + a += tools::epsilon<Real>() * a; + b -= tools::epsilon<Real>() * b; +} +// +// This is where all the work is done: +// +template <class Dist, class Tolerance> +typename Dist::value_type + do_inverse_discrete_quantile( + const Dist& dist, + const typename Dist::value_type& p, + const typename Dist::value_type& q, + typename Dist::value_type guess, + const typename Dist::value_type& multiplier, + typename Dist::value_type adder, + const Tolerance& tol, + boost::uintmax_t& max_iter) +{ + typedef typename Dist::value_type value_type; + typedef typename Dist::policy_type policy_type; + + static const char* function = "boost::math::do_inverse_discrete_quantile<%1%>"; + + BOOST_MATH_STD_USING + + distribution_quantile_finder<Dist> f(dist, p, q); + // + // Max bounds of the distribution: + // + value_type min_bound, max_bound; + std::tr1::tie(min_bound, max_bound) = support(dist); + + if(guess > max_bound) + guess = max_bound; + if(guess < min_bound) + guess = min_bound; + + value_type fa = f(guess); + boost::uintmax_t count = max_iter - 1; + value_type fb(fa), a(guess), b =0; // Compiler warning C4701: potentially uninitialized local variable 'b' used + + if(fa == 0) + return guess; + + // + // For small expected results, just use a linear search: + // + if(guess < 10) + { + b = a; + while((a < 10) && (fa * fb >= 0)) + { + if(fb <= 0) + { + a = b; + b = a + 1; + if(b > max_bound) + b = max_bound; + fb = f(b); + --count; + if(fb == 0) + return b; + } + else + { + b = a; + a = (std::max)(value_type(b - 1), value_type(0)); + if(a < min_bound) + a = min_bound; + fa = f(a); + --count; + if(fa == 0) + return a; + } + } + } + // + // Try and bracket using a couple of additions first, + // we're assuming that "guess" is likely to be accurate + // to the nearest int or so: + // + else if(adder != 0) + { + // + // If we're looking for a large result, then bump "adder" up + // by a bit to increase our chances of bracketing the root: + // + //adder = (std::max)(adder, 0.001f * guess); + if(fa < 0) + { + b = a + adder; + if(b > max_bound) + b = max_bound; + } + else + { + b = (std::max)(value_type(a - adder), value_type(0)); + if(b < min_bound) + b = min_bound; + } + fb = f(b); + --count; + if(fb == 0) + return b; + if(count && (fa * fb >= 0)) + { + // + // We didn't bracket the root, try + // once more: + // + a = b; + fa = fb; + if(fa < 0) + { + b = a + adder; + if(b > max_bound) + b = max_bound; + } + else + { + b = (std::max)(value_type(a - adder), value_type(0)); + if(b < min_bound) + b = min_bound; + } + fb = f(b); + --count; + } + if(a > b) + { + using std::swap; + swap(a, b); + swap(fa, fb); + } + } + // + // If the root hasn't been bracketed yet, try again + // using the multiplier this time: + // + if((boost::math::sign)(fb) == (boost::math::sign)(fa)) + { + if(fa < 0) + { + // + // Zero is to the right of x2, so walk upwards + // until we find it: + // + while((boost::math::sign)(fb) == (boost::math::sign)(fa)) + { + if(count == 0) + policies::raise_evaluation_error(function, "Unable to bracket root, last nearest value was %1%", b, policy_type()); + a = b; + fa = fb; + b *= multiplier; + if(b > max_bound) + b = max_bound; + fb = f(b); + --count; + BOOST_MATH_INSTRUMENT_CODE("a = " << a << " b = " << b << " fa = " << fa << " fb = " << fb << " count = " << count); + } + } + else + { + // + // Zero is to the left of a, so walk downwards + // until we find it: + // + while((boost::math::sign)(fb) == (boost::math::sign)(fa)) + { + if(fabs(a) < tools::min_value<value_type>()) + { + // Escape route just in case the answer is zero! + max_iter -= count; + max_iter += 1; + return 0; + } + if(count == 0) + policies::raise_evaluation_error(function, "Unable to bracket root, last nearest value was %1%", a, policy_type()); + b = a; + fb = fa; + a /= multiplier; + if(a < min_bound) + a = min_bound; + fa = f(a); + --count; + BOOST_MATH_INSTRUMENT_CODE("a = " << a << " b = " << b << " fa = " << fa << " fb = " << fb << " count = " << count); + } + } + } + max_iter -= count; + if(fa == 0) + return a; + if(fb == 0) + return b; + // + // Adjust bounds so that if we're looking for an integer + // result, then both ends round the same way: + // + adjust_bounds(a, b, tol); + // + // We don't want zero or denorm lower bounds: + // + if(a < tools::min_value<value_type>()) + a = tools::min_value<value_type>(); + // + // Go ahead and find the root: + // + std::pair<value_type, value_type> r = toms748_solve(f, a, b, fa, fb, tol, count, policy_type()); + max_iter += count; + BOOST_MATH_INSTRUMENT_CODE("max_iter = " << max_iter << " count = " << count); + return (r.first + r.second) / 2; +} +// +// Now finally are the public API functions. +// There is one overload for each policy, +// each one is responsible for selecting the correct +// termination condition, and rounding the result +// to an int where required. +// +template <class Dist> +inline typename Dist::value_type + inverse_discrete_quantile( + const Dist& dist, + const typename Dist::value_type& p, + const typename Dist::value_type& q, + const typename Dist::value_type& guess, + const typename Dist::value_type& multiplier, + const typename Dist::value_type& adder, + const policies::discrete_quantile<policies::real>&, + boost::uintmax_t& max_iter) +{ + if(p <= pdf(dist, 0)) + return 0; + return do_inverse_discrete_quantile( + dist, + p, + q, + guess, + multiplier, + adder, + tools::eps_tolerance<typename Dist::value_type>(policies::digits<typename Dist::value_type, typename Dist::policy_type>()), + max_iter); +} + +template <class Dist> +inline typename Dist::value_type + inverse_discrete_quantile( + const Dist& dist, + const typename Dist::value_type& p, + const typename Dist::value_type& q, + const typename Dist::value_type& guess, + const typename Dist::value_type& multiplier, + const typename Dist::value_type& adder, + const policies::discrete_quantile<policies::integer_round_outwards>&, + boost::uintmax_t& max_iter) +{ + typedef typename Dist::value_type value_type; + BOOST_MATH_STD_USING + if(p <= pdf(dist, 0)) + return 0; + // + // What happens next depends on whether we're looking for an + // upper or lower quantile: + // + if(p < 0.5f) + return floor(do_inverse_discrete_quantile( + dist, + p, + q, + (guess < 1 ? value_type(1) : (value_type)floor(guess)), + multiplier, + adder, + tools::equal_floor(), + max_iter)); + // else: + return ceil(do_inverse_discrete_quantile( + dist, + p, + q, + (value_type)ceil(guess), + multiplier, + adder, + tools::equal_ceil(), + max_iter)); +} + +template <class Dist> +inline typename Dist::value_type + inverse_discrete_quantile( + const Dist& dist, + const typename Dist::value_type& p, + const typename Dist::value_type& q, + const typename Dist::value_type& guess, + const typename Dist::value_type& multiplier, + const typename Dist::value_type& adder, + const policies::discrete_quantile<policies::integer_round_inwards>&, + boost::uintmax_t& max_iter) +{ + typedef typename Dist::value_type value_type; + BOOST_MATH_STD_USING + if(p <= pdf(dist, 0)) + return 0; + // + // What happens next depends on whether we're looking for an + // upper or lower quantile: + // + if(p < 0.5f) + return ceil(do_inverse_discrete_quantile( + dist, + p, + q, + ceil(guess), + multiplier, + adder, + tools::equal_ceil(), + max_iter)); + // else: + return floor(do_inverse_discrete_quantile( + dist, + p, + q, + (guess < 1 ? value_type(1) : floor(guess)), + multiplier, + adder, + tools::equal_floor(), + max_iter)); +} + +template <class Dist> +inline typename Dist::value_type + inverse_discrete_quantile( + const Dist& dist, + const typename Dist::value_type& p, + const typename Dist::value_type& q, + const typename Dist::value_type& guess, + const typename Dist::value_type& multiplier, + const typename Dist::value_type& adder, + const policies::discrete_quantile<policies::integer_round_down>&, + boost::uintmax_t& max_iter) +{ + typedef typename Dist::value_type value_type; + BOOST_MATH_STD_USING + if(p <= pdf(dist, 0)) + return 0; + return floor(do_inverse_discrete_quantile( + dist, + p, + q, + (guess < 1 ? value_type(1) : floor(guess)), + multiplier, + adder, + tools::equal_floor(), + max_iter)); +} + +template <class Dist> +inline typename Dist::value_type + inverse_discrete_quantile( + const Dist& dist, + const typename Dist::value_type& p, + const typename Dist::value_type& q, + const typename Dist::value_type& guess, + const typename Dist::value_type& multiplier, + const typename Dist::value_type& adder, + const policies::discrete_quantile<policies::integer_round_up>&, + boost::uintmax_t& max_iter) +{ + BOOST_MATH_STD_USING + if(p <= pdf(dist, 0)) + return 0; + return ceil(do_inverse_discrete_quantile( + dist, + p, + q, + ceil(guess), + multiplier, + adder, + tools::equal_ceil(), + max_iter)); +} + +template <class Dist> +inline typename Dist::value_type + inverse_discrete_quantile( + const Dist& dist, + const typename Dist::value_type& p, + const typename Dist::value_type& q, + const typename Dist::value_type& guess, + const typename Dist::value_type& multiplier, + const typename Dist::value_type& adder, + const policies::discrete_quantile<policies::integer_round_nearest>&, + boost::uintmax_t& max_iter) +{ + typedef typename Dist::value_type value_type; + BOOST_MATH_STD_USING + if(p <= pdf(dist, 0)) + return 0; + // + // Note that we adjust the guess to the nearest half-integer: + // this increase the chances that we will bracket the root + // with two results that both round to the same integer quickly. + // + return floor(do_inverse_discrete_quantile( + dist, + p, + q, + (guess < 0.5f ? value_type(1.5f) : floor(guess + 0.5f) + 0.5f), + multiplier, + adder, + tools::equal_nearest_integer(), + max_iter) + 0.5f); +} + +}}} // namespaces + +#endif // BOOST_MATH_DISTRIBUTIONS_DETAIL_INV_DISCRETE_QUANTILE + + diff --git a/Utilities/BGL/boost/math/distributions/exponential.hpp b/Utilities/BGL/boost/math/distributions/exponential.hpp new file mode 100644 index 0000000000000000000000000000000000000000..47e1c97fcb87cb892e4f9abbd83545e00f217801 --- /dev/null +++ b/Utilities/BGL/boost/math/distributions/exponential.hpp @@ -0,0 +1,261 @@ +// Copyright John Maddock 2006. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_STATS_EXPONENTIAL_HPP +#define BOOST_STATS_EXPONENTIAL_HPP + +#include <boost/math/distributions/fwd.hpp> +#include <boost/math/constants/constants.hpp> +#include <boost/math/special_functions/log1p.hpp> +#include <boost/math/special_functions/expm1.hpp> +#include <boost/math/distributions/complement.hpp> +#include <boost/math/distributions/detail/common_error_handling.hpp> +#include <boost/config/no_tr1/cmath.hpp> + +#ifdef BOOST_MSVC +# pragma warning(push) +# pragma warning(disable: 4702) // unreachable code (return after domain_error throw). +#endif + +#include <utility> + +namespace boost{ namespace math{ + +namespace detail{ +// +// Error check: +// +template <class RealType, class Policy> +inline bool verify_lambda(const char* function, RealType l, RealType* presult, const Policy& pol) +{ + if(l <= 0) + { + *presult = policies::raise_domain_error<RealType>( + function, + "The scale parameter \"lambda\" must be > 0, but was: %1%.", l, pol); + return false; + } + return true; +} + +template <class RealType, class Policy> +inline bool verify_exp_x(const char* function, RealType x, RealType* presult, const Policy& pol) +{ + if(x < 0) + { + *presult = policies::raise_domain_error<RealType>( + function, + "The random variable must be >= 0, but was: %1%.", x, pol); + return false; + } + return true; +} + +} // namespace detail + +template <class RealType = double, class Policy = policies::policy<> > +class exponential_distribution +{ +public: + typedef RealType value_type; + typedef Policy policy_type; + + exponential_distribution(RealType lambda = 1) + : m_lambda(lambda) + { + RealType err; + detail::verify_lambda("boost::math::exponential_distribution<%1%>::exponential_distribution", lambda, &err, Policy()); + } // exponential_distribution + + RealType lambda()const { return m_lambda; } + +private: + RealType m_lambda; +}; + +typedef exponential_distribution<double> exponential; + +template <class RealType, class Policy> +inline const std::pair<RealType, RealType> range(const exponential_distribution<RealType, Policy>& /*dist*/) +{ // Range of permissible values for random variable x. + using boost::math::tools::max_value; + return std::pair<RealType, RealType>(static_cast<RealType>(0), max_value<RealType>()); +} + +template <class RealType, class Policy> +inline const std::pair<RealType, RealType> support(const exponential_distribution<RealType, Policy>& /*dist*/) +{ // Range of supported values for random variable x. + // This is range where cdf rises from 0 to 1, and outside it, the pdf is zero. + using boost::math::tools::max_value; + using boost::math::tools::min_value; + return std::pair<RealType, RealType>(min_value<RealType>(), max_value<RealType>()); + // min_value<RealType>() to avoid a discontinuity at x = 0. +} + +template <class RealType, class Policy> +inline RealType pdf(const exponential_distribution<RealType, Policy>& dist, const RealType& x) +{ + BOOST_MATH_STD_USING // for ADL of std functions + + static const char* function = "boost::math::pdf(const exponential_distribution<%1%>&, %1%)"; + + RealType lambda = dist.lambda(); + RealType result; + if(0 == detail::verify_lambda(function, lambda, &result, Policy())) + return result; + if(0 == detail::verify_exp_x(function, x, &result, Policy())) + return result; + result = lambda * exp(-lambda * x); + return result; +} // pdf + +template <class RealType, class Policy> +inline RealType cdf(const exponential_distribution<RealType, Policy>& dist, const RealType& x) +{ + BOOST_MATH_STD_USING // for ADL of std functions + + static const char* function = "boost::math::cdf(const exponential_distribution<%1%>&, %1%)"; + + RealType result; + RealType lambda = dist.lambda(); + if(0 == detail::verify_lambda(function, lambda, &result, Policy())) + return result; + if(0 == detail::verify_exp_x(function, x, &result, Policy())) + return result; + result = -boost::math::expm1(-x * lambda, Policy()); + + return result; +} // cdf + +template <class RealType, class Policy> +inline RealType quantile(const exponential_distribution<RealType, Policy>& dist, const RealType& p) +{ + BOOST_MATH_STD_USING // for ADL of std functions + + static const char* function = "boost::math::quantile(const exponential_distribution<%1%>&, %1%)"; + + RealType result; + RealType lambda = dist.lambda(); + if(0 == detail::verify_lambda(function, lambda, &result, Policy())) + return result; + if(0 == detail::check_probability(function, p, &result, Policy())) + return result; + + if(p == 0) + return 0; + if(p == 1) + return policies::raise_overflow_error<RealType>(function, 0, Policy()); + + result = -boost::math::log1p(-p, Policy()) / lambda; + return result; +} // quantile + +template <class RealType, class Policy> +inline RealType cdf(const complemented2_type<exponential_distribution<RealType, Policy>, RealType>& c) +{ + BOOST_MATH_STD_USING // for ADL of std functions + + static const char* function = "boost::math::cdf(const exponential_distribution<%1%>&, %1%)"; + + RealType result; + RealType lambda = c.dist.lambda(); + if(0 == detail::verify_lambda(function, lambda, &result, Policy())) + return result; + if(0 == detail::verify_exp_x(function, c.param, &result, Policy())) + return result; + result = exp(-c.param * lambda); + + return result; +} + +template <class RealType, class Policy> +inline RealType quantile(const complemented2_type<exponential_distribution<RealType, Policy>, RealType>& c) +{ + BOOST_MATH_STD_USING // for ADL of std functions + + static const char* function = "boost::math::quantile(const exponential_distribution<%1%>&, %1%)"; + + RealType result; + RealType lambda = c.dist.lambda(); + if(0 == detail::verify_lambda(function, lambda, &result, Policy())) + return result; + + RealType q = c.param; + if(0 == detail::check_probability(function, q, &result, Policy())) + return result; + + if(q == 1) + return 0; + if(q == 0) + return policies::raise_overflow_error<RealType>(function, 0, Policy()); + + result = -log(q) / lambda; + return result; +} + +template <class RealType, class Policy> +inline RealType mean(const exponential_distribution<RealType, Policy>& dist) +{ + RealType result; + RealType lambda = dist.lambda(); + if(0 == detail::verify_lambda("boost::math::mean(const exponential_distribution<%1%>&)", lambda, &result, Policy())) + return result; + return 1 / lambda; +} + +template <class RealType, class Policy> +inline RealType standard_deviation(const exponential_distribution<RealType, Policy>& dist) +{ + RealType result; + RealType lambda = dist.lambda(); + if(0 == detail::verify_lambda("boost::math::standard_deviation(const exponential_distribution<%1%>&)", lambda, &result, Policy())) + return result; + return 1 / lambda; +} + +template <class RealType, class Policy> +inline RealType mode(const exponential_distribution<RealType, Policy>& /*dist*/) +{ + return 0; +} + +template <class RealType, class Policy> +inline RealType median(const exponential_distribution<RealType, Policy>& dist) +{ + using boost::math::constants::ln_two; + return ln_two<RealType>() / dist.lambda(); // ln(2) / lambda +} + +template <class RealType, class Policy> +inline RealType skewness(const exponential_distribution<RealType, Policy>& /*dist*/) +{ + return 2; +} + +template <class RealType, class Policy> +inline RealType kurtosis(const exponential_distribution<RealType, Policy>& /*dist*/) +{ + return 9; +} + +template <class RealType, class Policy> +inline RealType kurtosis_excess(const exponential_distribution<RealType, Policy>& /*dist*/) +{ + return 6; +} + +} // namespace math +} // namespace boost + +#ifdef BOOST_MSVC +# pragma warning(pop) +#endif + +// This include must be at the end, *after* the accessors +// for this distribution have been defined, in order to +// keep compilers that support two-phase lookup happy. +#include <boost/math/distributions/detail/derived_accessors.hpp> + +#endif // BOOST_STATS_EXPONENTIAL_HPP diff --git a/Utilities/BGL/boost/math/distributions/extreme_value.hpp b/Utilities/BGL/boost/math/distributions/extreme_value.hpp new file mode 100644 index 0000000000000000000000000000000000000000..e171ab210f5989a7d3a28f0e3b3e0704d7cba653 --- /dev/null +++ b/Utilities/BGL/boost/math/distributions/extreme_value.hpp @@ -0,0 +1,260 @@ +// Copyright John Maddock 2006. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_STATS_EXTREME_VALUE_HPP +#define BOOST_STATS_EXTREME_VALUE_HPP + +#include <boost/math/distributions/fwd.hpp> +#include <boost/math/constants/constants.hpp> +#include <boost/math/special_functions/log1p.hpp> +#include <boost/math/special_functions/expm1.hpp> +#include <boost/math/distributions/complement.hpp> +#include <boost/math/distributions/detail/common_error_handling.hpp> +#include <boost/config/no_tr1/cmath.hpp> + +// +// This is the maximum extreme value distribution, see +// http://www.itl.nist.gov/div898/handbook/eda/section3/eda366g.htm +// and http://mathworld.wolfram.com/ExtremeValueDistribution.html +// Also known as a Fisher-Tippett distribution, a log-Weibull +// distribution or a Gumbel distribution. + +#include <utility> + +#ifdef BOOST_MSVC +# pragma warning(push) +# pragma warning(disable: 4702) // unreachable code (return after domain_error throw). +#endif + +namespace boost{ namespace math{ + +namespace detail{ +// +// Error check: +// +template <class RealType, class Policy> +inline bool verify_scale_b(const char* function, RealType b, RealType* presult, const Policy& pol) +{ + if(b <= 0) + { + *presult = policies::raise_domain_error<RealType>( + function, + "The scale parameter \"b\" must be > 0, but was: %1%.", b, pol); + return false; + } + return true; +} + +} // namespace detail + +template <class RealType = double, class Policy = policies::policy<> > +class extreme_value_distribution +{ +public: + typedef RealType value_type; + typedef Policy policy_type; + + extreme_value_distribution(RealType a = 0, RealType b = 1) + : m_a(a), m_b(b) + { + RealType err; + detail::verify_scale_b("boost::math::extreme_value_distribution<%1%>::extreme_value_distribution", b, &err, Policy()); + } // extreme_value_distribution + + RealType location()const { return m_a; } + RealType scale()const { return m_b; } + +private: + RealType m_a, m_b; +}; + +typedef extreme_value_distribution<double> extreme_value; + +template <class RealType, class Policy> +inline const std::pair<RealType, RealType> range(const extreme_value_distribution<RealType, Policy>& /*dist*/) +{ // Range of permissible values for random variable x. + using boost::math::tools::max_value; + return std::pair<RealType, RealType>(-max_value<RealType>(), max_value<RealType>()); +} + +template <class RealType, class Policy> +inline const std::pair<RealType, RealType> support(const extreme_value_distribution<RealType, Policy>& /*dist*/) +{ // Range of supported values for random variable x. + // This is range where cdf rises from 0 to 1, and outside it, the pdf is zero. + using boost::math::tools::max_value; + return std::pair<RealType, RealType>(-max_value<RealType>(), max_value<RealType>()); +} + +template <class RealType, class Policy> +inline RealType pdf(const extreme_value_distribution<RealType, Policy>& dist, const RealType& x) +{ + BOOST_MATH_STD_USING // for ADL of std functions + + RealType a = dist.location(); + RealType b = dist.scale(); + RealType result; + if(0 == detail::verify_scale_b("boost::math::pdf(const extreme_value_distribution<%1%>&, %1%)", b, &result, Policy())) + return result; + result = exp((a-x)/b) * exp(-exp((a-x)/b)) / b; + return result; +} // pdf + +template <class RealType, class Policy> +inline RealType cdf(const extreme_value_distribution<RealType, Policy>& dist, const RealType& x) +{ + BOOST_MATH_STD_USING // for ADL of std functions + + RealType a = dist.location(); + RealType b = dist.scale(); + RealType result; + if(0 == detail::verify_scale_b("boost::math::cdf(const extreme_value_distribution<%1%>&, %1%)", b, &result, Policy())) + return result; + + result = exp(-exp((a-x)/b)); + + return result; +} // cdf + +template <class RealType, class Policy> +RealType quantile(const extreme_value_distribution<RealType, Policy>& dist, const RealType& p) +{ + BOOST_MATH_STD_USING // for ADL of std functions + + static const char* function = "boost::math::quantile(const extreme_value_distribution<%1%>&, %1%)"; + + RealType a = dist.location(); + RealType b = dist.scale(); + RealType result; + if(0 == detail::verify_scale_b(function, b, &result, Policy())) + return result; + if(0 == detail::check_probability(function, p, &result, Policy())) + return result; + + if(p == 0) + return -policies::raise_overflow_error<RealType>(function, 0, Policy()); + if(p == 1) + return policies::raise_overflow_error<RealType>(function, 0, Policy()); + + result = a - log(-log(p)) * b; + + return result; +} // quantile + +template <class RealType, class Policy> +inline RealType cdf(const complemented2_type<extreme_value_distribution<RealType, Policy>, RealType>& c) +{ + BOOST_MATH_STD_USING // for ADL of std functions + + RealType a = c.dist.location(); + RealType b = c.dist.scale(); + RealType result; + if(0 == detail::verify_scale_b("boost::math::cdf(const extreme_value_distribution<%1%>&, %1%)", b, &result, Policy())) + return result; + + result = -boost::math::expm1(-exp((a-c.param)/b), Policy()); + + return result; +} + +template <class RealType, class Policy> +RealType quantile(const complemented2_type<extreme_value_distribution<RealType, Policy>, RealType>& c) +{ + BOOST_MATH_STD_USING // for ADL of std functions + + static const char* function = "boost::math::quantile(const extreme_value_distribution<%1%>&, %1%)"; + + RealType a = c.dist.location(); + RealType b = c.dist.scale(); + RealType q = c.param; + RealType result; + if(0 == detail::verify_scale_b(function, b, &result, Policy())) + return result; + if(0 == detail::check_probability(function, q, &result, Policy())) + return result; + + if(q == 0) + return policies::raise_overflow_error<RealType>(function, 0, Policy()); + if(q == 1) + return -policies::raise_overflow_error<RealType>(function, 0, Policy()); + + result = a - log(-boost::math::log1p(-q, Policy())) * b; + + return result; +} + +template <class RealType, class Policy> +inline RealType mean(const extreme_value_distribution<RealType, Policy>& dist) +{ + RealType a = dist.location(); + RealType b = dist.scale(); + RealType result; + if(0 == detail::verify_scale_b("boost::math::mean(const extreme_value_distribution<%1%>&)", b, &result, Policy())) + return result; + return a + constants::euler<RealType>() * b; +} + +template <class RealType, class Policy> +inline RealType standard_deviation(const extreme_value_distribution<RealType, Policy>& dist) +{ + BOOST_MATH_STD_USING // for ADL of std functions. + + RealType b = dist.scale(); + RealType result; + if(0 == detail::verify_scale_b("boost::math::standard_deviation(const extreme_value_distribution<%1%>&)", b, &result, Policy())) + return result; + return constants::pi<RealType>() * b / sqrt(static_cast<RealType>(6)); +} + +template <class RealType, class Policy> +inline RealType mode(const extreme_value_distribution<RealType, Policy>& dist) +{ + return dist.location(); +} + +template <class RealType, class Policy> +inline RealType median(const extreme_value_distribution<RealType, Policy>& dist) +{ + using constants::ln_ln_two; + return dist.location() - dist.scale() * ln_ln_two<RealType>(); +} + +template <class RealType, class Policy> +inline RealType skewness(const extreme_value_distribution<RealType, Policy>& /*dist*/) +{ + // + // This is 12 * sqrt(6) * zeta(3) / pi^3: + // See http://mathworld.wolfram.com/ExtremeValueDistribution.html + // + return static_cast<RealType>(1.1395470994046486574927930193898461120875997958366L); +} + +template <class RealType, class Policy> +inline RealType kurtosis(const extreme_value_distribution<RealType, Policy>& /*dist*/) +{ + // See http://mathworld.wolfram.com/ExtremeValueDistribution.html + return RealType(27) / 5; +} + +template <class RealType, class Policy> +inline RealType kurtosis_excess(const extreme_value_distribution<RealType, Policy>& /*dist*/) +{ + // See http://mathworld.wolfram.com/ExtremeValueDistribution.html + return RealType(12) / 5; +} + + +} // namespace math +} // namespace boost + +#ifdef BOOST_MSVC +# pragma warning(pop) +#endif + +// This include must be at the end, *after* the accessors +// for this distribution have been defined, in order to +// keep compilers that support two-phase lookup happy. +#include <boost/math/distributions/detail/derived_accessors.hpp> + +#endif // BOOST_STATS_EXTREME_VALUE_HPP diff --git a/Utilities/BGL/boost/math/distributions/find_location.hpp b/Utilities/BGL/boost/math/distributions/find_location.hpp new file mode 100644 index 0000000000000000000000000000000000000000..42ec9866680e1584dd7d0d79cf180ce0c1aaabc1 --- /dev/null +++ b/Utilities/BGL/boost/math/distributions/find_location.hpp @@ -0,0 +1,146 @@ +// Copyright John Maddock 2007. +// Copyright Paul A. Bristow 2007. + +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_STATS_FIND_LOCATION_HPP +#define BOOST_STATS_FIND_LOCATION_HPP + +#include <boost/math/distributions/fwd.hpp> // for all distribution signatures. +#include <boost/math/distributions/complement.hpp> +#include <boost/math/policies/policy.hpp> +#include <boost/math/tools/traits.hpp> +#include <boost/static_assert.hpp> +#include <boost/math/special_functions/fpclassify.hpp> +#include <boost/math/policies/error_handling.hpp> +// using boost::math::policies::policy; +// using boost::math::complement; // will be needed by users who want complement, +// but NOT placed here to avoid putting it in global scope. + +namespace boost +{ + namespace math + { + // Function to find location of random variable z + // to give probability p (given scale) + // Applies to normal, lognormal, extreme value, Cauchy, (and symmetrical triangular), + // enforced by BOOST_STATIC_ASSERT below. + + template <class Dist, class Policy> + inline + typename Dist::value_type find_location( // For example, normal mean. + typename Dist::value_type z, // location of random variable z to give probability, P(X > z) == p. + // For example, a nominal minimum acceptable z, so that p * 100 % are > z + typename Dist::value_type p, // probability value desired at x, say 0.95 for 95% > z. + typename Dist::value_type scale, // scale parameter, for example, normal standard deviation. + const Policy& pol + ) + { +#if !defined(BOOST_NO_SFINAE) && !BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x590)) + // Will fail to compile here if try to use with a distribution without scale & location, + // for example pareto, and many others. These tests are disabled by the pp-logic + // above if the compiler doesn't support the SFINAE tricks used in the traits class. + BOOST_STATIC_ASSERT(::boost::math::tools::is_distribution<Dist>::value); + BOOST_STATIC_ASSERT(::boost::math::tools::is_scaled_distribution<Dist>::value); +#endif + static const char* function = "boost::math::find_location<Dist, Policy>&, %1%)"; + + if(!(boost::math::isfinite)(p) || (p < 0) || (p > 1)) + { + return policies::raise_domain_error<typename Dist::value_type>( + function, "Probability parameter was %1%, but must be >= 0 and <= 1!", p, pol); + } + if(!(boost::math::isfinite)(z)) + { + return policies::raise_domain_error<typename Dist::value_type>( + function, "z parameter was %1%, but must be finite!", z, pol); + } + if(!(boost::math::isfinite)(scale)) + { + return policies::raise_domain_error<typename Dist::value_type>( + function, "scale parameter was %1%, but must be finite!", scale, pol); + } + + //cout << "z " << z << ", p " << p << ", quantile(Dist(), p) " + // << quantile(Dist(), p) << ", quan * scale " << quantile(Dist(), p) * scale << endl; + return z - (quantile(Dist(), p) * scale); + } // find_location + + template <class Dist> + inline // with default policy. + typename Dist::value_type find_location( // For example, normal mean. + typename Dist::value_type z, // location of random variable z to give probability, P(X > z) == p. + // For example, a nominal minimum acceptable z, so that p * 100 % are > z + typename Dist::value_type p, // probability value desired at x, say 0.95 for 95% > z. + typename Dist::value_type scale) // scale parameter, for example, normal standard deviation. + { // Forward to find_location with default policy. + return (find_location<Dist>(z, p, scale, policies::policy<>())); + } // find_location + + // So the user can start from the complement q = (1 - p) of the probability p, + // for example, l = find_location<normal>(complement(z, q, sd)); + + template <class Dist, class Real1, class Real2, class Real3> + inline typename Dist::value_type find_location( // Default policy. + complemented3_type<Real1, Real2, Real3> const& c) + { + static const char* function = "boost::math::find_location<Dist, Policy>&, %1%)"; + + typename Dist::value_type p = c.param1; + if(!(boost::math::isfinite)(p) || (p < 0) || (p > 1)) + { + return policies::raise_domain_error<typename Dist::value_type>( + function, "Probability parameter was %1%, but must be >= 0 and <= 1!", p, policies::policy<>()); + } + typename Dist::value_type z = c.dist; + if(!(boost::math::isfinite)(z)) + { + return policies::raise_domain_error<typename Dist::value_type>( + function, "z parameter was %1%, but must be finite!", z, policies::policy<>()); + } + typename Dist::value_type scale = c.param2; + if(!(boost::math::isfinite)(scale)) + { + return policies::raise_domain_error<typename Dist::value_type>( + function, "scale parameter was %1%, but must be finite!", scale, policies::policy<>()); + } + // cout << "z " << c.dist << ", quantile (Dist(), " << c.param1 << ") * scale " << c.param2 << endl; + return z - quantile(Dist(), p) * scale; + } // find_location complement + + + template <class Dist, class Real1, class Real2, class Real3, class Real4> + inline typename Dist::value_type find_location( // Explicit policy. + complemented4_type<Real1, Real2, Real3, Real4> const& c) + { + static const char* function = "boost::math::find_location<Dist, Policy>&, %1%)"; + + typename Dist::value_type p = c.param1; + if(!(boost::math::isfinite)(p) || (p < 0) || (p > 1)) + { + return policies::raise_domain_error<typename Dist::value_type>( + function, "Probability parameter was %1%, but must be >= 0 and <= 1!", p, c.param3); + } + typename Dist::value_type z = c.dist; + if(!(boost::math::isfinite)(z)) + { + return policies::raise_domain_error<typename Dist::value_type>( + function, "z parameter was %1%, but must be finite!", z, c.param3); + } + typename Dist::value_type scale = c.param2; + if(!(boost::math::isfinite)(scale)) + { + return policies::raise_domain_error<typename Dist::value_type>( + function, "scale parameter was %1%, but must be finite!", scale, c.param3); + } + // cout << "z " << c.dist << ", quantile (Dist(), " << c.param1 << ") * scale " << c.param2 << endl; + return z - quantile(Dist(), p) * scale; + } // find_location complement + + } // namespace boost +} // namespace math + +#endif // BOOST_STATS_FIND_LOCATION_HPP + diff --git a/Utilities/BGL/boost/math/distributions/find_scale.hpp b/Utilities/BGL/boost/math/distributions/find_scale.hpp new file mode 100644 index 0000000000000000000000000000000000000000..53d1ac0f3a93e71aa33c70fface0e2029c4a1f12 --- /dev/null +++ b/Utilities/BGL/boost/math/distributions/find_scale.hpp @@ -0,0 +1,211 @@ +// Copyright John Maddock 2007. +// Copyright Paul A. Bristow 2007. + +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_STATS_FIND_SCALE_HPP +#define BOOST_STATS_FIND_SCALE_HPP + +#include <boost/math/distributions/fwd.hpp> // for all distribution signatures. +#include <boost/math/distributions/complement.hpp> +#include <boost/math/policies/policy.hpp> +// using boost::math::policies::policy; +#include <boost/math/tools/traits.hpp> +#include <boost/static_assert.hpp> +#include <boost/math/special_functions/fpclassify.hpp> +#include <boost/math/policies/error_handling.hpp> +// using boost::math::complement; // will be needed by users who want complement, +// but NOT placed here to avoid putting it in global scope. + +namespace boost +{ + namespace math + { + // Function to find location of random variable z + // to give probability p (given scale) + // Applies to normal, lognormal, extreme value, Cauchy, (and symmetrical triangular), + // distributions that have scale. + // BOOST_STATIC_ASSERTs, see below, are used to enforce this. + + template <class Dist, class Policy> + inline + typename Dist::value_type find_scale( // For example, normal mean. + typename Dist::value_type z, // location of random variable z to give probability, P(X > z) == p. + // For example, a nominal minimum acceptable weight z, so that p * 100 % are > z + typename Dist::value_type p, // probability value desired at x, say 0.95 for 95% > z. + typename Dist::value_type location, // location parameter, for example, normal distribution mean. + const Policy& pol + ) + { +#if !defined(BOOST_NO_SFINAE) && !BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x590)) + BOOST_STATIC_ASSERT(::boost::math::tools::is_distribution<Dist>::value); + BOOST_STATIC_ASSERT(::boost::math::tools::is_scaled_distribution<Dist>::value); +#endif + static const char* function = "boost::math::find_scale<Dist, Policy>(%1%, %1%, %1%, Policy)"; + + if(!(boost::math::isfinite)(p) || (p < 0) || (p > 1)) + { + return policies::raise_domain_error<typename Dist::value_type>( + function, "Probability parameter was %1%, but must be >= 0 and <= 1!", p, pol); + } + if(!(boost::math::isfinite)(z)) + { + return policies::raise_domain_error<typename Dist::value_type>( + function, "find_scale z parameter was %1%, but must be finite!", z, pol); + } + if(!(boost::math::isfinite)(location)) + { + return policies::raise_domain_error<typename Dist::value_type>( + function, "find_scale location parameter was %1%, but must be finite!", location, pol); + } + + //cout << "z " << z << ", p " << p << ", quantile(Dist(), p) " + //<< quantile(Dist(), p) << ", z - mean " << z - location + //<<", sd " << (z - location) / quantile(Dist(), p) << endl; + + //quantile(N01, 0.001) -3.09023 + //quantile(N01, 0.01) -2.32635 + //quantile(N01, 0.05) -1.64485 + //quantile(N01, 0.333333) -0.430728 + //quantile(N01, 0.5) 0 + //quantile(N01, 0.666667) 0.430728 + //quantile(N01, 0.9) 1.28155 + //quantile(N01, 0.95) 1.64485 + //quantile(N01, 0.99) 2.32635 + //quantile(N01, 0.999) 3.09023 + + typename Dist::value_type result = + (z - location) // difference between desired x and current location. + / quantile(Dist(), p); // standard distribution. + + if (result <= 0) + { // If policy isn't to throw, return the scale <= 0. + policies::raise_evaluation_error<typename Dist::value_type>(function, + "Computed scale (%1%) is <= 0!" " Was the complement intended?", + result, Policy()); + } + return result; + } // template <class Dist, class Policy> find_scale + + template <class Dist> + inline // with default policy. + typename Dist::value_type find_scale( // For example, normal mean. + typename Dist::value_type z, // location of random variable z to give probability, P(X > z) == p. + // For example, a nominal minimum acceptable z, so that p * 100 % are > z + typename Dist::value_type p, // probability value desired at x, say 0.95 for 95% > z. + typename Dist::value_type location) // location parameter, for example, mean. + { // Forward to find_scale using the default policy. + return (find_scale<Dist>(z, p, location, policies::policy<>())); + } // find_scale + + template <class Dist, class Real1, class Real2, class Real3, class Policy> + inline typename Dist::value_type find_scale( + complemented4_type<Real1, Real2, Real3, Policy> const& c) + { + //cout << "cparam1 q " << c.param1 // q + // << ", c.dist z " << c.dist // z + // << ", c.param2 l " << c.param2 // l + // << ", quantile (Dist(), c.param1 = q) " + // << quantile(Dist(), c.param1) //q + // << endl; + +#if !defined(BOOST_NO_SFINAE) && !BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x590)) + BOOST_STATIC_ASSERT(::boost::math::tools::is_distribution<Dist>::value); + BOOST_STATIC_ASSERT(::boost::math::tools::is_scaled_distribution<Dist>::value); +#endif + static const char* function = "boost::math::find_scale<Dist, Policy>(complement(%1%, %1%, %1%, Policy))"; + + // Checks on arguments, as not complemented version, + // Explicit policy. + typename Dist::value_type q = c.param1; + if(!(boost::math::isfinite)(q) || (q < 0) || (q > 1)) + { + return policies::raise_domain_error<typename Dist::value_type>( + function, "Probability parameter was %1%, but must be >= 0 and <= 1!", q, c.param3); + } + typename Dist::value_type z = c.dist; + if(!(boost::math::isfinite)(z)) + { + return policies::raise_domain_error<typename Dist::value_type>( + function, "find_scale z parameter was %1%, but must be finite!", z, c.param3); + } + typename Dist::value_type location = c.param2; + if(!(boost::math::isfinite)(location)) + { + return policies::raise_domain_error<typename Dist::value_type>( + function, "find_scale location parameter was %1%, but must be finite!", location, c.param3); + } + + typename Dist::value_type result = + (c.dist - c.param2) // difference between desired x and current location. + / quantile(complement(Dist(), c.param1)); + // ( z - location) / (quantile(complement(Dist(), q)) + if (result <= 0) + { // If policy isn't to throw, return the scale <= 0. + policies::raise_evaluation_error<typename Dist::value_type>(function, + "Computed scale (%1%) is <= 0!" " Was the complement intended?", + result, Policy()); + } + return result; + } // template <class Dist, class Policy, class Real1, class Real2, class Real3> typename Dist::value_type find_scale + + // So the user can start from the complement q = (1 - p) of the probability p, + // for example, s = find_scale<normal>(complement(z, q, l)); + + template <class Dist, class Real1, class Real2, class Real3> + inline typename Dist::value_type find_scale( + complemented3_type<Real1, Real2, Real3> const& c) + { + //cout << "cparam1 q " << c.param1 // q + // << ", c.dist z " << c.dist // z + // << ", c.param2 l " << c.param2 // l + // << ", quantile (Dist(), c.param1 = q) " + // << quantile(Dist(), c.param1) //q + // << endl; + +#if !defined(BOOST_NO_SFINAE) && !BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x590)) + BOOST_STATIC_ASSERT(::boost::math::tools::is_distribution<Dist>::value); + BOOST_STATIC_ASSERT(::boost::math::tools::is_scaled_distribution<Dist>::value); +#endif + static const char* function = "boost::math::find_scale<Dist, Policy>(complement(%1%, %1%, %1%, Policy))"; + + // Checks on arguments, as not complemented version, + // default policy policies::policy<>(). + typename Dist::value_type q = c.param1; + if(!(boost::math::isfinite)(q) || (q < 0) || (q > 1)) + { + return policies::raise_domain_error<typename Dist::value_type>( + function, "Probability parameter was %1%, but must be >= 0 and <= 1!", q, policies::policy<>()); + } + typename Dist::value_type z = c.dist; + if(!(boost::math::isfinite)(z)) + { + return policies::raise_domain_error<typename Dist::value_type>( + function, "find_scale z parameter was %1%, but must be finite!", z, policies::policy<>()); + } + typename Dist::value_type location = c.param2; + if(!(boost::math::isfinite)(location)) + { + return policies::raise_domain_error<typename Dist::value_type>( + function, "find_scale location parameter was %1%, but must be finite!", location, policies::policy<>()); + } + + typename Dist::value_type result = + (z - location) // difference between desired x and current location. + / quantile(complement(Dist(), q)); + // ( z - location) / (quantile(complement(Dist(), q)) + if (result <= 0) + { // If policy isn't to throw, return the scale <= 0. + policies::raise_evaluation_error<typename Dist::value_type>(function, + "Computed scale (%1%) is <= 0!" " Was the complement intended?", + result, policies::policy<>()); // This is only the default policy - also Want a version with Policy here. + } + return result; + } // template <class Dist, class Real1, class Real2, class Real3> typename Dist::value_type find_scale + + } // namespace boost +} // namespace math + +#endif // BOOST_STATS_FIND_SCALE_HPP diff --git a/Utilities/BGL/boost/math/distributions/fisher_f.hpp b/Utilities/BGL/boost/math/distributions/fisher_f.hpp new file mode 100644 index 0000000000000000000000000000000000000000..d7c06a15c7c807ae23318d98ea77f3e4f82d0ca5 --- /dev/null +++ b/Utilities/BGL/boost/math/distributions/fisher_f.hpp @@ -0,0 +1,385 @@ +// Copyright John Maddock 2006. + +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_DISTRIBUTIONS_FISHER_F_HPP +#define BOOST_MATH_DISTRIBUTIONS_FISHER_F_HPP + +#include <boost/math/distributions/fwd.hpp> +#include <boost/math/special_functions/beta.hpp> // for incomplete beta. +#include <boost/math/distributions/complement.hpp> // complements +#include <boost/math/distributions/detail/common_error_handling.hpp> // error checks +#include <boost/math/special_functions/fpclassify.hpp> + +#include <utility> + +namespace boost{ namespace math{ + +template <class RealType = double, class Policy = policies::policy<> > +class fisher_f_distribution +{ +public: + typedef RealType value_type; + typedef Policy policy_type; + + fisher_f_distribution(const RealType& i, const RealType& j) : m_df1(i), m_df2(j) + { + static const char* function = "fisher_f_distribution<%1%>::fisher_f_distribution"; + RealType result; + detail::check_df( + function, m_df1, &result, Policy()); + detail::check_df( + function, m_df2, &result, Policy()); + } // fisher_f_distribution + + RealType degrees_of_freedom1()const + { + return m_df1; + } + RealType degrees_of_freedom2()const + { + return m_df2; + } + +private: + // + // Data members: + // + RealType m_df1; // degrees of freedom are a real number. + RealType m_df2; // degrees of freedom are a real number. +}; + +typedef fisher_f_distribution<double> fisher_f; + +template <class RealType, class Policy> +inline const std::pair<RealType, RealType> range(const fisher_f_distribution<RealType, Policy>& /*dist*/) +{ // Range of permissible values for random variable x. + using boost::math::tools::max_value; + return std::pair<RealType, RealType>(0, max_value<RealType>()); +} + +template <class RealType, class Policy> +inline const std::pair<RealType, RealType> support(const fisher_f_distribution<RealType, Policy>& /*dist*/) +{ // Range of supported values for random variable x. + // This is range where cdf rises from 0 to 1, and outside it, the pdf is zero. + using boost::math::tools::max_value; + return std::pair<RealType, RealType>(0, max_value<RealType>()); +} + +template <class RealType, class Policy> +RealType pdf(const fisher_f_distribution<RealType, Policy>& dist, const RealType& x) +{ + BOOST_MATH_STD_USING // for ADL of std functions + RealType df1 = dist.degrees_of_freedom1(); + RealType df2 = dist.degrees_of_freedom2(); + // Error check: + RealType error_result; + static const char* function = "boost::math::pdf(fisher_f_distribution<%1%> const&, %1%)"; + if(false == detail::check_df( + function, df1, &error_result, Policy()) + && detail::check_df( + function, df2, &error_result, Policy())) + return error_result; + + if((x < 0) || !(boost::math::isfinite)(x)) + { + return policies::raise_domain_error<RealType>( + function, "Random variable parameter was %1%, but must be > 0 !", x, Policy()); + } + + if(x == 0) + { + // special cases: + if(df1 < 2) + return policies::raise_overflow_error<RealType>( + function, 0, Policy()); + else if(df1 == 2) + return 1; + else + return 0; + } + + // + // You reach this formula by direct differentiation of the + // cdf expressed in terms of the incomplete beta. + // + // There are two versions so we don't pass a value of z + // that is very close to 1 to ibeta_derivative: for some values + // of df1 and df2, all the change takes place in this area. + // + RealType v1x = df1 * x; + RealType result; + if(v1x > df2) + { + result = (df2 * df1) / ((df2 + v1x) * (df2 + v1x)); + result *= ibeta_derivative(df2 / 2, df1 / 2, df2 / (df2 + v1x), Policy()); + } + else + { + result = df2 + df1 * x; + result = (result * df1 - x * df1 * df1) / (result * result); + result *= ibeta_derivative(df1 / 2, df2 / 2, v1x / (df2 + v1x), Policy()); + } + return result; +} // pdf + +template <class RealType, class Policy> +inline RealType cdf(const fisher_f_distribution<RealType, Policy>& dist, const RealType& x) +{ + static const char* function = "boost::math::cdf(fisher_f_distribution<%1%> const&, %1%)"; + RealType df1 = dist.degrees_of_freedom1(); + RealType df2 = dist.degrees_of_freedom2(); + // Error check: + RealType error_result; + if(false == detail::check_df( + function, df1, &error_result, Policy()) + && detail::check_df( + function, df2, &error_result, Policy())) + return error_result; + + if((x < 0) || !(boost::math::isfinite)(x)) + { + return policies::raise_domain_error<RealType>( + function, "Random Variable parameter was %1%, but must be > 0 !", x, Policy()); + } + + RealType v1x = df1 * x; + // + // There are two equivalent formulas used here, the aim is + // to prevent the final argument to the incomplete beta + // from being too close to 1: for some values of df1 and df2 + // the rate of change can be arbitrarily large in this area, + // whilst the value we're passing will have lost information + // content as a result of being 0.999999something. Better + // to switch things around so we're passing 1-z instead. + // + return v1x > df2 + ? boost::math::ibetac(df2 / 2, df1 / 2, df2 / (df2 + v1x), Policy()) + : boost::math::ibeta(df1 / 2, df2 / 2, v1x / (df2 + v1x), Policy()); +} // cdf + +template <class RealType, class Policy> +inline RealType quantile(const fisher_f_distribution<RealType, Policy>& dist, const RealType& p) +{ + static const char* function = "boost::math::quantile(fisher_f_distribution<%1%> const&, %1%)"; + RealType df1 = dist.degrees_of_freedom1(); + RealType df2 = dist.degrees_of_freedom2(); + // Error check: + RealType error_result; + if(false == detail::check_df( + function, df1, &error_result, Policy()) + && detail::check_df( + function, df2, &error_result, Policy()) + && detail::check_probability( + function, p, &error_result, Policy())) + return error_result; + + RealType x, y; + + x = boost::math::ibeta_inv(df1 / 2, df2 / 2, p, &y, Policy()); + + return df2 * x / (df1 * y); +} // quantile + +template <class RealType, class Policy> +inline RealType cdf(const complemented2_type<fisher_f_distribution<RealType, Policy>, RealType>& c) +{ + static const char* function = "boost::math::cdf(fisher_f_distribution<%1%> const&, %1%)"; + RealType df1 = c.dist.degrees_of_freedom1(); + RealType df2 = c.dist.degrees_of_freedom2(); + RealType x = c.param; + // Error check: + RealType error_result; + if(false == detail::check_df( + function, df1, &error_result, Policy()) + && detail::check_df( + function, df2, &error_result, Policy())) + return error_result; + + if((x < 0) || !(boost::math::isfinite)(x)) + { + return policies::raise_domain_error<RealType>( + function, "Random Variable parameter was %1%, but must be > 0 !", x, Policy()); + } + + RealType v1x = df1 * x; + // + // There are two equivalent formulas used here, the aim is + // to prevent the final argument to the incomplete beta + // from being too close to 1: for some values of df1 and df2 + // the rate of change can be arbitrarily large in this area, + // whilst the value we're passing will have lost information + // content as a result of being 0.999999something. Better + // to switch things around so we're passing 1-z instead. + // + return v1x > df2 + ? boost::math::ibeta(df2 / 2, df1 / 2, df2 / (df2 + v1x), Policy()) + : boost::math::ibetac(df1 / 2, df2 / 2, v1x / (df2 + v1x), Policy()); +} + +template <class RealType, class Policy> +inline RealType quantile(const complemented2_type<fisher_f_distribution<RealType, Policy>, RealType>& c) +{ + static const char* function = "boost::math::quantile(fisher_f_distribution<%1%> const&, %1%)"; + RealType df1 = c.dist.degrees_of_freedom1(); + RealType df2 = c.dist.degrees_of_freedom2(); + RealType p = c.param; + // Error check: + RealType error_result; + if(false == detail::check_df( + function, df1, &error_result, Policy()) + && detail::check_df( + function, df2, &error_result, Policy()) + && detail::check_probability( + function, p, &error_result, Policy())) + return error_result; + + RealType x, y; + + x = boost::math::ibetac_inv(df1 / 2, df2 / 2, p, &y, Policy()); + + return df2 * x / (df1 * y); +} + +template <class RealType, class Policy> +inline RealType mean(const fisher_f_distribution<RealType, Policy>& dist) +{ // Mean of F distribution = v. + static const char* function = "boost::math::mean(fisher_f_distribution<%1%> const&)"; + RealType df1 = dist.degrees_of_freedom1(); + RealType df2 = dist.degrees_of_freedom2(); + // Error check: + RealType error_result; + if(false == detail::check_df( + function, df1, &error_result, Policy()) + && detail::check_df( + function, df2, &error_result, Policy())) + return error_result; + if(df2 <= 2) + { + return policies::raise_domain_error<RealType>( + function, "Second degree of freedom was %1% but must be > 2 in order for the distribution to have a mean.", df2, Policy()); + } + return df2 / (df2 - 2); +} // mean + +template <class RealType, class Policy> +inline RealType variance(const fisher_f_distribution<RealType, Policy>& dist) +{ // Variance of F distribution. + static const char* function = "boost::math::variance(fisher_f_distribution<%1%> const&)"; + RealType df1 = dist.degrees_of_freedom1(); + RealType df2 = dist.degrees_of_freedom2(); + // Error check: + RealType error_result; + if(false == detail::check_df( + function, df1, &error_result, Policy()) + && detail::check_df( + function, df2, &error_result, Policy())) + return error_result; + if(df2 <= 4) + { + return policies::raise_domain_error<RealType>( + function, "Second degree of freedom was %1% but must be > 4 in order for the distribution to have a valid variance.", df2, Policy()); + } + return 2 * df2 * df2 * (df1 + df2 - 2) / (df1 * (df2 - 2) * (df2 - 2) * (df2 - 4)); +} // variance + +template <class RealType, class Policy> +inline RealType mode(const fisher_f_distribution<RealType, Policy>& dist) +{ + static const char* function = "boost::math::mode(fisher_f_distribution<%1%> const&)"; + RealType df1 = dist.degrees_of_freedom1(); + RealType df2 = dist.degrees_of_freedom2(); + // Error check: + RealType error_result; + if(false == detail::check_df( + function, df1, &error_result, Policy()) + && detail::check_df( + function, df2, &error_result, Policy())) + return error_result; + if(df2 <= 2) + { + return policies::raise_domain_error<RealType>( + function, "Second degree of freedom was %1% but must be > 2 in order for the distribution to have a mode.", df2, Policy()); + } + return df2 * (df1 - 2) / (df1 * (df2 + 2)); +} + +//template <class RealType, class Policy> +//inline RealType median(const fisher_f_distribution<RealType, Policy>& dist) +//{ // Median of Fisher F distribution is not defined. +// return tools::domain_error<RealType>(BOOST_CURRENT_FUNCTION, "Median is not implemented, result is %1%!", std::numeric_limits<RealType>::quiet_NaN()); +// } // median + +// Now implemented via quantile(half) in derived accessors. + +template <class RealType, class Policy> +inline RealType skewness(const fisher_f_distribution<RealType, Policy>& dist) +{ + static const char* function = "boost::math::skewness(fisher_f_distribution<%1%> const&)"; + BOOST_MATH_STD_USING // ADL of std names + // See http://mathworld.wolfram.com/F-Distribution.html + RealType df1 = dist.degrees_of_freedom1(); + RealType df2 = dist.degrees_of_freedom2(); + // Error check: + RealType error_result; + if(false == detail::check_df( + function, df1, &error_result, Policy()) + && detail::check_df( + function, df2, &error_result, Policy())) + return error_result; + if(df2 <= 6) + { + return policies::raise_domain_error<RealType>( + function, "Second degree of freedom was %1% but must be > 6 in order for the distribution to have a skewness.", df2, Policy()); + } + return 2 * (df2 + 2 * df1 - 2) * sqrt((2 * df2 - 8) / (df1 * (df2 + df1 - 2))) / (df2 - 6); +} + +template <class RealType, class Policy> +RealType kurtosis_excess(const fisher_f_distribution<RealType, Policy>& dist); + +template <class RealType, class Policy> +inline RealType kurtosis(const fisher_f_distribution<RealType, Policy>& dist) +{ + return 3 + kurtosis_excess(dist); +} + +template <class RealType, class Policy> +inline RealType kurtosis_excess(const fisher_f_distribution<RealType, Policy>& dist) +{ + static const char* function = "boost::math::kurtosis_excess(fisher_f_distribution<%1%> const&)"; + // See http://mathworld.wolfram.com/F-Distribution.html + RealType df1 = dist.degrees_of_freedom1(); + RealType df2 = dist.degrees_of_freedom2(); + // Error check: + RealType error_result; + if(false == detail::check_df( + function, df1, &error_result, Policy()) + && detail::check_df( + function, df2, &error_result, Policy())) + return error_result; + if(df2 <= 8) + { + return policies::raise_domain_error<RealType>( + function, "Second degree of freedom was %1% but must be > 8 in order for the distribution to have a kutosis.", df2, Policy()); + } + RealType df2_2 = df2 * df2; + RealType df1_2 = df1 * df1; + RealType n = -16 + 20 * df2 - 8 * df2_2 + df2_2 * df2 + 44 * df1 - 32 * df2 * df1 + 5 * df2_2 * df1 - 22 * df1_2 + 5 * df2 * df1_2; + n *= 12; + RealType d = df1 * (df2 - 6) * (df2 - 8) * (df1 + df2 - 2); + return n / d; +} + +} // namespace math +} // namespace boost + +// This include must be at the end, *after* the accessors +// for this distribution have been defined, in order to +// keep compilers that support two-phase lookup happy. +#include <boost/math/distributions/detail/derived_accessors.hpp> + +#endif // BOOST_MATH_DISTRIBUTIONS_FISHER_F_HPP diff --git a/Utilities/BGL/boost/math/distributions/fwd.hpp b/Utilities/BGL/boost/math/distributions/fwd.hpp new file mode 100644 index 0000000000000000000000000000000000000000..4c896e473d1c67ec550c2ba922f38f4807f37f6c --- /dev/null +++ b/Utilities/BGL/boost/math/distributions/fwd.hpp @@ -0,0 +1,122 @@ +// Copyright Paul A. Bristow 2007. +// Copyright John Maddock 2007. + +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_DISTRIBUTIONS_FWD_HPP +#define BOOST_MATH_DISTRIBUTIONS_FWD_HPP + +namespace boost{ namespace math{ + +template <class RealType, class Policy> +class bernoulli_distribution; + +template <class RealType, class Policy> +class beta_distribution; + +template <class RealType, class Policy> +class binomial_distribution; + +template <class RealType, class Policy> +class cauchy_distribution; + +template <class RealType, class Policy> +class chi_squared_distribution; + +template <class RealType, class Policy> +class exponential_distribution; + +template <class RealType, class Policy> +class extreme_value_distribution; + +template <class RealType, class Policy> +class fisher_f_distribution; + +template <class RealType, class Policy> +class gamma_distribution; + +template <class RealType, class Policy> +class hypergeometric_distribution; + +template <class RealType, class Policy> +class laplace_distribution; + +template <class RealType, class Policy> +class logistic_distribution; + +template <class RealType, class Policy> +class lognormal_distribution; + +template <class RealType, class Policy> +class negative_binomial_distribution; + +template <class RealType, class Policy> +class non_central_chi_squared_distribution; + +template <class RealType, class Policy> +class non_central_beta_distribution; + +template <class RealType, class Policy> +class non_central_f_distribution; + +template <class RealType, class Policy> +class non_central_t_distribution; + +template <class RealType, class Policy> +class normal_distribution; + +template <class RealType, class Policy> +class pareto_distribution; + +template <class RealType, class Policy> +class poisson_distribution; + +template <class RealType, class Policy> +class rayleigh_distribution; + +template <class RealType, class Policy> +class students_t_distribution; + +template <class RealType, class Policy> +class triangular_distribution; + +template <class RealType, class Policy> +class uniform_distribution; + +template <class RealType, class Policy> +class weibull_distribution; + +}} // namespaces + +#define BOOST_MATH_DECLARE_DISTRIBUTIONS(Type, Policy)\ + typedef boost::math::bernoulli_distribution<Type, Policy> bernoulli;\ + typedef boost::math::beta_distribution<Type, Policy> beta;\ + typedef boost::math::binomial_distribution<Type, Policy> binomial;\ + typedef boost::math::cauchy_distribution<Type, Policy> cauchy;\ + typedef boost::math::chi_squared_distribution<Type, Policy> chi_squared;\ + typedef boost::math::exponential_distribution<Type, Policy> exponential;\ + typedef boost::math::extreme_value_distribution<Type, Policy> extreme_value;\ + typedef boost::math::fisher_f_distribution<Type, Policy> fisher_f;\ + typedef boost::math::gamma_distribution<Type, Policy> gamma;\ + typedef boost::math::laplace_distribution<Type, Policy> laplace;\ + typedef boost::math::logistic_distribution<Type, Policy> logistic;\ + typedef boost::math::lognormal_distribution<Type, Policy> lognormal;\ + typedef boost::math::negative_binomial_distribution<Type, Policy> negative_binomial;\ + typedef boost::math::normal_distribution<Type, Policy> normal;\ + typedef boost::math::pareto_distribution<Type, Policy> pareto;\ + typedef boost::math::poisson_distribution<Type, Policy> poisson;\ + typedef boost::math::rayleigh_distribution<Type, Policy> rayleigh;\ + typedef boost::math::students_t_distribution<Type, Policy> students_t;\ + typedef boost::math::triangular_distribution<Type, Policy> triangular;\ + typedef boost::math::uniform_distribution<Type, Policy> uniform;\ + typedef boost::math::weibull_distribution<Type, Policy> weibull;\ + typedef boost::math::non_central_chi_squared_distribution<Type, Policy> non_central_chi_squared;\ + typedef boost::math::non_central_beta_distribution<Type, Policy> non_central_beta;\ + typedef boost::math::non_central_f_distribution<Type, Policy> non_central_f;\ + typedef boost::math::non_central_t_distribution<Type, Policy> non_central_t;\ + typedef boost::math::hypergeometric_distribution<Type, Policy> hypergeometric;\ + +#endif // BOOST_MATH_DISTRIBUTIONS_FWD_HPP diff --git a/Utilities/BGL/boost/math/distributions/gamma.hpp b/Utilities/BGL/boost/math/distributions/gamma.hpp new file mode 100644 index 0000000000000000000000000000000000000000..a287e7cde2d70082230810c0ae850c243c40afe2 --- /dev/null +++ b/Utilities/BGL/boost/math/distributions/gamma.hpp @@ -0,0 +1,349 @@ +// Copyright John Maddock 2006. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_STATS_GAMMA_HPP +#define BOOST_STATS_GAMMA_HPP + +// http://www.itl.nist.gov/div898/handbook/eda/section3/eda366b.htm +// http://mathworld.wolfram.com/GammaDistribution.html +// http://en.wikipedia.org/wiki/Gamma_distribution + +#include <boost/math/distributions/fwd.hpp> +#include <boost/math/special_functions/gamma.hpp> +#include <boost/math/distributions/detail/common_error_handling.hpp> +#include <boost/math/distributions/complement.hpp> + +#include <utility> + +namespace boost{ namespace math +{ +namespace detail +{ + +template <class RealType, class Policy> +inline bool check_gamma_shape( + const char* function, + RealType shape, + RealType* result, const Policy& pol) +{ + if((shape <= 0) || !(boost::math::isfinite)(shape)) + { + *result = policies::raise_domain_error<RealType>( + function, + "Shape parameter is %1%, but must be > 0 !", shape, pol); + return false; + } + return true; +} + +template <class RealType, class Policy> +inline bool check_gamma_x( + const char* function, + RealType const& x, + RealType* result, const Policy& pol) +{ + if((x < 0) || !(boost::math::isfinite)(x)) + { + *result = policies::raise_domain_error<RealType>( + function, + "Random variate is %1% but must be >= 0 !", x, pol); + return false; + } + return true; +} + +template <class RealType, class Policy> +inline bool check_gamma( + const char* function, + RealType scale, + RealType shape, + RealType* result, const Policy& pol) +{ + return check_scale(function, scale, result, pol) && check_gamma_shape(function, shape, result, pol); +} + +} // namespace detail + +template <class RealType = double, class Policy = policies::policy<> > +class gamma_distribution +{ +public: + typedef RealType value_type; + typedef Policy policy_type; + + gamma_distribution(RealType shape, RealType scale = 1) + : m_shape(shape), m_scale(scale) + { + RealType result; + detail::check_gamma("boost::math::gamma_distribution<%1%>::gamma_distribution", scale, shape, &result, Policy()); + } + + RealType shape()const + { + return m_shape; + } + + RealType scale()const + { + return m_scale; + } +private: + // + // Data members: + // + RealType m_shape; // distribution shape + RealType m_scale; // distribution scale +}; + +// NO typedef because of clash with name of gamma function. + +template <class RealType, class Policy> +inline const std::pair<RealType, RealType> range(const gamma_distribution<RealType, Policy>& /* dist */) +{ // Range of permissible values for random variable x. + using boost::math::tools::max_value; + return std::pair<RealType, RealType>(0, max_value<RealType>()); +} + +template <class RealType, class Policy> +inline const std::pair<RealType, RealType> support(const gamma_distribution<RealType, Policy>& /* dist */) +{ // Range of supported values for random variable x. + // This is range where cdf rises from 0 to 1, and outside it, the pdf is zero. + using boost::math::tools::max_value; + using boost::math::tools::min_value; + return std::pair<RealType, RealType>(min_value<RealType>(), max_value<RealType>()); +} + +template <class RealType, class Policy> +inline RealType pdf(const gamma_distribution<RealType, Policy>& dist, const RealType& x) +{ + BOOST_MATH_STD_USING // for ADL of std functions + + static const char* function = "boost::math::pdf(const gamma_distribution<%1%>&, %1%)"; + + RealType shape = dist.shape(); + RealType scale = dist.scale(); + + RealType result; + if(false == detail::check_gamma(function, scale, shape, &result, Policy())) + return result; + if(false == detail::check_gamma_x(function, x, &result, Policy())) + return result; + + if(x == 0) + { + return 0; + } + result = gamma_p_derivative(shape, x / scale, Policy()) / scale; + return result; +} // pdf + +template <class RealType, class Policy> +inline RealType cdf(const gamma_distribution<RealType, Policy>& dist, const RealType& x) +{ + BOOST_MATH_STD_USING // for ADL of std functions + + static const char* function = "boost::math::cdf(const gamma_distribution<%1%>&, %1%)"; + + RealType shape = dist.shape(); + RealType scale = dist.scale(); + + RealType result; + if(false == detail::check_gamma(function, scale, shape, &result, Policy())) + return result; + if(false == detail::check_gamma_x(function, x, &result, Policy())) + return result; + + result = boost::math::gamma_p(shape, x / scale, Policy()); + return result; +} // cdf + +template <class RealType, class Policy> +inline RealType quantile(const gamma_distribution<RealType, Policy>& dist, const RealType& p) +{ + BOOST_MATH_STD_USING // for ADL of std functions + + static const char* function = "boost::math::quantile(const gamma_distribution<%1%>&, %1%)"; + + RealType shape = dist.shape(); + RealType scale = dist.scale(); + + RealType result; + if(false == detail::check_gamma(function, scale, shape, &result, Policy())) + return result; + if(false == detail::check_probability(function, p, &result, Policy())) + return result; + + if(p == 1) + return policies::raise_overflow_error<RealType>(function, 0, Policy()); + + result = gamma_p_inv(shape, p, Policy()) * scale; + + return result; +} + +template <class RealType, class Policy> +inline RealType cdf(const complemented2_type<gamma_distribution<RealType, Policy>, RealType>& c) +{ + BOOST_MATH_STD_USING // for ADL of std functions + + static const char* function = "boost::math::quantile(const gamma_distribution<%1%>&, %1%)"; + + RealType shape = c.dist.shape(); + RealType scale = c.dist.scale(); + + RealType result; + if(false == detail::check_gamma(function, scale, shape, &result, Policy())) + return result; + if(false == detail::check_gamma_x(function, c.param, &result, Policy())) + return result; + + result = gamma_q(shape, c.param / scale, Policy()); + + return result; +} + +template <class RealType, class Policy> +inline RealType quantile(const complemented2_type<gamma_distribution<RealType, Policy>, RealType>& c) +{ + BOOST_MATH_STD_USING // for ADL of std functions + + static const char* function = "boost::math::quantile(const gamma_distribution<%1%>&, %1%)"; + + RealType shape = c.dist.shape(); + RealType scale = c.dist.scale(); + RealType q = c.param; + + RealType result; + if(false == detail::check_gamma(function, scale, shape, &result, Policy())) + return result; + if(false == detail::check_probability(function, q, &result, Policy())) + return result; + + if(q == 0) + return policies::raise_overflow_error<RealType>(function, 0, Policy()); + + result = gamma_q_inv(shape, q, Policy()) * scale; + + return result; +} + +template <class RealType, class Policy> +inline RealType mean(const gamma_distribution<RealType, Policy>& dist) +{ + BOOST_MATH_STD_USING // for ADL of std functions + + static const char* function = "boost::math::mean(const gamma_distribution<%1%>&)"; + + RealType shape = dist.shape(); + RealType scale = dist.scale(); + + RealType result; + if(false == detail::check_gamma(function, scale, shape, &result, Policy())) + return result; + + result = shape * scale; + return result; +} + +template <class RealType, class Policy> +inline RealType variance(const gamma_distribution<RealType, Policy>& dist) +{ + BOOST_MATH_STD_USING // for ADL of std functions + + static const char* function = "boost::math::variance(const gamma_distribution<%1%>&)"; + + RealType shape = dist.shape(); + RealType scale = dist.scale(); + + RealType result; + if(false == detail::check_gamma(function, scale, shape, &result, Policy())) + return result; + + result = shape * scale * scale; + return result; +} + +template <class RealType, class Policy> +inline RealType mode(const gamma_distribution<RealType, Policy>& dist) +{ + BOOST_MATH_STD_USING // for ADL of std functions + + static const char* function = "boost::math::mode(const gamma_distribution<%1%>&)"; + + RealType shape = dist.shape(); + RealType scale = dist.scale(); + + RealType result; + if(false == detail::check_gamma(function, scale, shape, &result, Policy())) + return result; + + if(shape < 1) + return policies::raise_domain_error<RealType>( + function, + "The mode of the gamma distribution is only defined for values of the shape parameter >= 1, but got %1%.", + shape, Policy()); + + result = (shape - 1) * scale; + return result; +} + +//template <class RealType, class Policy> +//inline RealType median(const gamma_distribution<RealType, Policy>& dist) +//{ // Rely on default definition in derived accessors. +//} + +template <class RealType, class Policy> +inline RealType skewness(const gamma_distribution<RealType, Policy>& dist) +{ + BOOST_MATH_STD_USING // for ADL of std functions + + static const char* function = "boost::math::skewness(const gamma_distribution<%1%>&)"; + + RealType shape = dist.shape(); + RealType scale = dist.scale(); + + RealType result; + if(false == detail::check_gamma(function, scale, shape, &result, Policy())) + return result; + + result = 2 / sqrt(shape); + return result; +} + +template <class RealType, class Policy> +inline RealType kurtosis_excess(const gamma_distribution<RealType, Policy>& dist) +{ + BOOST_MATH_STD_USING // for ADL of std functions + + static const char* function = "boost::math::kurtosis_excess(const gamma_distribution<%1%>&)"; + + RealType shape = dist.shape(); + RealType scale = dist.scale(); + + RealType result; + if(false == detail::check_gamma(function, scale, shape, &result, Policy())) + return result; + + result = 6 / shape; + return result; +} + +template <class RealType, class Policy> +inline RealType kurtosis(const gamma_distribution<RealType, Policy>& dist) +{ + return kurtosis_excess(dist) + 3; +} + +} // namespace math +} // namespace boost + +// This include must be at the end, *after* the accessors +// for this distribution have been defined, in order to +// keep compilers that support two-phase lookup happy. +#include <boost/math/distributions/detail/derived_accessors.hpp> + +#endif // BOOST_STATS_GAMMA_HPP + + diff --git a/Utilities/BGL/boost/math/distributions/hypergeometric.hpp b/Utilities/BGL/boost/math/distributions/hypergeometric.hpp new file mode 100644 index 0000000000000000000000000000000000000000..2ba4f72ba065e5e729e1751a2b1ea65a5f2427a1 --- /dev/null +++ b/Utilities/BGL/boost/math/distributions/hypergeometric.hpp @@ -0,0 +1,290 @@ +// Copyright 2008 Gautam Sewani +// Copyright 2008 John Maddock +// +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_DISTRIBUTIONS_HYPERGEOMETRIC_HPP +#define BOOST_MATH_DISTRIBUTIONS_HYPERGEOMETRIC_HPP + +#include <boost/math/distributions/detail/common_error_handling.hpp> +#include <boost/math/distributions/complement.hpp> +#include <boost/math/distributions/detail/hypergeometric_pdf.hpp> +#include <boost/math/distributions/detail/hypergeometric_cdf.hpp> +#include <boost/math/distributions/detail/hypergeometric_quantile.hpp> +#include <boost/math/special_functions/fpclassify.hpp> + + +namespace boost { namespace math { + + template <class RealType = double, class Policy = policies::policy<> > + class hypergeometric_distribution + { + public: + typedef RealType value_type; + typedef Policy policy_type; + + hypergeometric_distribution(unsigned r, unsigned n, unsigned N) // Constructor. + : m_n(n), m_N(N), m_r(r) + { + static const char* function = "boost::math::hypergeometric_distribution<%1%>::hypergeometric_distribution"; + RealType ret; + check_params(function, &ret); + } + // Accessor functions. + unsigned total()const + { + return m_N; + } + + unsigned defective()const + { + return m_n; + } + + unsigned sample_count()const + { + return m_r; + } + + bool check_params(const char* function, RealType* result)const + { + if(m_r > m_N) + { + *result = boost::math::policies::raise_domain_error<RealType>( + function, "Parameter r out of range: must be <= N but got %1%", static_cast<RealType>(m_r), Policy()); + return false; + } + if(m_n > m_N) + { + *result = boost::math::policies::raise_domain_error<RealType>( + function, "Parameter n out of range: must be <= N but got %1%", static_cast<RealType>(m_n), Policy()); + return false; + } + return true; + } + bool check_x(unsigned x, const char* function, RealType* result)const + { + if(x < static_cast<unsigned>((std::max)(0, (int)(m_n + m_r) - (int)(m_N)))) + { + *result = boost::math::policies::raise_domain_error<RealType>( + function, "Random variable out of range: must be > 0 and > m + r - N but got %1%", static_cast<RealType>(x), Policy()); + return false; + } + if(x > (std::min)(m_r, m_n)) + { + *result = boost::math::policies::raise_domain_error<RealType>( + function, "Random variable out of range: must be less than both n and r but got %1%", static_cast<RealType>(x), Policy()); + return false; + } + return true; + } + + private: + // Data members: + unsigned m_n; // number of "defective" items + unsigned m_N; // number of "total" items + unsigned m_r; // number of items picked + + }; // class hypergeometric_distribution + + typedef hypergeometric_distribution<double> hypergeometric; + + template <class RealType, class Policy> + inline const std::pair<unsigned, unsigned> range(const hypergeometric_distribution<RealType, Policy>& dist) + { // Range of permissible values for random variable x. +#ifdef BOOST_MSVC +# pragma warning(push) +# pragma warning(disable:4267) +#endif + unsigned r = dist.sample_count(); + unsigned n = dist.defective(); + unsigned N = dist.total(); + unsigned l = static_cast<unsigned>((std::max)(0, (int)(n + r) - (int)(N))); + unsigned u = (std::min)(r, n); + return std::pair<unsigned, unsigned>(l, u); +#ifdef BOOST_MSVC +# pragma warning(pop) +#endif + } + + template <class RealType, class Policy> + inline const std::pair<unsigned, unsigned> support(const hypergeometric_distribution<RealType, Policy>& d) + { + return range(d); + } + + template <class RealType, class Policy> + inline RealType pdf(const hypergeometric_distribution<RealType, Policy>& dist, const unsigned& x) + { + static const char* function = "boost::math::pdf(const hypergeometric_distribution<%1%>&, const %1%&)"; + RealType result; + if(!dist.check_params(function, &result)) + return result; + if(!dist.check_x(x, function, &result)) + return result; + + return boost::math::detail::hypergeometric_pdf<RealType>( + x, dist.sample_count(), dist.defective(), dist.total(), Policy()); + } + + template <class RealType, class Policy, class U> + inline RealType pdf(const hypergeometric_distribution<RealType, Policy>& dist, const U& x) + { + static const char* function = "boost::math::pdf(const hypergeometric_distribution<%1%>&, const %1%&)"; + RealType r = static_cast<RealType>(x); + unsigned u = boost::math::itrunc(r); + if(u != r) + { + return boost::math::policies::raise_domain_error<RealType>( + function, "Random variable out of range: must be an integer but got %1%", r, Policy()); + } + return pdf(dist, u); + } + + template <class RealType, class Policy> + inline RealType cdf(const hypergeometric_distribution<RealType, Policy>& dist, const unsigned& x) + { + static const char* function = "boost::math::cdf(const hypergeometric_distribution<%1%>&, const %1%&)"; + RealType result; + if(!dist.check_params(function, &result)) + return result; + if(!dist.check_x(x, function, &result)) + return result; + + return boost::math::detail::hypergeometric_cdf<RealType>( + x, dist.sample_count(), dist.defective(), dist.total(), false, Policy()); + } + + template <class RealType, class Policy, class U> + inline RealType cdf(const hypergeometric_distribution<RealType, Policy>& dist, const U& x) + { + static const char* function = "boost::math::cdf(const hypergeometric_distribution<%1%>&, const %1%&)"; + RealType r = static_cast<RealType>(x); + unsigned u = boost::math::itrunc(r); + if(u != r) + { + return boost::math::policies::raise_domain_error<RealType>( + function, "Random variable out of range: must be an integer but got %1%", r, Policy()); + } + return cdf(dist, u); + } + + template <class RealType, class Policy> + inline RealType cdf(const complemented2_type<hypergeometric_distribution<RealType, Policy>, unsigned>& c) + { + static const char* function = "boost::math::cdf(const hypergeometric_distribution<%1%>&, const %1%&)"; + RealType result; + if(!c.dist.check_params(function, &result)) + return result; + if(!c.dist.check_x(c.param, function, &result)) + return result; + + return boost::math::detail::hypergeometric_cdf<RealType>( + c.param, c.dist.sample_count(), c.dist.defective(), c.dist.total(), true, Policy()); + } + + template <class RealType, class Policy, class U> + inline RealType cdf(const complemented2_type<hypergeometric_distribution<RealType, Policy>, U>& c) + { + static const char* function = "boost::math::cdf(const hypergeometric_distribution<%1%>&, const %1%&)"; + RealType r = static_cast<RealType>(c.param); + unsigned u = boost::math::itrunc(r); + if(u != r) + { + return boost::math::policies::raise_domain_error<RealType>( + function, "Random variable out of range: must be an integer but got %1%", r, Policy()); + } + return cdf(complement(c.dist, u)); + } + + template <class RealType, class Policy> + inline RealType quantile(const hypergeometric_distribution<RealType, Policy>& dist, const RealType& p) + { + BOOST_MATH_STD_USING // for ADL of std functions + + // Checking function argument + RealType result; + const char* function = "boost::math::quantile(const hypergeometric_distribution<%1%>&, %1%)"; + if (false == dist.check_params(function, &result)) return result; + if(false == detail::check_probability(function, p, &result, Policy())) return result; + + return static_cast<RealType>(detail::hypergeometric_quantile(p, RealType(1 - p), dist.sample_count(), dist.defective(), dist.total(), Policy())); + } // quantile + + template <class RealType, class Policy> + inline RealType quantile(const complemented2_type<hypergeometric_distribution<RealType, Policy>, RealType>& c) + { + BOOST_MATH_STD_USING // for ADL of std functions + + // Checking function argument + RealType result; + const char* function = "quantile(const complemented2_type<hypergeometric_distribution<%1%>, %1%>&)"; + if (false == c.dist.check_params(function, &result)) return result; + if(false == detail::check_probability(function, c.param, &result, Policy())) return result; + + return static_cast<RealType>(detail::hypergeometric_quantile(RealType(1 - c.param), c.param, c.dist.sample_count(), c.dist.defective(), c.dist.total(), Policy())); + } // quantile + + template <class RealType, class Policy> + inline RealType mean(const hypergeometric_distribution<RealType, Policy>& dist) + { + return static_cast<RealType>(dist.sample_count() * dist.defective()) / dist.total(); + } // RealType mean(const hypergeometric_distribution<RealType, Policy>& dist) + + template <class RealType, class Policy> + inline RealType variance(const hypergeometric_distribution<RealType, Policy>& dist) + { + RealType r = static_cast<RealType>(dist.sample_count()); + RealType n = static_cast<RealType>(dist.defective()); + RealType N = static_cast<RealType>(dist.total()); + return r * (n / N) * (1 - n / N) * (N - r) / (N - 1); + } // RealType variance(const hypergeometric_distribution<RealType, Policy>& dist) + + template <class RealType, class Policy> + inline RealType mode(const hypergeometric_distribution<RealType, Policy>& dist) + { + BOOST_MATH_STD_USING + RealType r = static_cast<RealType>(dist.sample_count()); + RealType n = static_cast<RealType>(dist.defective()); + RealType N = static_cast<RealType>(dist.total()); + return floor((r + 1) * (n + 1) / (N + 2)); + } + + template <class RealType, class Policy> + inline RealType skewness(const hypergeometric_distribution<RealType, Policy>& dist) + { + BOOST_MATH_STD_USING + RealType r = static_cast<RealType>(dist.sample_count()); + RealType n = static_cast<RealType>(dist.defective()); + RealType N = static_cast<RealType>(dist.total()); + return (N - 2 * n) * sqrt(N - 1) * (N - 2 * r) / (sqrt(n * r * (N - n) * (N - r)) * (N - 2)); + } // RealType skewness(const hypergeometric_distribution<RealType, Policy>& dist) + + template <class RealType, class Policy> + inline RealType kurtosis_excess(const hypergeometric_distribution<RealType, Policy>& dist) + { + RealType r = static_cast<RealType>(dist.sample_count()); + RealType n = static_cast<RealType>(dist.defective()); + RealType N = static_cast<RealType>(dist.total()); + RealType t1 = N * N * (N - 1) / (r * (N - 2) * (N - 3) * (N - r)); + RealType t2 = (N * (N + 1) - 6 * N * (N - r)) / (n * (N - n)) + + 3 * r * (N - r) * (N + 6) / (N * N) - 6; + return t1 * t2; + } // RealType kurtosis_excess(const hypergeometric_distribution<RealType, Policy>& dist) + + template <class RealType, class Policy> + inline RealType kurtosis(const hypergeometric_distribution<RealType, Policy>& dist) + { + return kurtosis_excess(dist) + 3; + } // RealType kurtosis_excess(const hypergeometric_distribution<RealType, Policy>& dist) +}} // namespaces + +// This include must be at the end, *after* the accessors +// for this distribution have been defined, in order to +// keep compilers that support two-phase lookup happy. +#include <boost/math/distributions/detail/derived_accessors.hpp> + +#endif // include guard diff --git a/Utilities/BGL/boost/math/distributions/laplace.hpp b/Utilities/BGL/boost/math/distributions/laplace.hpp new file mode 100644 index 0000000000000000000000000000000000000000..c8814d99e5195e28e687754eeef4ab5e72414341 --- /dev/null +++ b/Utilities/BGL/boost/math/distributions/laplace.hpp @@ -0,0 +1,302 @@ +// Copyright Thijs van den Berg, 2008. +// Copyright John Maddock 2008. +// Copyright Paul A. Bristow 2008. + +// Use, modification and distribution are subject to 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) + +// This module implements the Laplace distribution. +// Weisstein, Eric W. "Laplace Distribution." From MathWorld--A Wolfram Web Resource. +// http://mathworld.wolfram.com/LaplaceDistribution.html +// http://en.wikipedia.org/wiki/Laplace_distribution +// +// Abramowitz and Stegun 1972, p 930 +// http://www.math.sfu.ca/~cbm/aands/page_930.htm + +#ifndef BOOST_STATS_LAPLACE_HPP +#define BOOST_STATS_LAPLACE_HPP + +#include <boost/math/distributions/detail/common_error_handling.hpp> +#include <boost/math/distributions/complement.hpp> +#include <boost/math/constants/constants.hpp> +#include <limits> + +namespace boost{ namespace math{ + +template <class RealType = double, class Policy = policies::policy<> > +class laplace_distribution +{ +public: + // ---------------------------------- + // public Types + // ---------------------------------- + typedef RealType value_type; + typedef Policy policy_type; + + // ---------------------------------- + // Constructor(s) + // ---------------------------------- + laplace_distribution(RealType location = 0, RealType scale = 1) + : m_location(location), m_scale(scale) + { + RealType result; + check_parameters("boost::math::laplace_distribution<%1%>::laplace_distribution()", &result); + } + + + // ---------------------------------- + // Public functions + // ---------------------------------- + + RealType location() const + { + return m_location; + } + + RealType scale() const + { + return m_scale; + } + + bool check_parameters(const char* function, RealType* result) const + { + if(false == detail::check_scale(function, m_scale, result, Policy())) return false; + if(false == detail::check_location(function, m_location, result, Policy())) return false; + return true; + } + + +private: + RealType m_location; + RealType m_scale; + +}; // class laplace_distribution + + + +// +// Convenient type synonym +// +typedef laplace_distribution<double> laplace; + +// +// Non member functions +// +template <class RealType, class Policy> +inline const std::pair<RealType, RealType> range(const laplace_distribution<RealType, Policy>&) +{ + using boost::math::tools::max_value; + return std::pair<RealType, RealType>(-max_value<RealType>(), max_value<RealType>()); +} + +template <class RealType, class Policy> +inline const std::pair<RealType, RealType> support(const laplace_distribution<RealType, Policy>&) +{ + using boost::math::tools::max_value; + return std::pair<RealType, RealType>(-max_value<RealType>(), max_value<RealType>()); +} + +template <class RealType, class Policy> +inline RealType pdf(const laplace_distribution<RealType, Policy>& dist, const RealType& x) +{ + BOOST_MATH_STD_USING // for ADL of std functions + + // Checking function argument + RealType result; + const char* function = "boost::math::pdf(const laplace_distribution<%1%>&, %1%))"; + if (false == dist.check_parameters(function, &result)) return result; + if (false == detail::check_x(function, x, &result, Policy())) return result; + + // Special pdf values + if((boost::math::isinf)(x)) + return 0; // pdf + and - infinity is zero. + + // General case + RealType scale( dist.scale() ); + RealType location( dist.location() ); + + RealType exponent = x - location; + if (exponent>0) exponent = -exponent; + exponent /= scale; + + result = exp(exponent); + result /= 2 * scale; + + return result; +} // pdf + +template <class RealType, class Policy> +inline RealType cdf(const laplace_distribution<RealType, Policy>& dist, const RealType& x) +{ + BOOST_MATH_STD_USING // for ADL of std functions + + // Checking function argument + RealType result; + const char* function = "boost::math::cdf(const laplace_distribution<%1%>&, %1%)"; + if (false == dist.check_parameters(function, &result)) return result; + if (false == detail::check_x(function, x, &result, Policy())) return result; + + // Special cdf values + if((boost::math::isinf)(x)) + { + if(x < 0) return 0; // -infinity + return 1; // + infinity + } + + // General cdf values + RealType scale( dist.scale() ); + RealType location( dist.location() ); + + if (x < location) + result = exp( (x-location)/scale )/2; + else + result = 1 - exp( (location-x)/scale )/2; + + return result; +} // cdf + + +template <class RealType, class Policy> +inline RealType quantile(const laplace_distribution<RealType, Policy>& dist, const RealType& p) +{ + BOOST_MATH_STD_USING // for ADL of std functions + + // Checking function argument + RealType result; + const char* function = "boost::math::quantile(const laplace_distribution<%1%>&, %1%)"; + if (false == dist.check_parameters(function, &result)) return result; + if(false == detail::check_probability(function, p, &result, Policy())) return result; + + // extreme values + if(p == 0) return -std::numeric_limits<RealType>::infinity(); + if(p == 1) return std::numeric_limits<RealType>::infinity(); + + // Calculate Quantile + RealType scale( dist.scale() ); + RealType location( dist.location() ); + + if (p - 0.5 < 0.0) + result = location + scale*log( static_cast<RealType>(p*2) ); + else + result = location - scale*log( static_cast<RealType>(-p*2 + 2) ); + + return result; +} // quantile + + +template <class RealType, class Policy> +inline RealType cdf(const complemented2_type<laplace_distribution<RealType, Policy>, RealType>& c) +{ + BOOST_MATH_STD_USING // for ADL of std functions + + RealType scale = c.dist.scale(); + RealType location = c.dist.location(); + RealType x = c.param; + + // Checking function argument + RealType result; + const char* function = "boost::math::cdf(const complemented2_type<laplace_distribution<%1%>, %1%>&)"; + if(false == detail::check_x(function, x, &result, Policy()))return result; + + // Calculate cdf + + // Special cdf value + if((boost::math::isinf)(x)) + { + if(x < 0) return 1; // cdf complement -infinity is unity. + return 0; // cdf complement +infinity is zero + } + + // Cdf interval value + if (-x < location) + result = exp( (-x-location)/scale )/2; + else + result = 1 - exp( (location+x)/scale )/2; + + return result; +} // cdf complement + + +template <class RealType, class Policy> +inline RealType quantile(const complemented2_type<laplace_distribution<RealType, Policy>, RealType>& c) +{ + BOOST_MATH_STD_USING // for ADL of std functions + + // Calculate quantile + RealType scale = c.dist.scale(); + RealType location = c.dist.location(); + RealType q = c.param; + + // Checking function argument + RealType result; + const char* function = "quantile(const complemented2_type<laplace_distribution<%1%>, %1%>&)"; + if(false == detail::check_probability(function, q, &result, Policy())) return result; + + + // extreme values + if(q == 0) return std::numeric_limits<RealType>::infinity(); + if(q == 1) return -std::numeric_limits<RealType>::infinity(); + + if (0.5 - q < 0.0) + result = location + scale*log( static_cast<RealType>(-q*2 + 2) ); + else + result = location - scale*log( static_cast<RealType>(q*2) ); + + + return result; +} // quantile + +template <class RealType, class Policy> +inline RealType mean(const laplace_distribution<RealType, Policy>& dist) +{ + return dist.location(); +} + +template <class RealType, class Policy> +inline RealType standard_deviation(const laplace_distribution<RealType, Policy>& dist) +{ + return constants::root_two<RealType>() * dist.scale(); +} + +template <class RealType, class Policy> +inline RealType mode(const laplace_distribution<RealType, Policy>& dist) +{ + return dist.location(); +} + +template <class RealType, class Policy> +inline RealType median(const laplace_distribution<RealType, Policy>& dist) +{ + return dist.location(); +} + +template <class RealType, class Policy> +inline RealType skewness(const laplace_distribution<RealType, Policy>& /*dist*/) +{ + return 0; +} + +template <class RealType, class Policy> +inline RealType kurtosis(const laplace_distribution<RealType, Policy>& /*dist*/) +{ + return 6; +} + +template <class RealType, class Policy> +inline RealType kurtosis_excess(const laplace_distribution<RealType, Policy>& /*dist*/) +{ + return 3; +} + +} // namespace math +} // namespace boost + +// This include must be at the end, *after* the accessors +// for this distribution have been defined, in order to +// keep compilers that support two-phase lookup happy. +#include <boost/math/distributions/detail/derived_accessors.hpp> + +#endif // BOOST_STATS_LAPLACE_HPP + + diff --git a/Utilities/BGL/boost/math/distributions/logistic.hpp b/Utilities/BGL/boost/math/distributions/logistic.hpp new file mode 100644 index 0000000000000000000000000000000000000000..869dbbebb73e176c4d1ce58d6486fd851df44b06 --- /dev/null +++ b/Utilities/BGL/boost/math/distributions/logistic.hpp @@ -0,0 +1,287 @@ +// Copyright 2008 Gautam Sewani +// +// Use, modification and distribution are subject to 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) + +#include <boost/math/distributions/fwd.hpp> +#include <boost/math/distributions/detail/common_error_handling.hpp> +#include <boost/math/distributions/complement.hpp> +#include <boost/math/special_functions/log1p.hpp> +#include <boost/math/constants/constants.hpp> +#include <utility> + +namespace boost { namespace math { + + template <class RealType = double, class Policy = policies::policy<> > + class logistic_distribution + { + public: + typedef RealType value_type; + typedef Policy policy_type; + + logistic_distribution(RealType location=0, RealType scale=1) // Constructor. + : m_location(location), m_scale(scale) + { + static const char* function = "boost::math::logistic_distribution<%1%>::logistic_distribution"; + + RealType result; + detail::check_scale(function, scale, &result, Policy()); + detail::check_location(function, location, &result, Policy()); + } + // Accessor functions. + RealType scale()const + { + return m_scale; + } + + RealType location()const + { + return m_location; + } + private: + // Data members: + RealType m_location; // distribution location aka mu. + RealType m_scale; // distribution scale aka s. + }; // class logistic_distribution + + + typedef logistic_distribution<double> logistic; + + template <class RealType, class Policy> + inline const std::pair<RealType, RealType> range(const logistic_distribution<RealType, Policy>& /* dist */) + { // Range of permissible values for random variable x. + using boost::math::tools::max_value; + return std::pair<RealType, RealType>(-max_value<RealType>(), max_value<RealType>()); // - to + infinity + } + + template <class RealType, class Policy> + inline const std::pair<RealType, RealType> support(const logistic_distribution<RealType, Policy>& /* dist */) + { // Range of supported values for random variable x. + // This is range where cdf rises from 0 to 1, and outside it, the pdf is zero. + using boost::math::tools::max_value; + return std::pair<RealType, RealType>(-max_value<RealType>(), max_value<RealType>()); // - to + infinity + } + + + template <class RealType, class Policy> + inline RealType pdf(const logistic_distribution<RealType, Policy>& dist, const RealType& x) + { + RealType scale = dist.scale(); + RealType location = dist.location(); + + static const char* function = "boost::math::pdf(const logistic_distribution<%1%>&, %1%)"; + if((boost::math::isinf)(x)) + { + return 0; // pdf + and - infinity is zero. + } + + RealType result; + if(false == detail::check_scale(function, scale , &result, Policy())) + { + return result; + } + if(false == detail::check_location(function, location, &result, Policy())) + { + return result; + } + if(false == detail::check_x(function, x, &result, Policy())) + { + return result; + } + + BOOST_MATH_STD_USING + RealType exp_term = (location - x) / scale; + if(fabs(exp_term) > tools::log_max_value<RealType>()) + return 0; + exp_term = exp(exp_term); + if((exp_term * scale > 1) && (exp_term > tools::max_value<RealType>() / (scale * exp_term))) + return 1 / (scale * exp_term); + return (exp_term) / (scale * (1 + exp_term) * (1 + exp_term)); + } + + template <class RealType, class Policy> + inline RealType cdf(const logistic_distribution<RealType, Policy>& dist, const RealType& x) + { + RealType scale = dist.scale(); + RealType location = dist.location(); + RealType result; // of checks. + static const char* function = "boost::math::cdf(const logistic_distribution<%1%>&, %1%)"; + if(false == detail::check_scale(function, scale, &result, Policy())) + { + return result; + } + if(false == detail::check_location(function, location, &result, Policy())) + { + return result; + } + + if((boost::math::isinf)(x)) + { + if(x < 0) return 0; // -infinity + return 1; // + infinity + } + + if(false == detail::check_x(function, x, &result, Policy())) + { + return result; + } + BOOST_MATH_STD_USING + RealType power = (location - x) / scale; + if(power > tools::log_max_value<RealType>()) + return 0; + if(power < -tools::log_max_value<RealType>()) + return 1; + return 1 / (1 + exp(power)); + } + + template <class RealType, class Policy> + inline RealType quantile(const logistic_distribution<RealType, Policy>& dist, const RealType& p) + { + BOOST_MATH_STD_USING + RealType location = dist.location(); + RealType scale = dist.scale(); + + static const char* function = "boost::math::quantile(const logistic_distribution<%1%>&, %1%)"; + + RealType result; + if(false == detail::check_scale(function, scale, &result, Policy())) + return result; + if(false == detail::check_location(function, location, &result, Policy())) + return result; + if(false == detail::check_probability(function, p, &result, Policy())) + return result; + + if(p == 0) + { + return -policies::raise_overflow_error<RealType>(function,"probability argument is 0, must be >0 and <1",Policy()); + } + if(p == 1) + { + return policies::raise_overflow_error<RealType>(function,"probability argument is 1, must be >0 and <1",Policy()); + } + //Expressions to try + //return location+scale*log(p/(1-p)); + //return location+scale*log1p((2*p-1)/(1-p)); + + //return location - scale*log( (1-p)/p); + //return location - scale*log1p((1-2*p)/p); + + //return -scale*log(1/p-1) + location; + return location - scale * log((1 - p) / p); + } // RealType quantile(const logistic_distribution<RealType, Policy>& dist, const RealType& p) + + template <class RealType, class Policy> + inline RealType cdf(const complemented2_type<logistic_distribution<RealType, Policy>, RealType>& c) + { + BOOST_MATH_STD_USING + RealType location = c.dist.location(); + RealType scale = c.dist.scale(); + RealType x = c.param; + static const char* function = "boost::math::cdf(const complement(logistic_distribution<%1%>&), %1%)"; + + if((boost::math::isinf)(x)) + { + if(x < 0) return 1; // cdf complement -infinity is unity. + return 0; // cdf complement +infinity is zero + } + RealType result; + if(false == detail::check_scale(function, scale, &result, Policy())) + return result; + if(false == detail::check_location(function, location, &result, Policy())) + return result; + if(false == detail::check_x(function, x, &result, Policy())) + return result; + RealType power = (x - location) / scale; + if(power > tools::log_max_value<RealType>()) + return 0; + if(power < -tools::log_max_value<RealType>()) + return 1; + return 1 / (1 + exp(power)); + } + + template <class RealType, class Policy> + inline RealType quantile(const complemented2_type<logistic_distribution<RealType, Policy>, RealType>& c) + { + BOOST_MATH_STD_USING + RealType scale = c.dist.scale(); + RealType location = c.dist.location(); + static const char* function = "boost::math::quantile(const complement(logistic_distribution<%1%>&), %1%)"; + RealType result; + if(false == detail::check_scale(function, scale, &result, Policy())) + return result; + if(false == detail::check_location(function, location, &result, Policy())) + return result; + RealType q = c.param; + if(false == detail::check_probability(function, q, &result, Policy())) + return result; + using boost::math::tools::max_value; + + if(q == 1) + { + return -policies::raise_overflow_error<RealType>(function,"probability argument is 1, but must be >0 and <1",Policy()); + } + if(q == 0) + { + return policies::raise_overflow_error<RealType>(function,"probability argument is 0, but must be >0 and <1",Policy()); + } + //Expressions to try + //return location+scale*log((1-q)/q); + return location + scale * log((1 - q) / q); + + //return location-scale*log(q/(1-q)); + //return location-scale*log1p((2*q-1)/(1-q)); + + //return location+scale*log(1/q-1); + //return location+scale*log1p(1/q-2); + } + + template <class RealType, class Policy> + inline RealType mean(const logistic_distribution<RealType, Policy>& dist) + { + return dist.location(); + } // RealType mean(const logistic_distribution<RealType, Policy>& dist) + + template <class RealType, class Policy> + inline RealType variance(const logistic_distribution<RealType, Policy>& dist) + { + BOOST_MATH_STD_USING + RealType scale = dist.scale(); + return boost::math::constants::pi<RealType>()*boost::math::constants::pi<RealType>()*scale*scale/3; + } // RealType variance(const logistic_distribution<RealType, Policy>& dist) + + template <class RealType, class Policy> + inline RealType mode(const logistic_distribution<RealType, Policy>& dist) + { + return dist.location(); + } + + template <class RealType, class Policy> + inline RealType median(const logistic_distribution<RealType, Policy>& dist) + { + return dist.location(); + } + template <class RealType, class Policy> + inline RealType skewness(const logistic_distribution<RealType, Policy>& /*dist*/) + { + return 0; + } // RealType skewness(const logistic_distribution<RealType, Policy>& dist) + + template <class RealType, class Policy> + inline RealType kurtosis_excess(const logistic_distribution<RealType, Policy>& /*dist*/) + { + return static_cast<RealType>(6)/5; + } // RealType kurtosis_excess(const logistic_distribution<RealType, Policy>& dist) + + template <class RealType, class Policy> + inline RealType kurtosis(const logistic_distribution<RealType, Policy>& dist) + { + return kurtosis_excess(dist) + 3; + } // RealType kurtosis_excess(const logistic_distribution<RealType, Policy>& dist) + }} + + +// Must come at the end: +#include <boost/math/distributions/detail/derived_accessors.hpp> + diff --git a/Utilities/BGL/boost/math/distributions/lognormal.hpp b/Utilities/BGL/boost/math/distributions/lognormal.hpp new file mode 100644 index 0000000000000000000000000000000000000000..a29370244ea6797ecd371d6b3fb7e3b406edcb29 --- /dev/null +++ b/Utilities/BGL/boost/math/distributions/lognormal.hpp @@ -0,0 +1,310 @@ +// Copyright John Maddock 2006. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_STATS_LOGNORMAL_HPP +#define BOOST_STATS_LOGNORMAL_HPP + +// http://www.itl.nist.gov/div898/handbook/eda/section3/eda3669.htm +// http://mathworld.wolfram.com/LogNormalDistribution.html +// http://en.wikipedia.org/wiki/Lognormal_distribution + +#include <boost/math/distributions/fwd.hpp> +#include <boost/math/distributions/normal.hpp> +#include <boost/math/special_functions/expm1.hpp> +#include <boost/math/distributions/detail/common_error_handling.hpp> + +#include <utility> + +namespace boost{ namespace math +{ +namespace detail +{ + + template <class RealType, class Policy> + inline bool check_lognormal_x( + const char* function, + RealType const& x, + RealType* result, const Policy& pol) + { + if((x < 0) || !(boost::math::isfinite)(x)) + { + *result = policies::raise_domain_error<RealType>( + function, + "Random variate is %1% but must be >= 0 !", x, pol); + return false; + } + return true; + } + +} // namespace detail + + +template <class RealType = double, class Policy = policies::policy<> > +class lognormal_distribution +{ +public: + typedef RealType value_type; + typedef Policy policy_type; + + lognormal_distribution(RealType location = 0, RealType scale = 1) + : m_location(location), m_scale(scale) + { + RealType result; + detail::check_scale("boost::math::lognormal_distribution<%1%>::lognormal_distribution", scale, &result, Policy()); + } + + RealType location()const + { + return m_location; + } + + RealType scale()const + { + return m_scale; + } +private: + // + // Data members: + // + RealType m_location; // distribution location. + RealType m_scale; // distribution scale. +}; + +typedef lognormal_distribution<double> lognormal; + +template <class RealType, class Policy> +inline const std::pair<RealType, RealType> range(const lognormal_distribution<RealType, Policy>& /*dist*/) +{ // Range of permissible values for random variable x is >0 to +infinity. + using boost::math::tools::max_value; + return std::pair<RealType, RealType>(0, max_value<RealType>()); +} + +template <class RealType, class Policy> +inline const std::pair<RealType, RealType> support(const lognormal_distribution<RealType, Policy>& /*dist*/) +{ // Range of supported values for random variable x. + // This is range where cdf rises from 0 to 1, and outside it, the pdf is zero. + using boost::math::tools::max_value; + return std::pair<RealType, RealType>(0, max_value<RealType>()); +} + +template <class RealType, class Policy> +RealType pdf(const lognormal_distribution<RealType, Policy>& dist, const RealType& x) +{ + BOOST_MATH_STD_USING // for ADL of std functions + + RealType mu = dist.location(); + RealType sigma = dist.scale(); + + static const char* function = "boost::math::pdf(const lognormal_distribution<%1%>&, %1%)"; + + RealType result; + if(0 == detail::check_scale(function, sigma, &result, Policy())) + return result; + if(0 == detail::check_lognormal_x(function, x, &result, Policy())) + return result; + + if(x == 0) + return 0; + + RealType exponent = log(x) - mu; + exponent *= -exponent; + exponent /= 2 * sigma * sigma; + + result = exp(exponent); + result /= sigma * sqrt(2 * constants::pi<RealType>()) * x; + + return result; +} + +template <class RealType, class Policy> +inline RealType cdf(const lognormal_distribution<RealType, Policy>& dist, const RealType& x) +{ + BOOST_MATH_STD_USING // for ADL of std functions + + static const char* function = "boost::math::cdf(const lognormal_distribution<%1%>&, %1%)"; + + RealType result; + if(0 == detail::check_lognormal_x(function, x, &result, Policy())) + return result; + + if(x == 0) + return 0; + + normal_distribution<RealType, Policy> norm(dist.location(), dist.scale()); + return cdf(norm, log(x)); +} + +template <class RealType, class Policy> +inline RealType quantile(const lognormal_distribution<RealType, Policy>& dist, const RealType& p) +{ + BOOST_MATH_STD_USING // for ADL of std functions + + static const char* function = "boost::math::quantile(const lognormal_distribution<%1%>&, %1%)"; + + RealType result; + if(0 == detail::check_probability(function, p, &result, Policy())) + return result; + + if(p == 0) + return 0; + if(p == 1) + return policies::raise_overflow_error<RealType>(function, 0, Policy()); + + normal_distribution<RealType, Policy> norm(dist.location(), dist.scale()); + return exp(quantile(norm, p)); +} + +template <class RealType, class Policy> +inline RealType cdf(const complemented2_type<lognormal_distribution<RealType, Policy>, RealType>& c) +{ + BOOST_MATH_STD_USING // for ADL of std functions + + static const char* function = "boost::math::cdf(const lognormal_distribution<%1%>&, %1%)"; + + RealType result; + if(0 == detail::check_lognormal_x(function, c.param, &result, Policy())) + return result; + + if(c.param == 0) + return 1; + + normal_distribution<RealType, Policy> norm(c.dist.location(), c.dist.scale()); + return cdf(complement(norm, log(c.param))); +} + +template <class RealType, class Policy> +inline RealType quantile(const complemented2_type<lognormal_distribution<RealType, Policy>, RealType>& c) +{ + BOOST_MATH_STD_USING // for ADL of std functions + + static const char* function = "boost::math::quantile(const lognormal_distribution<%1%>&, %1%)"; + + RealType result; + if(0 == detail::check_probability(function, c.param, &result, Policy())) + return result; + + if(c.param == 1) + return 0; + if(c.param == 0) + return policies::raise_overflow_error<RealType>(function, 0, Policy()); + + normal_distribution<RealType, Policy> norm(c.dist.location(), c.dist.scale()); + return exp(quantile(complement(norm, c.param))); +} + +template <class RealType, class Policy> +inline RealType mean(const lognormal_distribution<RealType, Policy>& dist) +{ + BOOST_MATH_STD_USING // for ADL of std functions + + RealType mu = dist.location(); + RealType sigma = dist.scale(); + + RealType result; + if(0 == detail::check_scale("boost::math::mean(const lognormal_distribution<%1%>&)", sigma, &result, Policy())) + return result; + + return exp(mu + sigma * sigma / 2); +} + +template <class RealType, class Policy> +inline RealType variance(const lognormal_distribution<RealType, Policy>& dist) +{ + BOOST_MATH_STD_USING // for ADL of std functions + + RealType mu = dist.location(); + RealType sigma = dist.scale(); + + RealType result; + if(0 == detail::check_scale("boost::math::variance(const lognormal_distribution<%1%>&)", sigma, &result, Policy())) + return result; + + return boost::math::expm1(sigma * sigma, Policy()) * exp(2 * mu + sigma * sigma); +} + +template <class RealType, class Policy> +inline RealType mode(const lognormal_distribution<RealType, Policy>& dist) +{ + BOOST_MATH_STD_USING // for ADL of std functions + + RealType mu = dist.location(); + RealType sigma = dist.scale(); + + RealType result; + if(0 == detail::check_scale("boost::math::mode(const lognormal_distribution<%1%>&)", sigma, &result, Policy())) + return result; + + return exp(mu - sigma * sigma); +} + +template <class RealType, class Policy> +inline RealType median(const lognormal_distribution<RealType, Policy>& dist) +{ + BOOST_MATH_STD_USING // for ADL of std functions + RealType mu = dist.location(); + return exp(mu); // e^mu +} + +template <class RealType, class Policy> +inline RealType skewness(const lognormal_distribution<RealType, Policy>& dist) +{ + BOOST_MATH_STD_USING // for ADL of std functions + + //RealType mu = dist.location(); + RealType sigma = dist.scale(); + + RealType ss = sigma * sigma; + RealType ess = exp(ss); + + RealType result; + if(0 == detail::check_scale("boost::math::skewness(const lognormal_distribution<%1%>&)", sigma, &result, Policy())) + return result; + + return (ess + 2) * sqrt(boost::math::expm1(ss, Policy())); +} + +template <class RealType, class Policy> +inline RealType kurtosis(const lognormal_distribution<RealType, Policy>& dist) +{ + BOOST_MATH_STD_USING // for ADL of std functions + + //RealType mu = dist.location(); + RealType sigma = dist.scale(); + RealType ss = sigma * sigma; + + RealType result; + if(0 == detail::check_scale("boost::math::kurtosis(const lognormal_distribution<%1%>&)", sigma, &result, Policy())) + return result; + + return exp(4 * ss) + 2 * exp(3 * ss) + 3 * exp(2 * ss) - 3; +} + +template <class RealType, class Policy> +inline RealType kurtosis_excess(const lognormal_distribution<RealType, Policy>& dist) +{ + BOOST_MATH_STD_USING // for ADL of std functions + + // RealType mu = dist.location(); + RealType sigma = dist.scale(); + RealType ss = sigma * sigma; + + RealType result; + if(0 == detail::check_scale("boost::math::kurtosis_excess(const lognormal_distribution<%1%>&)", sigma, &result, Policy())) + return result; + + return exp(4 * ss) + 2 * exp(3 * ss) + 3 * exp(2 * ss) - 6; +} + +} // namespace math +} // namespace boost + +// This include must be at the end, *after* the accessors +// for this distribution have been defined, in order to +// keep compilers that support two-phase lookup happy. +#include <boost/math/distributions/detail/derived_accessors.hpp> + +#endif // BOOST_STATS_STUDENTS_T_HPP + + diff --git a/Utilities/BGL/boost/math/distributions/negative_binomial.hpp b/Utilities/BGL/boost/math/distributions/negative_binomial.hpp new file mode 100644 index 0000000000000000000000000000000000000000..13ab44305ec1b53d48c3c4daf00f699239f5ec20 --- /dev/null +++ b/Utilities/BGL/boost/math/distributions/negative_binomial.hpp @@ -0,0 +1,588 @@ +// boost\math\special_functions\negative_binomial.hpp + +// Copyright Paul A. Bristow 2007. +// Copyright John Maddock 2007. + +// Use, modification and distribution are subject to 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) + +// http://en.wikipedia.org/wiki/negative_binomial_distribution +// http://mathworld.wolfram.com/NegativeBinomialDistribution.html +// http://documents.wolfram.com/teachersedition/Teacher/Statistics/DiscreteDistributions.html + +// The negative binomial distribution NegativeBinomialDistribution[n, p] +// is the distribution of the number (k) of failures that occur in a sequence of trials before +// r successes have occurred, where the probability of success in each trial is p. + +// In a sequence of Bernoulli trials or events +// (independent, yes or no, succeed or fail) with success_fraction probability p, +// negative_binomial is the probability that k or fewer failures +// preceed the r th trial's success. +// random variable k is the number of failures (NOT the probability). + +// Negative_binomial distribution is a discrete probability distribution. +// But note that the negative binomial distribution +// (like others including the binomial, Poisson & Bernoulli) +// is strictly defined as a discrete function: only integral values of k are envisaged. +// However because of the method of calculation using a continuous gamma function, +// it is convenient to treat it as if a continous function, +// and permit non-integral values of k. + +// However, by default the policy is to use discrete_quantile_policy. + +// To enforce the strict mathematical model, users should use conversion +// on k outside this function to ensure that k is integral. + +// MATHCAD cumulative negative binomial pnbinom(k, n, p) + +// Implementation note: much greater speed, and perhaps greater accuracy, +// might be achieved for extreme values by using a normal approximation. +// This is NOT been tested or implemented. + +#ifndef BOOST_MATH_SPECIAL_NEGATIVE_BINOMIAL_HPP +#define BOOST_MATH_SPECIAL_NEGATIVE_BINOMIAL_HPP + +#include <boost/math/distributions/fwd.hpp> +#include <boost/math/special_functions/beta.hpp> // for ibeta(a, b, x) == Ix(a, b). +#include <boost/math/distributions/complement.hpp> // complement. +#include <boost/math/distributions/detail/common_error_handling.hpp> // error checks domain_error & logic_error. +#include <boost/math/special_functions/fpclassify.hpp> // isnan. +#include <boost/math/tools/roots.hpp> // for root finding. +#include <boost/math/distributions/detail/inv_discrete_quantile.hpp> + +#include <boost/type_traits/is_floating_point.hpp> +#include <boost/type_traits/is_integral.hpp> +#include <boost/type_traits/is_same.hpp> +#include <boost/mpl/if.hpp> + +#include <limits> // using std::numeric_limits; +#include <utility> + +#if defined (BOOST_MSVC) +# pragma warning(push) +// This believed not now necessary, so commented out. +//# pragma warning(disable: 4702) // unreachable code. +// in domain_error_imp in error_handling. +#endif + +namespace boost +{ + namespace math + { + namespace negative_binomial_detail + { + // Common error checking routines for negative binomial distribution functions: + template <class RealType, class Policy> + inline bool check_successes(const char* function, const RealType& r, RealType* result, const Policy& pol) + { + if( !(boost::math::isfinite)(r) || (r <= 0) ) + { + *result = policies::raise_domain_error<RealType>( + function, + "Number of successes argument is %1%, but must be > 0 !", r, pol); + return false; + } + return true; + } + template <class RealType, class Policy> + inline bool check_success_fraction(const char* function, const RealType& p, RealType* result, const Policy& pol) + { + if( !(boost::math::isfinite)(p) || (p < 0) || (p > 1) ) + { + *result = policies::raise_domain_error<RealType>( + function, + "Success fraction argument is %1%, but must be >= 0 and <= 1 !", p, pol); + return false; + } + return true; + } + template <class RealType, class Policy> + inline bool check_dist(const char* function, const RealType& r, const RealType& p, RealType* result, const Policy& pol) + { + return check_success_fraction(function, p, result, pol) + && check_successes(function, r, result, pol); + } + template <class RealType, class Policy> + inline bool check_dist_and_k(const char* function, const RealType& r, const RealType& p, RealType k, RealType* result, const Policy& pol) + { + if(check_dist(function, r, p, result, pol) == false) + { + return false; + } + if( !(boost::math::isfinite)(k) || (k < 0) ) + { // Check k failures. + *result = policies::raise_domain_error<RealType>( + function, + "Number of failures argument is %1%, but must be >= 0 !", k, pol); + return false; + } + return true; + } // Check_dist_and_k + + template <class RealType, class Policy> + inline bool check_dist_and_prob(const char* function, const RealType& r, RealType p, RealType prob, RealType* result, const Policy& pol) + { + if(check_dist(function, r, p, result, pol) && detail::check_probability(function, prob, result, pol) == false) + { + return false; + } + return true; + } // check_dist_and_prob + } // namespace negative_binomial_detail + + template <class RealType = double, class Policy = policies::policy<> > + class negative_binomial_distribution + { + public: + typedef RealType value_type; + typedef Policy policy_type; + + negative_binomial_distribution(RealType r, RealType p) : m_r(r), m_p(p) + { // Constructor. + RealType result; + negative_binomial_detail::check_dist( + "negative_binomial_distribution<%1%>::negative_binomial_distribution", + m_r, // Check successes r > 0. + m_p, // Check success_fraction 0 <= p <= 1. + &result, Policy()); + } // negative_binomial_distribution constructor. + + // Private data getter class member functions. + RealType success_fraction() const + { // Probability of success as fraction in range 0 to 1. + return m_p; + } + RealType successes() const + { // Total number of successes r. + return m_r; + } + + static RealType find_lower_bound_on_p( + RealType trials, + RealType successes, + RealType alpha) // alpha 0.05 equivalent to 95% for one-sided test. + { + static const char* function = "boost::math::negative_binomial<%1%>::find_lower_bound_on_p"; + RealType result; // of error checks. + RealType failures = trials - successes; + if(false == detail::check_probability(function, alpha, &result, Policy()) + && negative_binomial_detail::check_dist_and_k( + function, successes, RealType(0), failures, &result, Policy())) + { + return result; + } + // Use complement ibeta_inv function for lower bound. + // This is adapted from the corresponding binomial formula + // here: http://www.itl.nist.gov/div898/handbook/prc/section2/prc241.htm + // This is a Clopper-Pearson interval, and may be overly conservative, + // see also "A Simple Improved Inferential Method for Some + // Discrete Distributions" Yong CAI and K. KRISHNAMOORTHY + // http://www.ucs.louisiana.edu/~kxk4695/Discrete_new.pdf + // + return ibeta_inv(successes, failures + 1, alpha, static_cast<RealType*>(0), Policy()); + } // find_lower_bound_on_p + + static RealType find_upper_bound_on_p( + RealType trials, + RealType successes, + RealType alpha) // alpha 0.05 equivalent to 95% for one-sided test. + { + static const char* function = "boost::math::negative_binomial<%1%>::find_upper_bound_on_p"; + RealType result; // of error checks. + RealType failures = trials - successes; + if(false == negative_binomial_detail::check_dist_and_k( + function, successes, RealType(0), failures, &result, Policy()) + && detail::check_probability(function, alpha, &result, Policy())) + { + return result; + } + if(failures == 0) + return 1; + // Use complement ibetac_inv function for upper bound. + // Note adjusted failures value: *not* failures+1 as usual. + // This is adapted from the corresponding binomial formula + // here: http://www.itl.nist.gov/div898/handbook/prc/section2/prc241.htm + // This is a Clopper-Pearson interval, and may be overly conservative, + // see also "A Simple Improved Inferential Method for Some + // Discrete Distributions" Yong CAI and K. KRISHNAMOORTHY + // http://www.ucs.louisiana.edu/~kxk4695/Discrete_new.pdf + // + return ibetac_inv(successes, failures, alpha, static_cast<RealType*>(0), Policy()); + } // find_upper_bound_on_p + + // Estimate number of trials : + // "How many trials do I need to be P% sure of seeing k or fewer failures?" + + static RealType find_minimum_number_of_trials( + RealType k, // number of failures (k >= 0). + RealType p, // success fraction 0 <= p <= 1. + RealType alpha) // risk level threshold 0 <= alpha <= 1. + { + static const char* function = "boost::math::negative_binomial<%1%>::find_minimum_number_of_trials"; + // Error checks: + RealType result; + if(false == negative_binomial_detail::check_dist_and_k( + function, RealType(1), p, k, &result, Policy()) + && detail::check_probability(function, alpha, &result, Policy())) + { return result; } + + result = ibeta_inva(k + 1, p, alpha, Policy()); // returns n - k + return result + k; + } // RealType find_number_of_failures + + static RealType find_maximum_number_of_trials( + RealType k, // number of failures (k >= 0). + RealType p, // success fraction 0 <= p <= 1. + RealType alpha) // risk level threshold 0 <= alpha <= 1. + { + static const char* function = "boost::math::negative_binomial<%1%>::find_maximum_number_of_trials"; + // Error checks: + RealType result; + if(false == negative_binomial_detail::check_dist_and_k( + function, RealType(1), p, k, &result, Policy()) + && detail::check_probability(function, alpha, &result, Policy())) + { return result; } + + result = ibetac_inva(k + 1, p, alpha, Policy()); // returns n - k + return result + k; + } // RealType find_number_of_trials complemented + + private: + RealType m_r; // successes. + RealType m_p; // success_fraction + }; // template <class RealType, class Policy> class negative_binomial_distribution + + typedef negative_binomial_distribution<double> negative_binomial; // Reserved name of type double. + + template <class RealType, class Policy> + inline const std::pair<RealType, RealType> range(const negative_binomial_distribution<RealType, Policy>& /* dist */) + { // Range of permissible values for random variable k. + using boost::math::tools::max_value; + return std::pair<RealType, RealType>(0, max_value<RealType>()); // max_integer? + } + + template <class RealType, class Policy> + inline const std::pair<RealType, RealType> support(const negative_binomial_distribution<RealType, Policy>& /* dist */) + { // Range of supported values for random variable k. + // This is range where cdf rises from 0 to 1, and outside it, the pdf is zero. + using boost::math::tools::max_value; + return std::pair<RealType, RealType>(0, max_value<RealType>()); // max_integer? + } + + template <class RealType, class Policy> + inline RealType mean(const negative_binomial_distribution<RealType, Policy>& dist) + { // Mean of Negative Binomial distribution = r(1-p)/p. + return dist.successes() * (1 - dist.success_fraction() ) / dist.success_fraction(); + } // mean + + //template <class RealType, class Policy> + //inline RealType median(const negative_binomial_distribution<RealType, Policy>& dist) + //{ // Median of negative_binomial_distribution is not defined. + // return policies::raise_domain_error<RealType>(BOOST_CURRENT_FUNCTION, "Median is not implemented, result is %1%!", std::numeric_limits<RealType>::quiet_NaN()); + //} // median + // Now implemented via quantile(half) in derived accessors. + + template <class RealType, class Policy> + inline RealType mode(const negative_binomial_distribution<RealType, Policy>& dist) + { // Mode of Negative Binomial distribution = floor[(r-1) * (1 - p)/p] + BOOST_MATH_STD_USING // ADL of std functions. + return floor((dist.successes() -1) * (1 - dist.success_fraction()) / dist.success_fraction()); + } // mode + + template <class RealType, class Policy> + inline RealType skewness(const negative_binomial_distribution<RealType, Policy>& dist) + { // skewness of Negative Binomial distribution = 2-p / (sqrt(r(1-p)) + BOOST_MATH_STD_USING // ADL of std functions. + RealType p = dist.success_fraction(); + RealType r = dist.successes(); + + return (2 - p) / + sqrt(r * (1 - p)); + } // skewness + + template <class RealType, class Policy> + inline RealType kurtosis(const negative_binomial_distribution<RealType, Policy>& dist) + { // kurtosis of Negative Binomial distribution + // http://en.wikipedia.org/wiki/Negative_binomial is kurtosis_excess so add 3 + RealType p = dist.success_fraction(); + RealType r = dist.successes(); + return 3 + (6 / r) + ((p * p) / (r * (1 - p))); + } // kurtosis + + template <class RealType, class Policy> + inline RealType kurtosis_excess(const negative_binomial_distribution<RealType, Policy>& dist) + { // kurtosis excess of Negative Binomial distribution + // http://mathworld.wolfram.com/Kurtosis.html table of kurtosis_excess + RealType p = dist.success_fraction(); + RealType r = dist.successes(); + return (6 - p * (6-p)) / (r * (1-p)); + } // kurtosis_excess + + template <class RealType, class Policy> + inline RealType variance(const negative_binomial_distribution<RealType, Policy>& dist) + { // Variance of Binomial distribution = r (1-p) / p^2. + return dist.successes() * (1 - dist.success_fraction()) + / (dist.success_fraction() * dist.success_fraction()); + } // variance + + // RealType standard_deviation(const negative_binomial_distribution<RealType, Policy>& dist) + // standard_deviation provided by derived accessors. + // RealType hazard(const negative_binomial_distribution<RealType, Policy>& dist) + // hazard of Negative Binomial distribution provided by derived accessors. + // RealType chf(const negative_binomial_distribution<RealType, Policy>& dist) + // chf of Negative Binomial distribution provided by derived accessors. + + template <class RealType, class Policy> + inline RealType pdf(const negative_binomial_distribution<RealType, Policy>& dist, const RealType& k) + { // Probability Density/Mass Function. + BOOST_FPU_EXCEPTION_GUARD + + static const char* function = "boost::math::pdf(const negative_binomial_distribution<%1%>&, %1%)"; + + RealType r = dist.successes(); + RealType p = dist.success_fraction(); + RealType result; + if(false == negative_binomial_detail::check_dist_and_k( + function, + r, + dist.success_fraction(), + k, + &result, Policy())) + { + return result; + } + + result = (p/(r + k)) * ibeta_derivative(r, static_cast<RealType>(k+1), p, Policy()); + // Equivalent to: + // return exp(lgamma(r + k) - lgamma(r) - lgamma(k+1)) * pow(p, r) * pow((1-p), k); + return result; + } // negative_binomial_pdf + + template <class RealType, class Policy> + inline RealType cdf(const negative_binomial_distribution<RealType, Policy>& dist, const RealType& k) + { // Cumulative Distribution Function of Negative Binomial. + static const char* function = "boost::math::cdf(const negative_binomial_distribution<%1%>&, %1%)"; + using boost::math::ibeta; // Regularized incomplete beta function. + // k argument may be integral, signed, or unsigned, or floating point. + // If necessary, it has already been promoted from an integral type. + RealType p = dist.success_fraction(); + RealType r = dist.successes(); + // Error check: + RealType result; + if(false == negative_binomial_detail::check_dist_and_k( + function, + r, + dist.success_fraction(), + k, + &result, Policy())) + { + return result; + } + + RealType probability = ibeta(r, static_cast<RealType>(k+1), p, Policy()); + // Ip(r, k+1) = ibeta(r, k+1, p) + return probability; + } // cdf Cumulative Distribution Function Negative Binomial. + + template <class RealType, class Policy> + inline RealType cdf(const complemented2_type<negative_binomial_distribution<RealType, Policy>, RealType>& c) + { // Complemented Cumulative Distribution Function Negative Binomial. + + static const char* function = "boost::math::cdf(const negative_binomial_distribution<%1%>&, %1%)"; + using boost::math::ibetac; // Regularized incomplete beta function complement. + // k argument may be integral, signed, or unsigned, or floating point. + // If necessary, it has already been promoted from an integral type. + RealType const& k = c.param; + negative_binomial_distribution<RealType, Policy> const& dist = c.dist; + RealType p = dist.success_fraction(); + RealType r = dist.successes(); + // Error check: + RealType result; + if(false == negative_binomial_detail::check_dist_and_k( + function, + r, + p, + k, + &result, Policy())) + { + return result; + } + // Calculate cdf negative binomial using the incomplete beta function. + // Use of ibeta here prevents cancellation errors in calculating + // 1-p if p is very small, perhaps smaller than machine epsilon. + // Ip(k+1, r) = ibetac(r, k+1, p) + // constrain_probability here? + RealType probability = ibetac(r, static_cast<RealType>(k+1), p, Policy()); + // Numerical errors might cause probability to be slightly outside the range < 0 or > 1. + // This might cause trouble downstream, so warn, possibly throw exception, but constrain to the limits. + return probability; + } // cdf Cumulative Distribution Function Negative Binomial. + + template <class RealType, class Policy> + inline RealType quantile(const negative_binomial_distribution<RealType, Policy>& dist, const RealType& P) + { // Quantile, percentile/100 or Percent Point Negative Binomial function. + // Return the number of expected failures k for a given probability p. + + // Inverse cumulative Distribution Function or Quantile (percentile / 100) of negative_binomial Probability. + // MAthCAD pnbinom return smallest k such that negative_binomial(k, n, p) >= probability. + // k argument may be integral, signed, or unsigned, or floating point. + // BUT Cephes/CodeCogs says: finds argument p (0 to 1) such that cdf(k, n, p) = y + static const char* function = "boost::math::quantile(const negative_binomial_distribution<%1%>&, %1%)"; + BOOST_MATH_STD_USING // ADL of std functions. + + RealType p = dist.success_fraction(); + RealType r = dist.successes(); + // Check dist and P. + RealType result; + if(false == negative_binomial_detail::check_dist_and_prob + (function, r, p, P, &result, Policy())) + { + return result; + } + + // Special cases. + if (P == 1) + { // Would need +infinity failures for total confidence. + result = policies::raise_overflow_error<RealType>( + function, + "Probability argument is 1, which implies infinite failures !", Policy()); + return result; + // usually means return +std::numeric_limits<RealType>::infinity(); + // unless #define BOOST_MATH_THROW_ON_OVERFLOW_ERROR + } + if (P == 0) + { // No failures are expected if P = 0. + return 0; // Total trials will be just dist.successes. + } + if (P <= pow(dist.success_fraction(), dist.successes())) + { // p <= pdf(dist, 0) == cdf(dist, 0) + return 0; + } + /* + // Calculate quantile of negative_binomial using the inverse incomplete beta function. + using boost::math::ibeta_invb; + return ibeta_invb(r, p, P, Policy()) - 1; // + */ + RealType guess = 0; + RealType factor = 5; + if(r * r * r * P * p > 0.005) + guess = detail::inverse_negative_binomial_cornish_fisher(r, p, RealType(1-p), P, RealType(1-P), Policy()); + + if(guess < 10) + { + // + // Cornish-Fisher Negative binomial approximation not accurate in this area: + // + guess = (std::min)(RealType(r * 2), RealType(10)); + } + else + factor = (1-P < sqrt(tools::epsilon<RealType>())) ? 2 : (guess < 20 ? 1.2f : 1.1f); + BOOST_MATH_INSTRUMENT_CODE("guess = " << guess); + // + // Max iterations permitted: + // + boost::uintmax_t max_iter = policies::get_max_root_iterations<Policy>(); + typedef typename Policy::discrete_quantile_type discrete_type; + return detail::inverse_discrete_quantile( + dist, + P, + 1-P, + guess, + factor, + RealType(1), + discrete_type(), + max_iter); + } // RealType quantile(const negative_binomial_distribution dist, p) + + template <class RealType, class Policy> + inline RealType quantile(const complemented2_type<negative_binomial_distribution<RealType, Policy>, RealType>& c) + { // Quantile or Percent Point Binomial function. + // Return the number of expected failures k for a given + // complement of the probability Q = 1 - P. + static const char* function = "boost::math::quantile(const negative_binomial_distribution<%1%>&, %1%)"; + BOOST_MATH_STD_USING + + // Error checks: + RealType Q = c.param; + const negative_binomial_distribution<RealType, Policy>& dist = c.dist; + RealType p = dist.success_fraction(); + RealType r = dist.successes(); + RealType result; + if(false == negative_binomial_detail::check_dist_and_prob( + function, + r, + p, + Q, + &result, Policy())) + { + return result; + } + + // Special cases: + // + if(Q == 1) + { // There may actually be no answer to this question, + // since the probability of zero failures may be non-zero, + return 0; // but zero is the best we can do: + } + if (-Q <= boost::math::powm1(dist.success_fraction(), dist.successes(), Policy())) + { // q <= cdf(complement(dist, 0)) == pdf(dist, 0) + return 0; // + } + if(Q == 0) + { // Probability 1 - Q == 1 so infinite failures to achieve certainty. + // Would need +infinity failures for total confidence. + result = policies::raise_overflow_error<RealType>( + function, + "Probability argument complement is 0, which implies infinite failures !", Policy()); + return result; + // usually means return +std::numeric_limits<RealType>::infinity(); + // unless #define BOOST_MATH_THROW_ON_OVERFLOW_ERROR + } + //return ibetac_invb(r, p, Q, Policy()) -1; + RealType guess = 0; + RealType factor = 5; + if(r * r * r * (1-Q) * p > 0.005) + guess = detail::inverse_negative_binomial_cornish_fisher(r, p, RealType(1-p), RealType(1-Q), Q, Policy()); + + if(guess < 10) + { + // + // Cornish-Fisher Negative binomial approximation not accurate in this area: + // + guess = (std::min)(RealType(r * 2), RealType(10)); + } + else + factor = (Q < sqrt(tools::epsilon<RealType>())) ? 2 : (guess < 20 ? 1.2f : 1.1f); + BOOST_MATH_INSTRUMENT_CODE("guess = " << guess); + // + // Max iterations permitted: + // + boost::uintmax_t max_iter = policies::get_max_root_iterations<Policy>(); + typedef typename Policy::discrete_quantile_type discrete_type; + return detail::inverse_discrete_quantile( + dist, + 1-Q, + Q, + guess, + factor, + RealType(1), + discrete_type(), + max_iter); + } // quantile complement + + } // namespace math +} // namespace boost + +// This include must be at the end, *after* the accessors +// for this distribution have been defined, in order to +// keep compilers that support two-phase lookup happy. +#include <boost/math/distributions/detail/derived_accessors.hpp> + +#if defined (BOOST_MSVC) +# pragma warning(pop) +#endif + +#endif // BOOST_MATH_SPECIAL_NEGATIVE_BINOMIAL_HPP diff --git a/Utilities/BGL/boost/math/distributions/non_central_beta.hpp b/Utilities/BGL/boost/math/distributions/non_central_beta.hpp new file mode 100644 index 0000000000000000000000000000000000000000..3a98f64d7071af3197cdc5bcea90b2a530d19579 --- /dev/null +++ b/Utilities/BGL/boost/math/distributions/non_central_beta.hpp @@ -0,0 +1,843 @@ +// boost\math\distributions\non_central_beta.hpp + +// Copyright John Maddock 2008. + +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_SPECIAL_NON_CENTRAL_BETA_HPP +#define BOOST_MATH_SPECIAL_NON_CENTRAL_BETA_HPP + +#include <boost/math/distributions/fwd.hpp> +#include <boost/math/special_functions/beta.hpp> // for incomplete gamma. gamma_q +#include <boost/math/distributions/complement.hpp> // complements +#include <boost/math/distributions/beta.hpp> // central distribution +#include <boost/math/distributions/detail/generic_mode.hpp> +#include <boost/math/distributions/detail/common_error_handling.hpp> // error checks +#include <boost/math/special_functions/fpclassify.hpp> // isnan. +#include <boost/math/tools/roots.hpp> // for root finding. + +namespace boost +{ + namespace math + { + + template <class RealType, class Policy> + class non_central_beta_distribution; + + namespace detail{ + + template <class T, class Policy> + T non_central_beta_p(T a, T b, T lam, T x, T y, const Policy& pol, T init_val = 0) + { + BOOST_MATH_STD_USING + using namespace boost::math; + // + // Variables come first: + // + boost::uintmax_t max_iter = policies::get_max_series_iterations<Policy>(); + T errtol = boost::math::policies::get_epsilon<T, Policy>(); + T l2 = lam / 2; + // + // k is the starting point for iteration, and is the + // maximum of the poisson weighting term: + // + int k = itrunc(l2); + if(k == 0) + k = 1; + // Starting Poisson weight: + T pois = gamma_p_derivative(T(k+1), l2, pol); + if(pois == 0) + return init_val; + // recurance term: + T xterm; + // Starting beta term: + T beta = x < y + ? detail::ibeta_imp(T(a + k), b, x, pol, false, true, &xterm) + : detail::ibeta_imp(b, T(a + k), y, pol, true, true, &xterm); + + xterm *= y / (a + b + k - 1); + T poisf(pois), betaf(beta), xtermf(xterm); + T sum = init_val; + + if((beta == 0) && (xterm == 0)) + return init_val; + + // + // Backwards recursion first, this is the stable + // direction for recursion: + // + T last_term = 0; + boost::uintmax_t count = k; + for(int i = k; i >= 0; --i) + { + T term = beta * pois; + sum += term; + if(((fabs(term/sum) < errtol) && (last_term >= term)) || (term == 0)) + { + count = k - i; + break; + } + pois *= i / l2; + beta += xterm; + xterm *= (a + i - 1) / (x * (a + b + i - 2)); + last_term = term; + } + for(int i = k + 1; ; ++i) + { + poisf *= l2 / i; + xtermf *= (x * (a + b + i - 2)) / (a + i - 1); + betaf -= xtermf; + + T term = poisf * betaf; + sum += term; + if((fabs(term/sum) < errtol) || (term == 0)) + { + break; + } + if(static_cast<boost::uintmax_t>(count + i - k) > max_iter) + { + return policies::raise_evaluation_error( + "cdf(non_central_beta_distribution<%1%>, %1%)", + "Series did not converge, closest value was %1%", sum, pol); + } + } + return sum; + } + + template <class T, class Policy> + T non_central_beta_q(T a, T b, T lam, T x, T y, const Policy& pol, T init_val = 0) + { + BOOST_MATH_STD_USING + using namespace boost::math; + // + // Variables come first: + // + boost::uintmax_t max_iter = policies::get_max_series_iterations<Policy>(); + T errtol = boost::math::policies::get_epsilon<T, Policy>(); + T l2 = lam / 2; + // + // k is the starting point for iteration, and is the + // maximum of the poisson weighting term: + // + int k = itrunc(l2); + if(k == 0) + k = 1; + // Starting Poisson weight: + T pois = gamma_p_derivative(T(k+1), l2, pol); + if(pois == 0) + return init_val; + // recurance term: + T xterm; + // Starting beta term: + T beta = x < y + ? detail::ibeta_imp(T(a + k), b, x, pol, true, true, &xterm) + : detail::ibeta_imp(b, T(a + k), y, pol, false, true, &xterm); + + xterm *= y / (a + b + k - 1); + T poisf(pois), betaf(beta), xtermf(xterm); + T sum = init_val; + if((beta == 0) && (xterm == 0)) + return init_val; + // + // Forwards recursion first, this is the stable + // direction for recursion, and the location + // of the bulk of the sum: + // + T last_term = 0; + boost::uintmax_t count = 0; + for(int i = k + 1; ; ++i) + { + poisf *= l2 / i; + xtermf *= (x * (a + b + i - 2)) / (a + i - 1); + betaf += xtermf; + + T term = poisf * betaf; + sum += term; + if((fabs(term/sum) < errtol) && (last_term >= term)) + { + count = i - k; + break; + } + if(static_cast<boost::uintmax_t>(i - k) > max_iter) + { + return policies::raise_evaluation_error( + "cdf(non_central_beta_distribution<%1%>, %1%)", + "Series did not converge, closest value was %1%", sum, pol); + } + last_term = term; + } + for(int i = k; i >= 0; --i) + { + T term = beta * pois; + sum += term; + if(fabs(term/sum) < errtol) + { + break; + } + if(static_cast<boost::uintmax_t>(count + k - i) > max_iter) + { + return policies::raise_evaluation_error( + "cdf(non_central_beta_distribution<%1%>, %1%)", + "Series did not converge, closest value was %1%", sum, pol); + } + pois *= i / l2; + beta -= xterm; + xterm *= (a + i - 1) / (x * (a + b + i - 2)); + } + return sum; + } + + template <class RealType, class Policy> + inline RealType non_central_beta_cdf(RealType x, RealType y, RealType a, RealType b, RealType l, bool invert, const Policy&) + { + typedef typename policies::evaluation<RealType, Policy>::type value_type; + typedef typename policies::normalise< + Policy, + policies::promote_float<false>, + policies::promote_double<false>, + policies::discrete_quantile<>, + policies::assert_undefined<> >::type forwarding_policy; + + BOOST_MATH_STD_USING + + if(x == 0) + return invert ? 1.0f : 0.0f; + if(y == 0) + return invert ? 0.0f : 1.0f; + value_type result; + value_type c = a + b + l / 2; + value_type cross = 1 - (b / c) * (1 + l / (2 * c * c)); + if(l == 0) + result = cdf(boost::math::beta_distribution<RealType, Policy>(a, b), x); + else if(x > cross) + { + // Complement is the smaller of the two: + result = detail::non_central_beta_q( + static_cast<value_type>(a), + static_cast<value_type>(b), + static_cast<value_type>(l), + static_cast<value_type>(x), + static_cast<value_type>(y), + forwarding_policy(), + static_cast<value_type>(invert ? 0 : -1)); + invert = !invert; + } + else + { + result = detail::non_central_beta_p( + static_cast<value_type>(a), + static_cast<value_type>(b), + static_cast<value_type>(l), + static_cast<value_type>(x), + static_cast<value_type>(y), + forwarding_policy(), + static_cast<value_type>(invert ? -1 : 0)); + } + if(invert) + result = -result; + return policies::checked_narrowing_cast<RealType, forwarding_policy>( + result, + "boost::math::non_central_beta_cdf<%1%>(%1%, %1%, %1%)"); + } + + template <class T, class Policy> + struct nc_beta_quantile_functor + { + nc_beta_quantile_functor(const non_central_beta_distribution<T,Policy>& d, T t, bool c) + : dist(d), target(t), comp(c) {} + + T operator()(const T& x) + { + return comp ? + target - cdf(complement(dist, x)) + : cdf(dist, x) - target; + } + + private: + non_central_beta_distribution<T,Policy> dist; + T target; + bool comp; + }; + + // + // This is more or less a copy of bracket_and_solve_root, but + // modified to search only the interval [0,1] using similar + // heuristics. + // + template <class F, class T, class Tol, class Policy> + std::pair<T, T> bracket_and_solve_root_01(F f, const T& guess, T factor, bool rising, Tol tol, boost::uintmax_t& max_iter, const Policy& pol) + { + BOOST_MATH_STD_USING + static const char* function = "boost::math::tools::bracket_and_solve_root_01<%1%>"; + // + // Set up inital brackets: + // + T a = guess; + T b = a; + T fa = f(a); + T fb = fa; + // + // Set up invocation count: + // + boost::uintmax_t count = max_iter - 1; + + if((fa < 0) == (guess < 0 ? !rising : rising)) + { + // + // Zero is to the right of b, so walk upwards + // until we find it: + // + while((boost::math::sign)(fb) == (boost::math::sign)(fa)) + { + if(count == 0) + { + b = policies::raise_evaluation_error(function, "Unable to bracket root, last nearest value was %1%", b, pol); + return std::make_pair(a, b); + } + // + // Heuristic: every 20 iterations we double the growth factor in case the + // initial guess was *really* bad ! + // + if((max_iter - count) % 20 == 0) + factor *= 2; + // + // Now go ahead and move are guess by "factor", + // we do this by reducing 1-guess by factor: + // + a = b; + fa = fb; + b = 1 - ((1 - b) / factor); + fb = f(b); + --count; + BOOST_MATH_INSTRUMENT_CODE("a = " << a << " b = " << b << " fa = " << fa << " fb = " << fb << " count = " << count); + } + } + else + { + // + // Zero is to the left of a, so walk downwards + // until we find it: + // + while((boost::math::sign)(fb) == (boost::math::sign)(fa)) + { + if(fabs(a) < tools::min_value<T>()) + { + // Escape route just in case the answer is zero! + max_iter -= count; + max_iter += 1; + return a > 0 ? std::make_pair(T(0), T(a)) : std::make_pair(T(a), T(0)); + } + if(count == 0) + { + a = policies::raise_evaluation_error(function, "Unable to bracket root, last nearest value was %1%", a, pol); + return std::make_pair(a, b); + } + // + // Heuristic: every 20 iterations we double the growth factor in case the + // initial guess was *really* bad ! + // + if((max_iter - count) % 20 == 0) + factor *= 2; + // + // Now go ahead and move are guess by "factor": + // + b = a; + fb = fa; + a /= factor; + fa = f(a); + --count; + BOOST_MATH_INSTRUMENT_CODE("a = " << a << " b = " << b << " fa = " << fa << " fb = " << fb << " count = " << count); + } + } + max_iter -= count; + max_iter += 1; + std::pair<T, T> r = toms748_solve( + f, + (a < 0 ? b : a), + (a < 0 ? a : b), + (a < 0 ? fb : fa), + (a < 0 ? fa : fb), + tol, + count, + pol); + max_iter += count; + BOOST_MATH_INSTRUMENT_CODE("max_iter = " << max_iter << " count = " << count); + return r; + } + + template <class RealType, class Policy> + RealType nc_beta_quantile(const non_central_beta_distribution<RealType, Policy>& dist, const RealType& p, bool comp) + { + static const char* function = "quantile(non_central_beta_distribution<%1%>, %1%)"; + typedef typename policies::evaluation<RealType, Policy>::type value_type; + typedef typename policies::normalise< + Policy, + policies::promote_float<false>, + policies::promote_double<false>, + policies::discrete_quantile<>, + policies::assert_undefined<> >::type forwarding_policy; + + value_type a = dist.alpha(); + value_type b = dist.beta(); + value_type l = dist.non_centrality(); + value_type r; + if(!beta_detail::check_alpha( + function, + a, &r, Policy()) + || + !beta_detail::check_beta( + function, + b, &r, Policy()) + || + !detail::check_non_centrality( + function, + l, + &r, + Policy()) + || + !detail::check_probability( + function, + static_cast<value_type>(p), + &r, + Policy())) + return (RealType)r; + // + // Special cases first: + // + if(p == 0) + return comp + ? 1.0f + : 0.0f; + if(p == 1) + return !comp + ? 1.0f + : 0.0f; + + value_type c = a + b + l / 2; + value_type mean = 1 - (b / c) * (1 + l / (2 * c * c)); + /* + // + // Calculate a normal approximation to the quantile, + // uses mean and variance approximations from: + // Algorithm AS 310: + // Computing the Non-Central Beta Distribution Function + // R. Chattamvelli; R. Shanmugam + // Applied Statistics, Vol. 46, No. 1. (1997), pp. 146-156. + // + // Unfortunately, when this is wrong it tends to be *very* + // wrong, so it's disabled for now, even though it often + // gets the initial guess quite close. Probably we could + // do much better by factoring in the skewness if only + // we could calculate it.... + // + value_type delta = l / 2; + value_type delta2 = delta * delta; + value_type delta3 = delta * delta2; + value_type delta4 = delta2 * delta2; + value_type G = c * (c + 1) + delta; + value_type alpha = a + b; + value_type alpha2 = alpha * alpha; + value_type eta = (2 * alpha + 1) * (2 * alpha + 1) + 1; + value_type H = 3 * alpha2 + 5 * alpha + 2; + value_type F = alpha2 * (alpha + 1) + H * delta + + (2 * alpha + 4) * delta2 + delta3; + value_type P = (3 * alpha + 1) * (9 * alpha + 17) + + 2 * alpha * (3 * alpha + 2) * (3 * alpha + 4) + 15; + value_type Q = 54 * alpha2 + 162 * alpha + 130; + value_type R = 6 * (6 * alpha + 11); + value_type D = delta + * (H * H + 2 * P * delta + Q * delta2 + R * delta3 + 9 * delta4); + value_type variance = (b / G) + * (1 + delta * (l * l + 3 * l + eta) / (G * G)) + - (b * b / F) * (1 + D / (F * F)); + value_type sd = sqrt(variance); + + value_type guess = comp + ? quantile(complement(normal_distribution<RealType, Policy>(static_cast<RealType>(mean), static_cast<RealType>(sd)), p)) + : quantile(normal_distribution<RealType, Policy>(static_cast<RealType>(mean), static_cast<RealType>(sd)), p); + + if(guess >= 1) + guess = mean; + if(guess <= tools::min_value<value_type>()) + guess = mean; + */ + value_type guess = mean; + detail::nc_beta_quantile_functor<value_type, Policy> + f(non_central_beta_distribution<value_type, Policy>(a, b, l), p, comp); + tools::eps_tolerance<value_type> tol(policies::digits<RealType, Policy>()); + boost::uintmax_t max_iter = policies::get_max_root_iterations<Policy>(); + + std::pair<value_type, value_type> ir + = bracket_and_solve_root_01( + f, guess, value_type(2.5), true, tol, + max_iter, Policy()); + value_type result = ir.first + (ir.second - ir.first) / 2; + + if(max_iter >= policies::get_max_root_iterations<Policy>()) + { + return policies::raise_evaluation_error<RealType>(function, "Unable to locate solution in a reasonable time:" + " either there is no answer to quantile of the non central beta distribution" + " or the answer is infinite. Current best guess is %1%", + policies::checked_narrowing_cast<RealType, forwarding_policy>( + result, + function), Policy()); + } + return policies::checked_narrowing_cast<RealType, forwarding_policy>( + result, + function); + } + + template <class T, class Policy> + T non_central_beta_pdf(T a, T b, T lam, T x, T y, const Policy& pol) + { + BOOST_MATH_STD_USING + using namespace boost::math; + // + // Variables come first: + // + boost::uintmax_t max_iter = policies::get_max_series_iterations<Policy>(); + T errtol = boost::math::policies::get_epsilon<T, Policy>(); + T l2 = lam / 2; + // + // k is the starting point for iteration, and is the + // maximum of the poisson weighting term: + // + int k = itrunc(l2); + // Starting Poisson weight: + T pois = gamma_p_derivative(T(k+1), l2, pol); + // Starting beta term: + T beta = x < y ? + ibeta_derivative(a + k, b, x, pol) + : ibeta_derivative(b, a + k, y, pol); + T sum = 0; + T poisf(pois); + T betaf(beta); + + // + // Stable backwards recursion first: + // + boost::uintmax_t count = k; + for(int i = k; i >= 0; --i) + { + T term = beta * pois; + sum += term; + if((fabs(term/sum) < errtol) || (term == 0)) + { + count = k - i; + break; + } + pois *= i / l2; + beta *= (a + i - 1) / (x * (a + i + b - 1)); + } + for(int i = k + 1; ; ++i) + { + poisf *= l2 / i; + betaf *= x * (a + b + i - 1) / (a + i - 1); + + T term = poisf * betaf; + sum += term; + if((fabs(term/sum) < errtol) || (term == 0)) + { + break; + } + if(static_cast<boost::uintmax_t>(count + i - k) > max_iter) + { + return policies::raise_evaluation_error( + "pdf(non_central_beta_distribution<%1%>, %1%)", + "Series did not converge, closest value was %1%", sum, pol); + } + } + return sum; + } + + template <class RealType, class Policy> + RealType nc_beta_pdf(const non_central_beta_distribution<RealType, Policy>& dist, const RealType& x) + { + BOOST_MATH_STD_USING + static const char* function = "pdf(non_central_beta_distribution<%1%>, %1%)"; + typedef typename policies::evaluation<RealType, Policy>::type value_type; + typedef typename policies::normalise< + Policy, + policies::promote_float<false>, + policies::promote_double<false>, + policies::discrete_quantile<>, + policies::assert_undefined<> >::type forwarding_policy; + + value_type a = dist.alpha(); + value_type b = dist.beta(); + value_type l = dist.non_centrality(); + value_type r; + if(!beta_detail::check_alpha( + function, + a, &r, Policy()) + || + !beta_detail::check_beta( + function, + b, &r, Policy()) + || + !detail::check_non_centrality( + function, + l, + &r, + Policy()) + || + !beta_detail::check_x( + function, + static_cast<value_type>(x), + &r, + Policy())) + return (RealType)r; + + BOOST_MATH_STD_USING + if(l == 0) + return pdf(boost::math::beta_distribution<RealType, Policy>(dist.alpha(), dist.beta()), x); + return policies::checked_narrowing_cast<RealType, forwarding_policy>( + non_central_beta_pdf(a, b, l, static_cast<value_type>(x), value_type(1 - static_cast<value_type>(x)), forwarding_policy()), + "function"); + } + + } // namespace detail + + template <class RealType = double, class Policy = policies::policy<> > + class non_central_beta_distribution + { + public: + typedef RealType value_type; + typedef Policy policy_type; + + non_central_beta_distribution(RealType a_, RealType b_, RealType lambda) : a(a_), b(b_), ncp(lambda) + { + const char* function = "boost::math::non_central_beta_distribution<%1%>::non_central_beta_distribution(%1%,%1%)"; + RealType r; + beta_detail::check_alpha( + function, + a, &r, Policy()); + beta_detail::check_beta( + function, + b, &r, Policy()); + detail::check_non_centrality( + function, + lambda, + &r, + Policy()); + } // non_central_beta_distribution constructor. + + RealType alpha() const + { // Private data getter function. + return a; + } + RealType beta() const + { // Private data getter function. + return b; + } + RealType non_centrality() const + { // Private data getter function. + return ncp; + } + private: + // Data member, initialized by constructor. + RealType a; // alpha. + RealType b; // beta. + RealType ncp; // non-centrality parameter + }; // template <class RealType, class Policy> class non_central_beta_distribution + + typedef non_central_beta_distribution<double> non_central_beta; // Reserved name of type double. + + // Non-member functions to give properties of the distribution. + + template <class RealType, class Policy> + inline const std::pair<RealType, RealType> range(const non_central_beta_distribution<RealType, Policy>& /* dist */) + { // Range of permissible values for random variable k. + using boost::math::tools::max_value; + return std::pair<RealType, RealType>(0, 1); + } + + template <class RealType, class Policy> + inline const std::pair<RealType, RealType> support(const non_central_beta_distribution<RealType, Policy>& /* dist */) + { // Range of supported values for random variable k. + // This is range where cdf rises from 0 to 1, and outside it, the pdf is zero. + using boost::math::tools::max_value; + return std::pair<RealType, RealType>(0, 1); + } + + template <class RealType, class Policy> + inline RealType mode(const non_central_beta_distribution<RealType, Policy>& dist) + { // mode. + static const char* function = "mode(non_central_beta_distribution<%1%> const&)"; + + RealType a = dist.alpha(); + RealType b = dist.beta(); + RealType l = dist.non_centrality(); + RealType r; + if(!beta_detail::check_alpha( + function, + a, &r, Policy()) + || + !beta_detail::check_beta( + function, + b, &r, Policy()) + || + !detail::check_non_centrality( + function, + l, + &r, + Policy())) + return (RealType)r; + RealType c = a + b + l / 2; + RealType mean = 1 - (b / c) * (1 + l / (2 * c * c)); + return detail::generic_find_mode_01( + dist, + mean, + function); + } + +#if 0 + // + // We don't have the necessary information to implement + // these at present. These are just disabled for now, + // prototypes retained so we can fill in the blanks + // later: + // + template <class RealType, class Policy> + inline RealType mean(const non_central_beta_distribution<RealType, Policy>& dist) + { + // TODO + return 0; + } // mean + + template <class RealType, class Policy> + inline RealType variance(const non_central_beta_distribution<RealType, Policy>& dist) + { // variance. + const char* function = "boost::math::non_central_beta_distribution<%1%>::variance()"; + // TODO + return 0; + } + + // RealType standard_deviation(const non_central_beta_distribution<RealType, Policy>& dist) + // standard_deviation provided by derived accessors. + + template <class RealType, class Policy> + inline RealType skewness(const non_central_beta_distribution<RealType, Policy>& dist) + { // skewness = sqrt(l). + const char* function = "boost::math::non_central_beta_distribution<%1%>::skewness()"; + // TODO + return 0; + } + + template <class RealType, class Policy> + inline RealType kurtosis_excess(const non_central_beta_distribution<RealType, Policy>& dist) + { + const char* function = "boost::math::non_central_beta_distribution<%1%>::kurtosis_excess()"; + // TODO + return 0; + } // kurtosis_excess + + template <class RealType, class Policy> + inline RealType kurtosis(const non_central_beta_distribution<RealType, Policy>& dist) + { + return kurtosis_excess(dist) + 3; + } +#endif + template <class RealType, class Policy> + inline RealType pdf(const non_central_beta_distribution<RealType, Policy>& dist, const RealType& x) + { // Probability Density/Mass Function. + return detail::nc_beta_pdf(dist, x); + } // pdf + + template <class RealType, class Policy> + RealType cdf(const non_central_beta_distribution<RealType, Policy>& dist, const RealType& x) + { + const char* function = "boost::math::non_central_beta_distribution<%1%>::cdf(%1%)"; + RealType a = dist.alpha(); + RealType b = dist.beta(); + RealType l = dist.non_centrality(); + RealType r; + if(!beta_detail::check_alpha( + function, + a, &r, Policy()) + || + !beta_detail::check_beta( + function, + b, &r, Policy()) + || + !detail::check_non_centrality( + function, + l, + &r, + Policy()) + || + !beta_detail::check_x( + function, + x, + &r, + Policy())) + return (RealType)r; + + if(l == 0) + return cdf(beta_distribution<RealType, Policy>(a, b), x); + + return detail::non_central_beta_cdf(x, RealType(1 - x), a, b, l, false, Policy()); + } // cdf + + template <class RealType, class Policy> + RealType cdf(const complemented2_type<non_central_beta_distribution<RealType, Policy>, RealType>& c) + { // Complemented Cumulative Distribution Function + const char* function = "boost::math::non_central_beta_distribution<%1%>::cdf(%1%)"; + non_central_beta_distribution<RealType, Policy> const& dist = c.dist; + RealType a = dist.alpha(); + RealType b = dist.beta(); + RealType l = dist.non_centrality(); + RealType x = c.param; + RealType r; + if(!beta_detail::check_alpha( + function, + a, &r, Policy()) + || + !beta_detail::check_beta( + function, + b, &r, Policy()) + || + !detail::check_non_centrality( + function, + l, + &r, + Policy()) + || + !beta_detail::check_x( + function, + x, + &r, + Policy())) + return (RealType)r; + + if(l == 0) + return cdf(complement(beta_distribution<RealType, Policy>(a, b), x)); + + return detail::non_central_beta_cdf(x, RealType(1 - x), a, b, l, true, Policy()); + } // ccdf + + template <class RealType, class Policy> + inline RealType quantile(const non_central_beta_distribution<RealType, Policy>& dist, const RealType& p) + { // Quantile (or Percent Point) function. + return detail::nc_beta_quantile(dist, p, false); + } // quantile + + template <class RealType, class Policy> + inline RealType quantile(const complemented2_type<non_central_beta_distribution<RealType, Policy>, RealType>& c) + { // Quantile (or Percent Point) function. + return detail::nc_beta_quantile(c.dist, c.param, true); + } // quantile complement. + + } // namespace math +} // namespace boost + +// This include must be at the end, *after* the accessors +// for this distribution have been defined, in order to +// keep compilers that support two-phase lookup happy. +#include <boost/math/distributions/detail/derived_accessors.hpp> + +#endif // BOOST_MATH_SPECIAL_NON_CENTRAL_BETA_HPP + diff --git a/Utilities/BGL/boost/math/distributions/non_central_chi_squared.hpp b/Utilities/BGL/boost/math/distributions/non_central_chi_squared.hpp new file mode 100644 index 0000000000000000000000000000000000000000..45099785daede0ef88b2ee96606cc95753baebb6 --- /dev/null +++ b/Utilities/BGL/boost/math/distributions/non_central_chi_squared.hpp @@ -0,0 +1,964 @@ +// boost\math\distributions\non_central_chi_squared.hpp + +// Copyright John Maddock 2008. + +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_SPECIAL_NON_CENTRAL_CHI_SQUARE_HPP +#define BOOST_MATH_SPECIAL_NON_CENTRAL_CHI_SQUARE_HPP + +#include <boost/math/distributions/fwd.hpp> +#include <boost/math/special_functions/gamma.hpp> // for incomplete gamma. gamma_q +#include <boost/math/special_functions/bessel.hpp> // for cyl_bessel_i +#include <boost/math/special_functions/round.hpp> // for iround +#include <boost/math/distributions/complement.hpp> // complements +#include <boost/math/distributions/chi_squared.hpp> // central distribution +#include <boost/math/distributions/detail/common_error_handling.hpp> // error checks +#include <boost/math/special_functions/fpclassify.hpp> // isnan. +#include <boost/math/tools/roots.hpp> // for root finding. +#include <boost/math/distributions/detail/generic_mode.hpp> +#include <boost/math/distributions/detail/generic_quantile.hpp> + +namespace boost +{ + namespace math + { + + template <class RealType, class Policy> + class non_central_chi_squared_distribution; + + namespace detail{ + + template <class T, class Policy> + T non_central_chi_square_q(T x, T f, T theta, const Policy& pol, T init_sum = 0) + { + // + // Computes the complement of the Non-Central Chi-Square + // Distribution CDF by summing a weighted sum of complements + // of the central-distributions. The weighting factor is + // a Poisson Distribution. + // + // This is an application of the technique described in: + // + // Computing discrete mixtures of continuous + // distributions: noncentral chisquare, noncentral t + // and the distribution of the square of the sample + // multiple correlation coeficient. + // D. Benton, K. Krishnamoorthy. + // Computational Statistics & Data Analysis 43 (2003) 249 - 267 + // + BOOST_MATH_STD_USING + + // Special case: + if(x == 0) + return 1; + + // + // Initialize the variables we'll be using: + // + T lambda = theta / 2; + T del = f / 2; + T y = x / 2; + boost::uintmax_t max_iter = policies::get_max_series_iterations<Policy>(); + T errtol = boost::math::policies::get_epsilon<T, Policy>(); + T sum = init_sum; + // + // k is the starting location for iteration, we'll + // move both forwards and backwards from this point. + // k is chosen as the peek of the Poisson weights, which + // will occur *before* the largest term. + // + int k = iround(lambda, pol); + // Forwards and backwards Poisson weights: + T poisf = boost::math::gamma_p_derivative(1 + k, lambda, pol); + T poisb = poisf * k / lambda; + // Initial forwards central chi squared term: + T gamf = boost::math::gamma_q(del + k, y, pol); + // Forwards and backwards recursion terms on the central chi squared: + T xtermf = boost::math::gamma_p_derivative(del + 1 + k, y, pol); + T xtermb = xtermf * (del + k) / y; + // Initial backwards central chi squared term: + T gamb = gamf - xtermb; + + // + // Forwards iteration first, this is the + // stable direction for the gamma function + // recurrences: + // + int i; + for(i = k; static_cast<boost::uintmax_t>(i-k) < max_iter; ++i) + { + T term = poisf * gamf; + sum += term; + poisf *= lambda / (i + 1); + gamf += xtermf; + xtermf *= y / (del + i + 1); + if(((sum == 0) || (fabs(term / sum) < errtol)) && (term >= poisf * gamf)) + break; + } + //Error check: + if(static_cast<boost::uintmax_t>(i-k) >= max_iter) + policies::raise_evaluation_error( + "cdf(non_central_chi_squared_distribution<%1%>, %1%)", + "Series did not converge, closest value was %1%", sum, pol); + // + // Now backwards iteration: the gamma + // function recurrences are unstable in this + // direction, we rely on the terms deminishing in size + // faster than we introduce cancellation errors. + // For this reason it's very important that we start + // *before* the largest term so that backwards iteration + // is strictly converging. + // + for(i = k - 1; i >= 0; --i) + { + T term = poisb * gamb; + sum += term; + poisb *= i / lambda; + xtermb *= (del + i) / y; + gamb -= xtermb; + if((sum == 0) || (fabs(term / sum) < errtol)) + break; + } + + return sum; + } + + template <class T, class Policy> + T non_central_chi_square_p_ding(T x, T f, T theta, const Policy& pol, T init_sum = 0) + { + // + // This is an implementation of: + // + // Algorithm AS 275: + // Computing the Non-Central #2 Distribution Function + // Cherng G. Ding + // Applied Statistics, Vol. 41, No. 2. (1992), pp. 478-482. + // + // This uses a stable forward iteration to sum the + // CDF, unfortunately this can not be used for large + // values of the non-centrality parameter because: + // * The first term may underfow to zero. + // * We may need an extra-ordinary number of terms + // before we reach the first *significant* term. + // + BOOST_MATH_STD_USING + // Special case: + if(x == 0) + return 0; + T tk = boost::math::gamma_p_derivative(f/2 + 1, x/2, pol); + T lambda = theta / 2; + T vk = exp(-lambda); + T uk = vk; + T sum = init_sum + tk * vk; + if(sum == 0) + return sum; + + boost::uintmax_t max_iter = policies::get_max_series_iterations<Policy>(); + T errtol = boost::math::policies::get_epsilon<T, Policy>(); + + int i; + T lterm(0), term(0); + for(i = 1; static_cast<boost::uintmax_t>(i) < max_iter; ++i) + { + tk = tk * x / (f + 2 * i); + uk = uk * lambda / i; + vk = vk + uk; + lterm = term; + term = vk * tk; + sum += term; + if((fabs(term / sum) < errtol) && (term <= lterm)) + break; + } + //Error check: + if(static_cast<boost::uintmax_t>(i) >= max_iter) + policies::raise_evaluation_error( + "cdf(non_central_chi_squared_distribution<%1%>, %1%)", + "Series did not converge, closest value was %1%", sum, pol); + return sum; + } + + + template <class T, class Policy> + T non_central_chi_square_p(T y, T n, T lambda, const Policy& pol, T init_sum) + { + // + // This is taken more or less directly from: + // + // Computing discrete mixtures of continuous + // distributions: noncentral chisquare, noncentral t + // and the distribution of the square of the sample + // multiple correlation coeficient. + // D. Benton, K. Krishnamoorthy. + // Computational Statistics & Data Analysis 43 (2003) 249 - 267 + // + // We're summing a Poisson weighting term multiplied by + // a central chi squared distribution. + // + BOOST_MATH_STD_USING + // Special case: + if(y == 0) + return 0; + boost::uintmax_t max_iter = policies::get_max_series_iterations<Policy>(); + T errtol = boost::math::policies::get_epsilon<T, Policy>(); + T errorf(0), errorb(0); + + T x = y / 2; + T del = lambda / 2; + // + // Starting location for the iteration, we'll iterate + // both forwards and backwards from this point. The + // location chosen is the maximum of the Poisson weight + // function, which ocurrs *after* the largest term in the + // sum. + // + int k = iround(del, pol); + T a = n / 2 + k; + // Central chi squared term for forward iteration: + T gamkf = boost::math::gamma_p(a, x, pol); + + if(lambda == 0) + return gamkf; + // Central chi squared term for backward iteration: + T gamkb = gamkf; + // Forwards Poisson weight: + T poiskf = gamma_p_derivative(k+1, del, pol); + // Backwards Poisson weight: + T poiskb = poiskf; + // Forwards gamma function recursion term: + T xtermf = boost::math::gamma_p_derivative(a, x, pol); + // Backwards gamma function recursion term: + T xtermb = xtermf * x / a; + T sum = init_sum + poiskf * gamkf; + if(sum == 0) + return sum; + int i = 1; + // + // Backwards recursion first, this is the stable + // direction for gamma function recurrences: + // + while(i <= k) + { + xtermb *= (a - i + 1) / x; + gamkb += xtermb; + poiskb = poiskb * (k - i + 1) / del; + errorf = errorb; + errorb = gamkb * poiskb; + sum += errorb; + if((fabs(errorb / sum) < errtol) && (errorb <= errorf)) + break; + ++i; + } + i = 1; + // + // Now forwards recursion, the gamma function + // recurrence relation is unstable in this direction, + // so we rely on the magnitude of successive terms + // decreasing faster than we introduce cancellation error. + // For this reason it's vital that k is chosen to be *after* + // the largest term, so that successive forward iterations + // are strictly (and rapidly) converging. + // + do + { + xtermf = xtermf * x / (a + i - 1); + gamkf = gamkf - xtermf; + poiskf = poiskf * del / (k + i); + errorf = poiskf * gamkf; + sum += errorf; + ++i; + }while((fabs(errorf / sum) > errtol) && (static_cast<boost::uintmax_t>(i) < max_iter)); + + //Error check: + if(static_cast<boost::uintmax_t>(i) >= max_iter) + policies::raise_evaluation_error( + "cdf(non_central_chi_squared_distribution<%1%>, %1%)", + "Series did not converge, closest value was %1%", sum, pol); + + return sum; + } + + template <class T, class Policy> + T non_central_chi_square_pdf(T x, T n, T lambda, const Policy& pol) + { + // + // As above but for the PDF: + // + BOOST_MATH_STD_USING + boost::uintmax_t max_iter = policies::get_max_series_iterations<Policy>(); + T errtol = boost::math::policies::get_epsilon<T, Policy>(); + T x2 = x / 2; + T n2 = n / 2; + T l2 = lambda / 2; + T sum = 0; + int k = itrunc(l2); + T pois = gamma_p_derivative(k + 1, l2, pol) * gamma_p_derivative(n2 + k, x2); + if(pois == 0) + return 0; + T poisb = pois; + for(int i = k; ; ++i) + { + sum += pois; + if(pois / sum < errtol) + break; + if(static_cast<boost::uintmax_t>(i - k) >= max_iter) + return policies::raise_evaluation_error( + "pdf(non_central_chi_squared_distribution<%1%>, %1%)", + "Series did not converge, closest value was %1%", sum, pol); + pois *= l2 * x2 / ((i + 1) * (n2 + i)); + } + for(int i = k - 1; i >= 0; --i) + { + poisb *= (i + 1) * (n2 + i) / (l2 * x2); + sum += poisb; + if(poisb / sum < errtol) + break; + } + return sum / 2; + } + + template <class RealType, class Policy> + inline RealType non_central_chi_squared_cdf(RealType x, RealType k, RealType l, bool invert, const Policy&) + { + typedef typename policies::evaluation<RealType, Policy>::type value_type; + typedef typename policies::normalise< + Policy, + policies::promote_float<false>, + policies::promote_double<false>, + policies::discrete_quantile<>, + policies::assert_undefined<> >::type forwarding_policy; + + BOOST_MATH_STD_USING + value_type result; + if(l == 0) + result = cdf(boost::math::chi_squared_distribution<RealType, Policy>(k), x); + else if(x > k + l) + { + // Complement is the smaller of the two: + result = detail::non_central_chi_square_q( + static_cast<value_type>(x), + static_cast<value_type>(k), + static_cast<value_type>(l), + forwarding_policy(), + static_cast<value_type>(invert ? 0 : -1)); + invert = !invert; + } + else if(l < 200) + { + // For small values of the non-centrality parameter + // we can use Ding's method: + result = detail::non_central_chi_square_p_ding( + static_cast<value_type>(x), + static_cast<value_type>(k), + static_cast<value_type>(l), + forwarding_policy(), + static_cast<value_type>(invert ? -1 : 0)); + } + else + { + // For largers values of the non-centrality + // parameter Ding's method will consume an + // extra-ordinary number of terms, and worse + // may return zero when the result is in fact + // finite, use Krishnamoorthy's method instead: + result = detail::non_central_chi_square_p( + static_cast<value_type>(x), + static_cast<value_type>(k), + static_cast<value_type>(l), + forwarding_policy(), + static_cast<value_type>(invert ? -1 : 0)); + } + if(invert) + result = -result; + return policies::checked_narrowing_cast<RealType, forwarding_policy>( + result, + "boost::math::non_central_chi_squared_cdf<%1%>(%1%, %1%, %1%)"); + } + + template <class T, class Policy> + struct nccs_quantile_functor + { + nccs_quantile_functor(const non_central_chi_squared_distribution<T,Policy>& d, T t, bool c) + : dist(d), target(t), comp(c) {} + + T operator()(const T& x) + { + return comp ? + target - cdf(complement(dist, x)) + : cdf(dist, x) - target; + } + + private: + non_central_chi_squared_distribution<T,Policy> dist; + T target; + bool comp; + }; + + template <class RealType, class Policy> + RealType nccs_quantile(const non_central_chi_squared_distribution<RealType, Policy>& dist, const RealType& p, bool comp) + { + static const char* function = "quantile(non_central_chi_squared_distribution<%1%>, %1%)"; + typedef typename policies::evaluation<RealType, Policy>::type value_type; + typedef typename policies::normalise< + Policy, + policies::promote_float<false>, + policies::promote_double<false>, + policies::discrete_quantile<>, + policies::assert_undefined<> >::type forwarding_policy; + + value_type k = dist.degrees_of_freedom(); + value_type l = dist.non_centrality(); + value_type r; + if(!detail::check_df( + function, + k, &r, Policy()) + || + !detail::check_non_centrality( + function, + l, + &r, + Policy()) + || + !detail::check_probability( + function, + static_cast<value_type>(p), + &r, + Policy())) + return (RealType)r; + + value_type b = (l * l) / (k + 3 * l); + value_type c = (k + 3 * l) / (k + 2 * l); + value_type ff = (k + 2 * l) / (c * c); + value_type guess; + if(comp) + guess = b + c * quantile(complement(chi_squared_distribution<value_type, forwarding_policy>(ff), p)); + else + guess = b + c * quantile(chi_squared_distribution<value_type, forwarding_policy>(ff), p); + + if(guess < 0) + guess = tools::min_value<value_type>(); + + value_type result = detail::generic_quantile( + non_central_chi_squared_distribution<value_type, forwarding_policy>(k, l), + p, + guess, + comp, + function); + return policies::checked_narrowing_cast<RealType, forwarding_policy>( + result, + function); + } + + template <class RealType, class Policy> + RealType nccs_pdf(const non_central_chi_squared_distribution<RealType, Policy>& dist, const RealType& x) + { + BOOST_MATH_STD_USING + static const char* function = "pdf(non_central_chi_squared_distribution<%1%>, %1%)"; + typedef typename policies::evaluation<RealType, Policy>::type value_type; + typedef typename policies::normalise< + Policy, + policies::promote_float<false>, + policies::promote_double<false>, + policies::discrete_quantile<>, + policies::assert_undefined<> >::type forwarding_policy; + + value_type k = dist.degrees_of_freedom(); + value_type l = dist.non_centrality(); + value_type r; + if(!detail::check_df( + function, + k, &r, Policy()) + || + !detail::check_non_centrality( + function, + l, + &r, + Policy()) + || + !detail::check_positive_x( + function, + (value_type)x, + &r, + Policy())) + return (RealType)r; + + BOOST_MATH_STD_USING + if(l == 0) + return pdf(boost::math::chi_squared_distribution<RealType, forwarding_policy>(dist.degrees_of_freedom()), x); + + // Special case: + if(x == 0) + return 0; + if(l > 50) + { + r = non_central_chi_square_pdf(static_cast<value_type>(x), k, l, forwarding_policy()); + } + else + { + r = log(x / l) * (k / 4 - 0.5f) - (x + l) / 2; + if(fabs(r) >= tools::log_max_value<RealType>() / 4) + { + r = non_central_chi_square_pdf(static_cast<value_type>(x), k, l, forwarding_policy()); + } + else + { + r = exp(r); + r = 0.5f * r + * boost::math::cyl_bessel_i(k/2 - 1, sqrt(l * x), forwarding_policy()); + } + } + return policies::checked_narrowing_cast<RealType, forwarding_policy>( + r, + function); + } + + template <class RealType, class Policy> + struct degrees_of_freedom_finder + { + degrees_of_freedom_finder( + RealType lam_, RealType x_, RealType p_, bool c) + : lam(lam_), x(x_), p(p_), comp(c) {} + + RealType operator()(const RealType& v) + { + non_central_chi_squared_distribution<RealType, Policy> d(v, lam); + return comp ? + p - cdf(complement(d, x)) + : cdf(d, x) - p; + } + private: + RealType lam; + RealType x; + RealType p; + bool comp; + }; + + template <class RealType, class Policy> + inline RealType find_degrees_of_freedom( + RealType lam, RealType x, RealType p, RealType q, const Policy& pol) + { + const char* function = "non_central_chi_squared<%1%>::find_degrees_of_freedom"; + if((p == 0) || (q == 0)) + { + // + // Can't a thing if one of p and q is zero: + // + return policies::raise_evaluation_error<RealType>(function, + "Can't find degrees of freedom when the probability is 0 or 1, only possible answer is %1%", + RealType(std::numeric_limits<RealType>::quiet_NaN()), Policy()); + } + degrees_of_freedom_finder<RealType, Policy> f(lam, x, p < q ? p : q, p < q ? false : true); + tools::eps_tolerance<RealType> tol(policies::digits<RealType, Policy>()); + boost::uintmax_t max_iter = policies::get_max_root_iterations<Policy>(); + // + // Pick an initial guess that we know will give us a probability + // right around 0.5. + // + RealType guess = x - lam; + if(guess < 1) + guess = 1; + std::pair<RealType, RealType> ir = tools::bracket_and_solve_root( + f, guess, RealType(2), false, tol, max_iter, pol); + RealType result = ir.first + (ir.second - ir.first) / 2; + if(max_iter >= policies::get_max_root_iterations<Policy>()) + { + policies::raise_evaluation_error<RealType>(function, "Unable to locate solution in a reasonable time:" + " or there is no answer to problem. Current best guess is %1%", result, Policy()); + } + return result; + } + + template <class RealType, class Policy> + struct non_centrality_finder + { + non_centrality_finder( + RealType v_, RealType x_, RealType p_, bool c) + : v(v_), x(x_), p(p_), comp(c) {} + + RealType operator()(const RealType& lam) + { + non_central_chi_squared_distribution<RealType, Policy> d(v, lam); + return comp ? + p - cdf(complement(d, x)) + : cdf(d, x) - p; + } + private: + RealType v; + RealType x; + RealType p; + bool comp; + }; + + template <class RealType, class Policy> + inline RealType find_non_centrality( + RealType v, RealType x, RealType p, RealType q, const Policy& pol) + { + const char* function = "non_central_chi_squared<%1%>::find_non_centrality"; + if((p == 0) || (q == 0)) + { + // + // Can't do a thing if one of p and q is zero: + // + return policies::raise_evaluation_error<RealType>(function, + "Can't find non centrality parameter when the probability is 0 or 1, only possible answer is %1%", + RealType(std::numeric_limits<RealType>::quiet_NaN()), Policy()); + } + non_centrality_finder<RealType, Policy> f(v, x, p < q ? p : q, p < q ? false : true); + tools::eps_tolerance<RealType> tol(policies::digits<RealType, Policy>()); + boost::uintmax_t max_iter = policies::get_max_root_iterations<Policy>(); + // + // Pick an initial guess that we know will give us a probability + // right around 0.5. + // + RealType guess = x - v; + if(guess < 1) + guess = 1; + std::pair<RealType, RealType> ir = tools::bracket_and_solve_root( + f, guess, RealType(2), false, tol, max_iter, pol); + RealType result = ir.first + (ir.second - ir.first) / 2; + if(max_iter >= policies::get_max_root_iterations<Policy>()) + { + policies::raise_evaluation_error<RealType>(function, "Unable to locate solution in a reasonable time:" + " or there is no answer to problem. Current best guess is %1%", result, Policy()); + } + return result; + } + + } + + template <class RealType = double, class Policy = policies::policy<> > + class non_central_chi_squared_distribution + { + public: + typedef RealType value_type; + typedef Policy policy_type; + + non_central_chi_squared_distribution(RealType df_, RealType lambda) : df(df_), ncp(lambda) + { + const char* function = "boost::math::non_central_chi_squared_distribution<%1%>::non_central_chi_squared_distribution(%1%,%1%)"; + RealType r; + detail::check_df( + function, + df, &r, Policy()); + detail::check_non_centrality( + function, + ncp, + &r, + Policy()); + } // non_central_chi_squared_distribution constructor. + + RealType degrees_of_freedom() const + { // Private data getter function. + return df; + } + RealType non_centrality() const + { // Private data getter function. + return ncp; + } + static RealType find_degrees_of_freedom(RealType lam, RealType x, RealType p) + { + const char* function = "non_central_chi_squared<%1%>::find_degrees_of_freedom"; + typedef typename policies::evaluation<RealType, Policy>::type value_type; + typedef typename policies::normalise< + Policy, + policies::promote_float<false>, + policies::promote_double<false>, + policies::discrete_quantile<>, + policies::assert_undefined<> >::type forwarding_policy; + value_type result = detail::find_degrees_of_freedom( + static_cast<value_type>(lam), + static_cast<value_type>(x), + static_cast<value_type>(p), + static_cast<value_type>(1-p), + forwarding_policy()); + return policies::checked_narrowing_cast<RealType, forwarding_policy>( + result, + function); + } + template <class A, class B, class C> + static RealType find_degrees_of_freedom(const complemented3_type<A,B,C>& c) + { + const char* function = "non_central_chi_squared<%1%>::find_degrees_of_freedom"; + typedef typename policies::evaluation<RealType, Policy>::type value_type; + typedef typename policies::normalise< + Policy, + policies::promote_float<false>, + policies::promote_double<false>, + policies::discrete_quantile<>, + policies::assert_undefined<> >::type forwarding_policy; + value_type result = detail::find_degrees_of_freedom( + static_cast<value_type>(c.dist), + static_cast<value_type>(c.param1), + static_cast<value_type>(1-c.param2), + static_cast<value_type>(c.param2), + forwarding_policy()); + return policies::checked_narrowing_cast<RealType, forwarding_policy>( + result, + function); + } + static RealType find_non_centrality(RealType v, RealType x, RealType p) + { + const char* function = "non_central_chi_squared<%1%>::find_non_centrality"; + typedef typename policies::evaluation<RealType, Policy>::type value_type; + typedef typename policies::normalise< + Policy, + policies::promote_float<false>, + policies::promote_double<false>, + policies::discrete_quantile<>, + policies::assert_undefined<> >::type forwarding_policy; + value_type result = detail::find_non_centrality( + static_cast<value_type>(v), + static_cast<value_type>(x), + static_cast<value_type>(p), + static_cast<value_type>(1-p), + forwarding_policy()); + return policies::checked_narrowing_cast<RealType, forwarding_policy>( + result, + function); + } + template <class A, class B, class C> + static RealType find_non_centrality(const complemented3_type<A,B,C>& c) + { + const char* function = "non_central_chi_squared<%1%>::find_non_centrality"; + typedef typename policies::evaluation<RealType, Policy>::type value_type; + typedef typename policies::normalise< + Policy, + policies::promote_float<false>, + policies::promote_double<false>, + policies::discrete_quantile<>, + policies::assert_undefined<> >::type forwarding_policy; + value_type result = detail::find_non_centrality( + static_cast<value_type>(c.dist), + static_cast<value_type>(c.param1), + static_cast<value_type>(1-c.param2), + static_cast<value_type>(c.param2), + forwarding_policy()); + return policies::checked_narrowing_cast<RealType, forwarding_policy>( + result, + function); + } + private: + // Data member, initialized by constructor. + RealType df; // degrees of freedom. + RealType ncp; // non-centrality parameter + }; // template <class RealType, class Policy> class non_central_chi_squared_distribution + + typedef non_central_chi_squared_distribution<double> non_central_chi_squared; // Reserved name of type double. + + // Non-member functions to give properties of the distribution. + + template <class RealType, class Policy> + inline const std::pair<RealType, RealType> range(const non_central_chi_squared_distribution<RealType, Policy>& /* dist */) + { // Range of permissible values for random variable k. + using boost::math::tools::max_value; + return std::pair<RealType, RealType>(0, max_value<RealType>()); // Max integer? + } + + template <class RealType, class Policy> + inline const std::pair<RealType, RealType> support(const non_central_chi_squared_distribution<RealType, Policy>& /* dist */) + { // Range of supported values for random variable k. + // This is range where cdf rises from 0 to 1, and outside it, the pdf is zero. + using boost::math::tools::max_value; + return std::pair<RealType, RealType>(0, max_value<RealType>()); + } + + template <class RealType, class Policy> + inline RealType mean(const non_central_chi_squared_distribution<RealType, Policy>& dist) + { // Mean of poisson distribution = lambda. + const char* function = "boost::math::non_central_chi_squared_distribution<%1%>::mean()"; + RealType k = dist.degrees_of_freedom(); + RealType l = dist.non_centrality(); + RealType r; + if(!detail::check_df( + function, + k, &r, Policy()) + || + !detail::check_non_centrality( + function, + l, + &r, + Policy())) + return r; + return k + l; + } // mean + + template <class RealType, class Policy> + inline RealType mode(const non_central_chi_squared_distribution<RealType, Policy>& dist) + { // mode. + static const char* function = "mode(non_central_chi_squared_distribution<%1%> const&)"; + + RealType k = dist.degrees_of_freedom(); + RealType l = dist.non_centrality(); + RealType r; + if(!detail::check_df( + function, + k, &r, Policy()) + || + !detail::check_non_centrality( + function, + l, + &r, + Policy())) + return (RealType)r; + return detail::generic_find_mode(dist, 1 + k, function); + } + + template <class RealType, class Policy> + inline RealType variance(const non_central_chi_squared_distribution<RealType, Policy>& dist) + { // variance. + const char* function = "boost::math::non_central_chi_squared_distribution<%1%>::variance()"; + RealType k = dist.degrees_of_freedom(); + RealType l = dist.non_centrality(); + RealType r; + if(!detail::check_df( + function, + k, &r, Policy()) + || + !detail::check_non_centrality( + function, + l, + &r, + Policy())) + return r; + return 2 * (2 * l + k); + } + + // RealType standard_deviation(const non_central_chi_squared_distribution<RealType, Policy>& dist) + // standard_deviation provided by derived accessors. + + template <class RealType, class Policy> + inline RealType skewness(const non_central_chi_squared_distribution<RealType, Policy>& dist) + { // skewness = sqrt(l). + const char* function = "boost::math::non_central_chi_squared_distribution<%1%>::skewness()"; + RealType k = dist.degrees_of_freedom(); + RealType l = dist.non_centrality(); + RealType r; + if(!detail::check_df( + function, + k, &r, Policy()) + || + !detail::check_non_centrality( + function, + l, + &r, + Policy())) + return r; + BOOST_MATH_STD_USING + return pow(2 / (k + 2 * l), RealType(3)/2) * (k + 3 * l); + } + + template <class RealType, class Policy> + inline RealType kurtosis_excess(const non_central_chi_squared_distribution<RealType, Policy>& dist) + { + const char* function = "boost::math::non_central_chi_squared_distribution<%1%>::kurtosis_excess()"; + RealType k = dist.degrees_of_freedom(); + RealType l = dist.non_centrality(); + RealType r; + if(!detail::check_df( + function, + k, &r, Policy()) + || + !detail::check_non_centrality( + function, + l, + &r, + Policy())) + return r; + return 12 * (k + 4 * l) / ((k + 2 * l) * (k + 2 * l)); + } // kurtosis_excess + + template <class RealType, class Policy> + inline RealType kurtosis(const non_central_chi_squared_distribution<RealType, Policy>& dist) + { + return kurtosis_excess(dist) + 3; + } + + template <class RealType, class Policy> + inline RealType pdf(const non_central_chi_squared_distribution<RealType, Policy>& dist, const RealType& x) + { // Probability Density/Mass Function. + return detail::nccs_pdf(dist, x); + } // pdf + + template <class RealType, class Policy> + RealType cdf(const non_central_chi_squared_distribution<RealType, Policy>& dist, const RealType& x) + { + const char* function = "boost::math::non_central_chi_squared_distribution<%1%>::cdf(%1%)"; + RealType k = dist.degrees_of_freedom(); + RealType l = dist.non_centrality(); + RealType r; + if(!detail::check_df( + function, + k, &r, Policy()) + || + !detail::check_non_centrality( + function, + l, + &r, + Policy()) + || + !detail::check_positive_x( + function, + x, + &r, + Policy())) + return r; + + return detail::non_central_chi_squared_cdf(x, k, l, false, Policy()); + } // cdf + + template <class RealType, class Policy> + RealType cdf(const complemented2_type<non_central_chi_squared_distribution<RealType, Policy>, RealType>& c) + { // Complemented Cumulative Distribution Function + const char* function = "boost::math::non_central_chi_squared_distribution<%1%>::cdf(%1%)"; + non_central_chi_squared_distribution<RealType, Policy> const& dist = c.dist; + RealType x = c.param; + RealType k = dist.degrees_of_freedom(); + RealType l = dist.non_centrality(); + RealType r; + if(!detail::check_df( + function, + k, &r, Policy()) + || + !detail::check_non_centrality( + function, + l, + &r, + Policy()) + || + !detail::check_positive_x( + function, + x, + &r, + Policy())) + return r; + + return detail::non_central_chi_squared_cdf(x, k, l, true, Policy()); + } // ccdf + + template <class RealType, class Policy> + inline RealType quantile(const non_central_chi_squared_distribution<RealType, Policy>& dist, const RealType& p) + { // Quantile (or Percent Point) function. + return detail::nccs_quantile(dist, p, false); + } // quantile + + template <class RealType, class Policy> + inline RealType quantile(const complemented2_type<non_central_chi_squared_distribution<RealType, Policy>, RealType>& c) + { // Quantile (or Percent Point) function. + return detail::nccs_quantile(c.dist, c.param, true); + } // quantile complement. + + } // namespace math +} // namespace boost + +// This include must be at the end, *after* the accessors +// for this distribution have been defined, in order to +// keep compilers that support two-phase lookup happy. +#include <boost/math/distributions/detail/derived_accessors.hpp> + +#endif // BOOST_MATH_SPECIAL_NON_CENTRAL_CHI_SQUARE_HPP + + + diff --git a/Utilities/BGL/boost/math/distributions/non_central_f.hpp b/Utilities/BGL/boost/math/distributions/non_central_f.hpp new file mode 100644 index 0000000000000000000000000000000000000000..6380ad1ca37fb7c033ee9f837d9bbbb49d1ba265 --- /dev/null +++ b/Utilities/BGL/boost/math/distributions/non_central_f.hpp @@ -0,0 +1,409 @@ +// boost\math\distributions\non_central_f.hpp + +// Copyright John Maddock 2008. + +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_SPECIAL_NON_CENTRAL_F_HPP +#define BOOST_MATH_SPECIAL_NON_CENTRAL_F_HPP + +#include <boost/math/distributions/non_central_beta.hpp> +#include <boost/math/distributions/detail/generic_mode.hpp> +#include <boost/math/special_functions/pow.hpp> + +namespace boost +{ + namespace math + { + template <class RealType = double, class Policy = policies::policy<> > + class non_central_f_distribution + { + public: + typedef RealType value_type; + typedef Policy policy_type; + + non_central_f_distribution(RealType v1_, RealType v2_, RealType lambda) : v1(v1_), v2(v2_), ncp(lambda) + { + const char* function = "boost::math::non_central_f_distribution<%1%>::non_central_f_distribution(%1%,%1%)"; + RealType r; + detail::check_df( + function, + v1, &r, Policy()); + detail::check_df( + function, + v2, &r, Policy()); + detail::check_non_centrality( + function, + lambda, + &r, + Policy()); + } // non_central_f_distribution constructor. + + RealType degrees_of_freedom1()const + { + return v1; + } + RealType degrees_of_freedom2()const + { + return v2; + } + RealType non_centrality() const + { // Private data getter function. + return ncp; + } + private: + // Data member, initialized by constructor. + RealType v1; // alpha. + RealType v2; // beta. + RealType ncp; // non-centrality parameter + }; // template <class RealType, class Policy> class non_central_f_distribution + + typedef non_central_f_distribution<double> non_central_f; // Reserved name of type double. + + // Non-member functions to give properties of the distribution. + + template <class RealType, class Policy> + inline const std::pair<RealType, RealType> range(const non_central_f_distribution<RealType, Policy>& /* dist */) + { // Range of permissible values for random variable k. + using boost::math::tools::max_value; + return std::pair<RealType, RealType>(0, max_value<RealType>()); + } + + template <class RealType, class Policy> + inline const std::pair<RealType, RealType> support(const non_central_f_distribution<RealType, Policy>& /* dist */) + { // Range of supported values for random variable k. + // This is range where cdf rises from 0 to 1, and outside it, the pdf is zero. + using boost::math::tools::max_value; + return std::pair<RealType, RealType>(0, max_value<RealType>()); + } + + template <class RealType, class Policy> + inline RealType mean(const non_central_f_distribution<RealType, Policy>& dist) + { + const char* function = "mean(non_central_f_distribution<%1%> const&)"; + RealType v1 = dist.degrees_of_freedom1(); + RealType v2 = dist.degrees_of_freedom2(); + RealType l = dist.non_centrality(); + RealType r; + if(!detail::check_df( + function, + v1, &r, Policy()) + || + !detail::check_df( + function, + v2, &r, Policy()) + || + !detail::check_non_centrality( + function, + l, + &r, + Policy())) + return r; + if(v2 <= 2) + return policies::raise_domain_error( + function, + "Second degrees of freedom parameter was %1%, but must be > 2 !", + v2, Policy()); + return v2 * (v1 + l) / (v1 * (v2 - 2)); + } // mean + + template <class RealType, class Policy> + inline RealType mode(const non_central_f_distribution<RealType, Policy>& dist) + { // mode. + static const char* function = "mode(non_central_chi_squared_distribution<%1%> const&)"; + + RealType n = dist.degrees_of_freedom1(); + RealType m = dist.degrees_of_freedom2(); + RealType l = dist.non_centrality(); + RealType r; + if(!detail::check_df( + function, + n, &r, Policy()) + || + !detail::check_df( + function, + m, &r, Policy()) + || + !detail::check_non_centrality( + function, + l, + &r, + Policy())) + return r; + return detail::generic_find_mode( + dist, + m * (n + l) / (n * (m - 2)), + function); + } + + template <class RealType, class Policy> + inline RealType variance(const non_central_f_distribution<RealType, Policy>& dist) + { // variance. + const char* function = "variance(non_central_f_distribution<%1%> const&)"; + RealType n = dist.degrees_of_freedom1(); + RealType m = dist.degrees_of_freedom2(); + RealType l = dist.non_centrality(); + RealType r; + if(!detail::check_df( + function, + n, &r, Policy()) + || + !detail::check_df( + function, + m, &r, Policy()) + || + !detail::check_non_centrality( + function, + l, + &r, + Policy())) + return r; + if(m <= 4) + return policies::raise_domain_error( + function, + "Second degrees of freedom parameter was %1%, but must be > 4 !", + m, Policy()); + RealType result = 2 * m * m * ((n + l) * (n + l) + + (m - 2) * (n + 2 * l)); + result /= (m - 4) * (m - 2) * (m - 2) * n * n; + return result; + } + + // RealType standard_deviation(const non_central_f_distribution<RealType, Policy>& dist) + // standard_deviation provided by derived accessors. + + template <class RealType, class Policy> + inline RealType skewness(const non_central_f_distribution<RealType, Policy>& dist) + { // skewness = sqrt(l). + const char* function = "skewness(non_central_f_distribution<%1%> const&)"; + BOOST_MATH_STD_USING + RealType n = dist.degrees_of_freedom1(); + RealType m = dist.degrees_of_freedom2(); + RealType l = dist.non_centrality(); + RealType r; + if(!detail::check_df( + function, + n, &r, Policy()) + || + !detail::check_df( + function, + m, &r, Policy()) + || + !detail::check_non_centrality( + function, + l, + &r, + Policy())) + return r; + if(m <= 6) + return policies::raise_domain_error( + function, + "Second degrees of freedom parameter was %1%, but must be > 6 !", + m, Policy()); + RealType result = 2 * constants::root_two<RealType>(); + result *= sqrt(m - 4); + result *= (n * (m + n - 2) *(m + 2 * n - 2) + + 3 * (m + n - 2) * (m + 2 * n - 2) * l + + 6 * (m + n - 2) * l * l + 2 * l * l * l); + result /= (m - 6) * pow(n * (m + n - 2) + 2 * (m + n - 2) * l + l * l, RealType(1.5f)); + return result; + } + + template <class RealType, class Policy> + inline RealType kurtosis_excess(const non_central_f_distribution<RealType, Policy>& dist) + { + const char* function = "kurtosis_excess(non_central_f_distribution<%1%> const&)"; + BOOST_MATH_STD_USING + RealType n = dist.degrees_of_freedom1(); + RealType m = dist.degrees_of_freedom2(); + RealType l = dist.non_centrality(); + RealType r; + if(!detail::check_df( + function, + n, &r, Policy()) + || + !detail::check_df( + function, + m, &r, Policy()) + || + !detail::check_non_centrality( + function, + l, + &r, + Policy())) + return r; + if(m <= 8) + return policies::raise_domain_error( + function, + "Second degrees of freedom parameter was %1%, but must be > 8 !", + m, Policy()); + RealType l2 = l * l; + RealType l3 = l2 * l; + RealType l4 = l2 * l2; + RealType result = (3 * (m - 4) * (n * (m + n - 2) + * (4 * (m - 2) * (m - 2) + + (m - 2) * (m + 10) * n + + (10 + m) * n * n) + + 4 * (m + n - 2) * (4 * (m - 2) * (m - 2) + + (m - 2) * (10 + m) * n + + (10 + m) * n * n) * l + 2 * (10 + m) + * (m + n - 2) * (2 * m + 3 * n - 4) * l2 + + 4 * (10 + m) * (-2 + m + n) * l3 + + (10 + m) * l4)) + / + ((-8 + m) * (-6 + m) * boost::math::pow<2>(n * (-2 + m + n) + + 2 * (-2 + m + n) * l + l2)); + return result; + } // kurtosis_excess + + template <class RealType, class Policy> + inline RealType kurtosis(const non_central_f_distribution<RealType, Policy>& dist) + { + return kurtosis_excess(dist) + 3; + } + + template <class RealType, class Policy> + inline RealType pdf(const non_central_f_distribution<RealType, Policy>& dist, const RealType& x) + { // Probability Density/Mass Function. + typedef typename policies::evaluation<RealType, Policy>::type value_type; + typedef typename policies::normalise< + Policy, + policies::promote_float<false>, + policies::promote_double<false>, + policies::discrete_quantile<>, + policies::assert_undefined<> >::type forwarding_policy; + + value_type alpha = dist.degrees_of_freedom1() / 2; + value_type beta = dist.degrees_of_freedom2() / 2; + value_type y = x * alpha / beta; + value_type r = pdf(boost::math::non_central_beta_distribution<value_type, forwarding_policy>(alpha, beta, dist.non_centrality()), y / (1 + y)); + return policies::checked_narrowing_cast<RealType, forwarding_policy>( + r * (dist.degrees_of_freedom1() / dist.degrees_of_freedom2()) / ((1 + y) * (1 + y)), + "pdf(non_central_f_distribution<%1%>, %1%)"); + } // pdf + + template <class RealType, class Policy> + RealType cdf(const non_central_f_distribution<RealType, Policy>& dist, const RealType& x) + { + const char* function = "cdf(const non_central_f_distribution<%1%>&, %1%)"; + RealType r; + if(!detail::check_df( + function, + dist.degrees_of_freedom1(), &r, Policy()) + || + !detail::check_df( + function, + dist.degrees_of_freedom2(), &r, Policy()) + || + !detail::check_non_centrality( + function, + dist.non_centrality(), + &r, + Policy())) + return r; + + if((x < 0) || !(boost::math::isfinite)(x)) + { + return policies::raise_domain_error<RealType>( + function, "Random Variable parameter was %1%, but must be > 0 !", x, Policy()); + } + + RealType alpha = dist.degrees_of_freedom1() / 2; + RealType beta = dist.degrees_of_freedom2() / 2; + RealType y = x * alpha / beta; + RealType c = y / (1 + y); + RealType cp = 1 / (1 + y); + // + // To ensure accuracy, we pass both x and 1-x to the + // non-central beta cdf routine, this ensures accuracy + // even when we compute x to be ~ 1: + // + r = detail::non_central_beta_cdf(c, cp, alpha, beta, + dist.non_centrality(), false, Policy()); + return r; + } // cdf + + template <class RealType, class Policy> + RealType cdf(const complemented2_type<non_central_f_distribution<RealType, Policy>, RealType>& c) + { // Complemented Cumulative Distribution Function + const char* function = "cdf(complement(const non_central_f_distribution<%1%>&, %1%))"; + RealType r; + if(!detail::check_df( + function, + c.dist.degrees_of_freedom1(), &r, Policy()) + || + !detail::check_df( + function, + c.dist.degrees_of_freedom2(), &r, Policy()) + || + !detail::check_non_centrality( + function, + c.dist.non_centrality(), + &r, + Policy())) + return r; + + if((c.param < 0) || !(boost::math::isfinite)(c.param)) + { + return policies::raise_domain_error<RealType>( + function, "Random Variable parameter was %1%, but must be > 0 !", c.param, Policy()); + } + + RealType alpha = c.dist.degrees_of_freedom1() / 2; + RealType beta = c.dist.degrees_of_freedom2() / 2; + RealType y = c.param * alpha / beta; + RealType x = y / (1 + y); + RealType cx = 1 / (1 + y); + // + // To ensure accuracy, we pass both x and 1-x to the + // non-central beta cdf routine, this ensures accuracy + // even when we compute x to be ~ 1: + // + r = detail::non_central_beta_cdf(x, cx, alpha, beta, + c.dist.non_centrality(), true, Policy()); + return r; + } // ccdf + + template <class RealType, class Policy> + inline RealType quantile(const non_central_f_distribution<RealType, Policy>& dist, const RealType& p) + { // Quantile (or Percent Point) function. + RealType alpha = dist.degrees_of_freedom1() / 2; + RealType beta = dist.degrees_of_freedom2() / 2; + RealType x = quantile(boost::math::non_central_beta_distribution<RealType, Policy>(alpha, beta, dist.non_centrality()), p); + if(x == 1) + return policies::raise_overflow_error<RealType>( + "quantile(const non_central_f_distribution<%1%>&, %1%)", + "Result of non central F quantile is too large to represent.", + Policy()); + return (x / (1 - x)) * (dist.degrees_of_freedom2() / dist.degrees_of_freedom1()); + } // quantile + + template <class RealType, class Policy> + inline RealType quantile(const complemented2_type<non_central_f_distribution<RealType, Policy>, RealType>& c) + { // Quantile (or Percent Point) function. + RealType alpha = c.dist.degrees_of_freedom1() / 2; + RealType beta = c.dist.degrees_of_freedom2() / 2; + RealType x = quantile(complement(boost::math::non_central_beta_distribution<RealType, Policy>(alpha, beta, c.dist.non_centrality()), c.param)); + if(x == 1) + return policies::raise_overflow_error<RealType>( + "quantile(complement(const non_central_f_distribution<%1%>&, %1%))", + "Result of non central F quantile is too large to represent.", + Policy()); + return (x / (1 - x)) * (c.dist.degrees_of_freedom2() / c.dist.degrees_of_freedom1()); + } // quantile complement. + + } // namespace math +} // namespace boost + +// This include must be at the end, *after* the accessors +// for this distribution have been defined, in order to +// keep compilers that support two-phase lookup happy. +#include <boost/math/distributions/detail/derived_accessors.hpp> + +#endif // BOOST_MATH_SPECIAL_NON_CENTRAL_F_HPP + + + diff --git a/Utilities/BGL/boost/math/distributions/non_central_t.hpp b/Utilities/BGL/boost/math/distributions/non_central_t.hpp new file mode 100644 index 0000000000000000000000000000000000000000..1bac891818c5fc2af64bb794bc4bd67e4bc2c0a2 --- /dev/null +++ b/Utilities/BGL/boost/math/distributions/non_central_t.hpp @@ -0,0 +1,1065 @@ +// boost\math\distributions\non_central_t.hpp + +// Copyright John Maddock 2008. + +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_SPECIAL_NON_CENTRAL_T_HPP +#define BOOST_MATH_SPECIAL_NON_CENTRAL_T_HPP + +#include <boost/math/distributions/fwd.hpp> +#include <boost/math/distributions/non_central_beta.hpp> // for nc beta +#include <boost/math/distributions/normal.hpp> // for normal CDF and quantile +#include <boost/math/distributions/students_t.hpp> +#include <boost/math/distributions/detail/generic_quantile.hpp> // quantile + +namespace boost +{ + namespace math + { + + template <class RealType, class Policy> + class non_central_t_distribution; + + namespace detail{ + + template <class T, class Policy> + T non_central_t2_p(T n, T delta, T x, T y, const Policy& pol, T init_val) + { + BOOST_MATH_STD_USING + // + // Variables come first: + // + boost::uintmax_t max_iter = policies::get_max_series_iterations<Policy>(); + T errtol = policies::get_epsilon<T, Policy>(); + T d2 = delta * delta / 2; + // + // k is the starting point for iteration, and is the + // maximum of the poisson weighting term: + // + int k = boost::math::itrunc(d2); + // Starting Poisson weight: + T pois = gamma_p_derivative(T(k+1), d2, pol) + * tgamma_delta_ratio(T(k + 1), T(0.5f)) + * delta / constants::root_two<T>(); + if(pois == 0) + return init_val; + // Recurance term: + T xterm; + // Starting beta term: + T beta = x < y + ? detail::ibeta_imp(T(k + 1), T(n / 2), x, pol, false, true, &xterm) + : detail::ibeta_imp(T(n / 2), T(k + 1), y, pol, true, true, &xterm); + + xterm *= y / (n / 2 + k); + T poisf(pois), betaf(beta), xtermf(xterm); + T sum = init_val; + if((xterm == 0) && (beta == 0)) + return init_val; + + // + // Backwards recursion first, this is the stable + // direction for recursion: + // + boost::uintmax_t count = 0; + for(int i = k; i >= 0; --i) + { + T term = beta * pois; + sum += term; + if(fabs(term/sum) < errtol) + break; + pois *= (i + 0.5f) / d2; + beta += xterm; + xterm *= (i) / (x * (n / 2 + i - 1)); + ++count; + } + for(int i = k + 1; ; ++i) + { + poisf *= d2 / (i + 0.5f); + xtermf *= (x * (n / 2 + i - 1)) / (i); + betaf -= xtermf; + T term = poisf * betaf; + sum += term; + if(fabs(term/sum) < errtol) + break; + ++count; + if(count > max_iter) + { + return policies::raise_evaluation_error( + "cdf(non_central_t_distribution<%1%>, %1%)", + "Series did not converge, closest value was %1%", sum, pol); + } + } + return sum; + } + + template <class T, class Policy> + T non_central_t2_q(T n, T delta, T x, T y, const Policy& pol, T init_val) + { + BOOST_MATH_STD_USING + // + // Variables come first: + // + boost::uintmax_t max_iter = policies::get_max_series_iterations<Policy>(); + T errtol = boost::math::policies::get_epsilon<T, Policy>(); + T d2 = delta * delta / 2; + // + // k is the starting point for iteration, and is the + // maximum of the poisson weighting term: + // + int k = boost::math::itrunc(d2); + // Starting Poisson weight: + T pois = gamma_p_derivative(T(k+1), d2, pol) + * tgamma_delta_ratio(T(k + 1), T(0.5f)) + * delta / constants::root_two<T>(); + if(pois == 0) + return init_val; + // Recurance term: + T xterm; + // Starting beta term: + T beta = x < y + ? detail::ibeta_imp(T(k + 1), T(n / 2), x, pol, true, true, &xterm) + : detail::ibeta_imp(T(n / 2), T(k + 1), y, pol, false, true, &xterm); + + xterm *= y / (n / 2 + k); + T poisf(pois), betaf(beta), xtermf(xterm); + T sum = init_val; + if((xterm == 0) && (beta == 0)) + return init_val; + + // + // Forward recursion first, this is the stable direction: + // + boost::uintmax_t count = 0; + for(int i = k + 1; ; ++i) + { + poisf *= d2 / (i + 0.5f); + xtermf *= (x * (n / 2 + i - 1)) / (i); + betaf += xtermf; + + T term = poisf * betaf; + sum += term; + if(fabs(term/sum) < errtol) + break; + if(count > max_iter) + { + return policies::raise_evaluation_error( + "cdf(non_central_t_distribution<%1%>, %1%)", + "Series did not converge, closest value was %1%", sum, pol); + } + ++count; + } + // + // Backwards recursion: + // + for(int i = k; i >= 0; --i) + { + T term = beta * pois; + sum += term; + if(fabs(term/sum) < errtol) + break; + pois *= (i + 0.5f) / d2; + beta -= xterm; + xterm *= (i) / (x * (n / 2 + i - 1)); + ++count; + if(count > max_iter) + { + return policies::raise_evaluation_error( + "cdf(non_central_t_distribution<%1%>, %1%)", + "Series did not converge, closest value was %1%", sum, pol); + } + } + return sum; + } + + template <class T, class Policy> + T non_central_t_cdf(T n, T delta, T t, bool invert, const Policy& pol) + { + // + // For t < 0 we have to use reflect: + // + if(t < 0) + { + t = -t; + delta = -delta; + invert = !invert; + } + // + // x and y are the corresponding random + // variables for the noncentral beta distribution, + // with y = 1 - x: + // + T x = t * t / (n + t * t); + T y = n / (n + t * t); + T d2 = delta * delta; + T a = 0.5f; + T b = n / 2; + T c = a + b + d2 / 2; + // + // Crossover point for calculating p or q is the same + // as for the noncentral beta: + // + T cross = 1 - (b / c) * (1 + d2 / (2 * c * c)); + T result; + if(x < cross) + { + // + // Calculate p: + // + if(x != 0) + { + result = non_central_beta_p(a, b, d2, x, y, pol); + result = non_central_t2_p(n, delta, x, y, pol, result); + result /= 2; + } + else + result = 0; + result += cdf(boost::math::normal_distribution<T, Policy>(), -delta); + } + else + { + // + // Calculate q: + // + invert = !invert; + if(x != 0) + { + result = non_central_beta_q(a, b, d2, x, y, pol); + result = non_central_t2_q(n, delta, x, y, pol, result); + result /= 2; + } + else + result = cdf(complement(boost::math::normal_distribution<T, Policy>(), -delta)); + } + if(invert) + result = 1 - result; + return result; + } + + template <class T, class Policy> + T non_central_t_quantile(T v, T delta, T p, T q, const Policy&) + { + BOOST_MATH_STD_USING + static const char* function = "quantile(non_central_t_distribution<%1%>, %1%)"; + typedef typename policies::evaluation<T, Policy>::type value_type; + typedef typename policies::normalise< + Policy, + policies::promote_float<false>, + policies::promote_double<false>, + policies::discrete_quantile<>, + policies::assert_undefined<> >::type forwarding_policy; + + T r; + if(!detail::check_df( + function, + v, &r, Policy()) + || + !detail::check_finite( + function, + delta, + &r, + Policy()) + || + !detail::check_probability( + function, + p, + &r, + Policy())) + return r; + + value_type guess = 0; + if(v > 3) + { + value_type mean = delta * sqrt(v / 2) * tgamma_delta_ratio((v - 1) * 0.5f, T(0.5f)); + value_type var = ((delta * delta + 1) * v) / (v - 2) - mean * mean; + if(p < q) + guess = quantile(normal_distribution<value_type, forwarding_policy>(mean, var), p); + else + guess = quantile(complement(normal_distribution<value_type, forwarding_policy>(mean, var), q)); + } + // + // We *must* get the sign of the initial guess correct, + // or our root-finder will fail, so double check it now: + // + value_type pzero = non_central_t_cdf( + static_cast<value_type>(v), + static_cast<value_type>(delta), + static_cast<value_type>(0), + !(p < q), + forwarding_policy()); + int s; + if(p < q) + s = boost::math::sign(p - pzero); + else + s = boost::math::sign(pzero - q); + if(s != boost::math::sign(guess)) + { + guess = s; + } + + value_type result = detail::generic_quantile( + non_central_t_distribution<value_type, forwarding_policy>(v, delta), + (p < q ? p : q), + guess, + (p >= q), + function); + return policies::checked_narrowing_cast<T, forwarding_policy>( + result, + function); + } + + template <class T, class Policy> + T non_central_t2_pdf(T n, T delta, T x, T y, const Policy& pol, T init_val) + { + BOOST_MATH_STD_USING + // + // Variables come first: + // + boost::uintmax_t max_iter = policies::get_max_series_iterations<Policy>(); + T errtol = boost::math::policies::get_epsilon<T, Policy>(); + T d2 = delta * delta / 2; + // + // k is the starting point for iteration, and is the + // maximum of the poisson weighting term: + // + int k = boost::math::itrunc(d2); + // Starting Poisson weight: + T pois = gamma_p_derivative(T(k+1), d2, pol) + * tgamma_delta_ratio(T(k + 1), T(0.5f)) + * delta / constants::root_two<T>(); + // Starting beta term: + T xterm = x < y + ? ibeta_derivative(T(k + 1), n / 2, x, pol) + : ibeta_derivative(n / 2, T(k + 1), y, pol); + T poisf(pois), xtermf(xterm); + T sum = init_val; + if((pois == 0) || (xterm == 0)) + return init_val; + + // + // Backwards recursion first, this is the stable + // direction for recursion: + // + boost::uintmax_t count = 0; + for(int i = k; i >= 0; --i) + { + T term = xterm * pois; + sum += term; + if((fabs(term/sum) < errtol) || (term == 0)) + break; + pois *= (i + 0.5f) / d2; + xterm *= (i) / (x * (n / 2 + i)); + ++count; + if(count > max_iter) + { + return policies::raise_evaluation_error( + "pdf(non_central_t_distribution<%1%>, %1%)", + "Series did not converge, closest value was %1%", sum, pol); + } + } + for(int i = k + 1; ; ++i) + { + poisf *= d2 / (i + 0.5f); + xtermf *= (x * (n / 2 + i)) / (i); + T term = poisf * xtermf; + sum += term; + if((fabs(term/sum) < errtol) || (term == 0)) + break; + ++count; + if(count > max_iter) + { + return policies::raise_evaluation_error( + "pdf(non_central_t_distribution<%1%>, %1%)", + "Series did not converge, closest value was %1%", sum, pol); + } + } + return sum; + } + + template <class T, class Policy> + T non_central_t_pdf(T n, T delta, T t, const Policy& pol) + { + BOOST_MATH_STD_USING + // + // For t < 0 we have to use the reflection formula: + // + if(t < 0) + { + t = -t; + delta = -delta; + } + if(t == 0) + { + // + // Handle this as a special case, using the formula + // from Weisstein, Eric W. + // "Noncentral Student's t-Distribution." + // From MathWorld--A Wolfram Web Resource. + // http://mathworld.wolfram.com/NoncentralStudentst-Distribution.html + // + // The formula is simplified thanks to the relation + // 1F1(a,b,0) = 1. + // + return tgamma_delta_ratio(n / 2 + 0.5f, T(0.5f)) + * sqrt(n / constants::pi<T>()) + * exp(-delta * delta / 2) / 2; + } + // + // x and y are the corresponding random + // variables for the noncentral beta distribution, + // with y = 1 - x: + // + T x = t * t / (n + t * t); + T y = n / (n + t * t); + T a = 0.5f; + T b = n / 2; + T d2 = delta * delta; + // + // Calculate pdf: + // + T dt = n * t / (n * n + 2 * n * t * t + t * t * t * t); + T result = non_central_beta_pdf(a, b, d2, x, y, pol); + T tol = tools::epsilon<T>() * result * 500; + result = non_central_t2_pdf(n, delta, x, y, pol, result); + if(result <= tol) + result = 0; + result *= dt; + return result; + } + + template <class T, class Policy> + T mean(T v, T delta, const Policy& pol) + { + BOOST_MATH_STD_USING + return delta * sqrt(v / 2) * tgamma_delta_ratio((v - 1) * 0.5f, T(0.5f), pol); + } + + template <class T, class Policy> + T variance(T v, T delta, const Policy& pol) + { + T result = ((delta * delta + 1) * v) / (v - 2); + T m = mean(v, delta, pol); + result -= m * m; + return result; + } + + template <class T, class Policy> + T skewness(T v, T delta, const Policy& pol) + { + BOOST_MATH_STD_USING + T mean = boost::math::detail::mean(v, delta, pol); + T l2 = delta * delta; + T var = ((l2 + 1) * v) / (v - 2) - mean * mean; + T result = -2 * var; + result += v * (l2 + 2 * v - 3) / ((v - 3) * (v - 2)); + result *= mean; + result /= pow(var, T(1.5f)); + return result; + } + + template <class T, class Policy> + T kurtosis_excess(T v, T delta, const Policy& pol) + { + BOOST_MATH_STD_USING + T mean = boost::math::detail::mean(v, delta, pol); + T l2 = delta * delta; + T var = ((l2 + 1) * v) / (v - 2) - mean * mean; + T result = -3 * var; + result += v * (l2 * (v + 1) + 3 * (3 * v - 5)) / ((v - 3) * (v - 2)); + result *= -mean * mean; + result += v * v * (l2 * l2 + 6 * l2 + 3) / ((v - 4) * (v - 2)); + result /= var * var; + return result; + } + +#if 0 + // + // This code is disabled, since there can be multiple answers to the + // question, and it's not clear how to find the "right" one. + // + template <class RealType, class Policy> + struct t_degrees_of_freedom_finder + { + t_degrees_of_freedom_finder( + RealType delta_, RealType x_, RealType p_, bool c) + : delta(delta_), x(x_), p(p_), comp(c) {} + + RealType operator()(const RealType& v) + { + non_central_t_distribution<RealType, Policy> d(v, delta); + return comp ? + p - cdf(complement(d, x)) + : cdf(d, x) - p; + } + private: + RealType delta; + RealType x; + RealType p; + bool comp; + }; + + template <class RealType, class Policy> + inline RealType find_t_degrees_of_freedom( + RealType delta, RealType x, RealType p, RealType q, const Policy& pol) + { + const char* function = "non_central_t<%1%>::find_degrees_of_freedom"; + if((p == 0) || (q == 0)) + { + // + // Can't a thing if one of p and q is zero: + // + return policies::raise_evaluation_error<RealType>(function, + "Can't find degrees of freedom when the probability is 0 or 1, only possible answer is %1%", + RealType(std::numeric_limits<RealType>::quiet_NaN()), Policy()); + } + t_degrees_of_freedom_finder<RealType, Policy> f(delta, x, p < q ? p : q, p < q ? false : true); + tools::eps_tolerance<RealType> tol(policies::digits<RealType, Policy>()); + boost::uintmax_t max_iter = policies::get_max_root_iterations<Policy>(); + // + // Pick an initial guess: + // + RealType guess = 200; + std::pair<RealType, RealType> ir = tools::bracket_and_solve_root( + f, guess, RealType(2), false, tol, max_iter, pol); + RealType result = ir.first + (ir.second - ir.first) / 2; + if(max_iter >= policies::get_max_root_iterations<Policy>()) + { + policies::raise_evaluation_error<RealType>(function, "Unable to locate solution in a reasonable time:" + " or there is no answer to problem. Current best guess is %1%", result, Policy()); + } + return result; + } + + template <class RealType, class Policy> + struct t_non_centrality_finder + { + t_non_centrality_finder( + RealType v_, RealType x_, RealType p_, bool c) + : v(v_), x(x_), p(p_), comp(c) {} + + RealType operator()(const RealType& delta) + { + non_central_t_distribution<RealType, Policy> d(v, delta); + return comp ? + p - cdf(complement(d, x)) + : cdf(d, x) - p; + } + private: + RealType v; + RealType x; + RealType p; + bool comp; + }; + + template <class RealType, class Policy> + inline RealType find_t_non_centrality( + RealType v, RealType x, RealType p, RealType q, const Policy& pol) + { + const char* function = "non_central_t<%1%>::find_t_non_centrality"; + if((p == 0) || (q == 0)) + { + // + // Can't do a thing if one of p and q is zero: + // + return policies::raise_evaluation_error<RealType>(function, + "Can't find non centrality parameter when the probability is 0 or 1, only possible answer is %1%", + RealType(std::numeric_limits<RealType>::quiet_NaN()), Policy()); + } + t_non_centrality_finder<RealType, Policy> f(v, x, p < q ? p : q, p < q ? false : true); + tools::eps_tolerance<RealType> tol(policies::digits<RealType, Policy>()); + boost::uintmax_t max_iter = policies::get_max_root_iterations<Policy>(); + // + // Pick an initial guess that we know is the right side of + // zero: + // + RealType guess; + if(f(0) < 0) + guess = 1; + else + guess = -1; + std::pair<RealType, RealType> ir = tools::bracket_and_solve_root( + f, guess, RealType(2), false, tol, max_iter, pol); + RealType result = ir.first + (ir.second - ir.first) / 2; + if(max_iter >= policies::get_max_root_iterations<Policy>()) + { + policies::raise_evaluation_error<RealType>(function, "Unable to locate solution in a reasonable time:" + " or there is no answer to problem. Current best guess is %1%", result, Policy()); + } + return result; + } +#endif + } // namespace detail + + template <class RealType = double, class Policy = policies::policy<> > + class non_central_t_distribution + { + public: + typedef RealType value_type; + typedef Policy policy_type; + + non_central_t_distribution(RealType v_, RealType lambda) : v(v_), ncp(lambda) + { + const char* function = "boost::math::non_central_t_distribution<%1%>::non_central_t_distribution(%1%,%1%)"; + RealType r; + detail::check_df( + function, + v, &r, Policy()); + detail::check_finite( + function, + lambda, + &r, + Policy()); + } // non_central_t_distribution constructor. + + RealType degrees_of_freedom() const + { // Private data getter function. + return v; + } + RealType non_centrality() const + { // Private data getter function. + return ncp; + } +#if 0 + // + // This code is disabled, since there can be multiple answers to the + // question, and it's not clear how to find the "right" one. + // + static RealType find_degrees_of_freedom(RealType delta, RealType x, RealType p) + { + const char* function = "non_central_t<%1%>::find_degrees_of_freedom"; + typedef typename policies::evaluation<RealType, Policy>::type value_type; + typedef typename policies::normalise< + Policy, + policies::promote_float<false>, + policies::promote_double<false>, + policies::discrete_quantile<>, + policies::assert_undefined<> >::type forwarding_policy; + value_type result = detail::find_t_degrees_of_freedom( + static_cast<value_type>(delta), + static_cast<value_type>(x), + static_cast<value_type>(p), + static_cast<value_type>(1-p), + forwarding_policy()); + return policies::checked_narrowing_cast<RealType, forwarding_policy>( + result, + function); + } + template <class A, class B, class C> + static RealType find_degrees_of_freedom(const complemented3_type<A,B,C>& c) + { + const char* function = "non_central_t<%1%>::find_degrees_of_freedom"; + typedef typename policies::evaluation<RealType, Policy>::type value_type; + typedef typename policies::normalise< + Policy, + policies::promote_float<false>, + policies::promote_double<false>, + policies::discrete_quantile<>, + policies::assert_undefined<> >::type forwarding_policy; + value_type result = detail::find_t_degrees_of_freedom( + static_cast<value_type>(c.dist), + static_cast<value_type>(c.param1), + static_cast<value_type>(1-c.param2), + static_cast<value_type>(c.param2), + forwarding_policy()); + return policies::checked_narrowing_cast<RealType, forwarding_policy>( + result, + function); + } + static RealType find_non_centrality(RealType v, RealType x, RealType p) + { + const char* function = "non_central_t<%1%>::find_t_non_centrality"; + typedef typename policies::evaluation<RealType, Policy>::type value_type; + typedef typename policies::normalise< + Policy, + policies::promote_float<false>, + policies::promote_double<false>, + policies::discrete_quantile<>, + policies::assert_undefined<> >::type forwarding_policy; + value_type result = detail::find_t_non_centrality( + static_cast<value_type>(v), + static_cast<value_type>(x), + static_cast<value_type>(p), + static_cast<value_type>(1-p), + forwarding_policy()); + return policies::checked_narrowing_cast<RealType, forwarding_policy>( + result, + function); + } + template <class A, class B, class C> + static RealType find_non_centrality(const complemented3_type<A,B,C>& c) + { + const char* function = "non_central_t<%1%>::find_t_non_centrality"; + typedef typename policies::evaluation<RealType, Policy>::type value_type; + typedef typename policies::normalise< + Policy, + policies::promote_float<false>, + policies::promote_double<false>, + policies::discrete_quantile<>, + policies::assert_undefined<> >::type forwarding_policy; + value_type result = detail::find_t_non_centrality( + static_cast<value_type>(c.dist), + static_cast<value_type>(c.param1), + static_cast<value_type>(1-c.param2), + static_cast<value_type>(c.param2), + forwarding_policy()); + return policies::checked_narrowing_cast<RealType, forwarding_policy>( + result, + function); + } +#endif + private: + // Data member, initialized by constructor. + RealType v; // degrees of freedom + RealType ncp; // non-centrality parameter + }; // template <class RealType, class Policy> class non_central_t_distribution + + typedef non_central_t_distribution<double> non_central_t; // Reserved name of type double. + + // Non-member functions to give properties of the distribution. + + template <class RealType, class Policy> + inline const std::pair<RealType, RealType> range(const non_central_t_distribution<RealType, Policy>& /* dist */) + { // Range of permissible values for random variable k. + using boost::math::tools::max_value; + return std::pair<RealType, RealType>(-max_value<RealType>(), max_value<RealType>()); + } + + template <class RealType, class Policy> + inline const std::pair<RealType, RealType> support(const non_central_t_distribution<RealType, Policy>& /* dist */) + { // Range of supported values for random variable k. + // This is range where cdf rises from 0 to 1, and outside it, the pdf is zero. + using boost::math::tools::max_value; + return std::pair<RealType, RealType>(-max_value<RealType>(), max_value<RealType>()); + } + + template <class RealType, class Policy> + inline RealType mode(const non_central_t_distribution<RealType, Policy>& dist) + { // mode. + static const char* function = "mode(non_central_t_distribution<%1%> const&)"; + RealType v = dist.degrees_of_freedom(); + RealType l = dist.non_centrality(); + RealType r; + if(!detail::check_df( + function, + v, &r, Policy()) + || + !detail::check_finite( + function, + l, + &r, + Policy())) + return (RealType)r; + + BOOST_MATH_STD_USING + + RealType m = v < 3 ? 0 : detail::mean(v, l, Policy()); + RealType var = v < 4 ? 1 : detail::variance(v, l, Policy()); + + return detail::generic_find_mode( + dist, + m, + function, + sqrt(var)); + } + + template <class RealType, class Policy> + inline RealType mean(const non_central_t_distribution<RealType, Policy>& dist) + { + BOOST_MATH_STD_USING + const char* function = "mean(const non_central_t_distribution<%1%>&)"; + typedef typename policies::evaluation<RealType, Policy>::type value_type; + typedef typename policies::normalise< + Policy, + policies::promote_float<false>, + policies::promote_double<false>, + policies::discrete_quantile<>, + policies::assert_undefined<> >::type forwarding_policy; + RealType v = dist.degrees_of_freedom(); + RealType l = dist.non_centrality(); + RealType r; + if(!detail::check_df( + function, + v, &r, Policy()) + || + !detail::check_finite( + function, + l, + &r, + Policy())) + return (RealType)r; + if(v <= 1) + return policies::raise_domain_error<RealType>( + function, + "The non central t distribution has no defined mean for degrees of freedom <= 1: got v=%1%.", v, Policy()); + // return l * sqrt(v / 2) * tgamma_delta_ratio((v - 1) * 0.5f, RealType(0.5f)); + return policies::checked_narrowing_cast<RealType, forwarding_policy>( + detail::mean(static_cast<value_type>(v), static_cast<value_type>(l), forwarding_policy()), function); + + } // mean + + template <class RealType, class Policy> + inline RealType variance(const non_central_t_distribution<RealType, Policy>& dist) + { // variance. + const char* function = "variance(const non_central_t_distribution<%1%>&)"; + typedef typename policies::evaluation<RealType, Policy>::type value_type; + typedef typename policies::normalise< + Policy, + policies::promote_float<false>, + policies::promote_double<false>, + policies::discrete_quantile<>, + policies::assert_undefined<> >::type forwarding_policy; + BOOST_MATH_STD_USING + RealType v = dist.degrees_of_freedom(); + RealType l = dist.non_centrality(); + RealType r; + if(!detail::check_df( + function, + v, &r, Policy()) + || + !detail::check_finite( + function, + l, + &r, + Policy())) + return (RealType)r; + if(v <= 2) + return policies::raise_domain_error<RealType>( + function, + "The non central t distribution has no defined variance for degrees of freedom <= 2: got v=%1%.", v, Policy()); + return policies::checked_narrowing_cast<RealType, forwarding_policy>( + detail::variance(static_cast<value_type>(v), static_cast<value_type>(l), forwarding_policy()), function); + } + + // RealType standard_deviation(const non_central_t_distribution<RealType, Policy>& dist) + // standard_deviation provided by derived accessors. + + template <class RealType, class Policy> + inline RealType skewness(const non_central_t_distribution<RealType, Policy>& dist) + { // skewness = sqrt(l). + const char* function = "skewness(const non_central_t_distribution<%1%>&)"; + typedef typename policies::evaluation<RealType, Policy>::type value_type; + typedef typename policies::normalise< + Policy, + policies::promote_float<false>, + policies::promote_double<false>, + policies::discrete_quantile<>, + policies::assert_undefined<> >::type forwarding_policy; + RealType v = dist.degrees_of_freedom(); + RealType l = dist.non_centrality(); + RealType r; + if(!detail::check_df( + function, + v, &r, Policy()) + || + !detail::check_finite( + function, + l, + &r, + Policy())) + return (RealType)r; + if(v <= 3) + return policies::raise_domain_error<RealType>( + function, + "The non central t distribution has no defined skewness for degrees of freedom <= 3: got v=%1%.", v, Policy());; + return policies::checked_narrowing_cast<RealType, forwarding_policy>( + detail::skewness(static_cast<value_type>(v), static_cast<value_type>(l), forwarding_policy()), function); + } + + template <class RealType, class Policy> + inline RealType kurtosis_excess(const non_central_t_distribution<RealType, Policy>& dist) + { + const char* function = "kurtosis_excess(const non_central_t_distribution<%1%>&)"; + typedef typename policies::evaluation<RealType, Policy>::type value_type; + typedef typename policies::normalise< + Policy, + policies::promote_float<false>, + policies::promote_double<false>, + policies::discrete_quantile<>, + policies::assert_undefined<> >::type forwarding_policy; + RealType v = dist.degrees_of_freedom(); + RealType l = dist.non_centrality(); + RealType r; + if(!detail::check_df( + function, + v, &r, Policy()) + || + !detail::check_finite( + function, + l, + &r, + Policy())) + return (RealType)r; + if(v <= 4) + return policies::raise_domain_error<RealType>( + function, + "The non central t distribution has no defined kurtosis for degrees of freedom <= 4: got v=%1%.", v, Policy());; + return policies::checked_narrowing_cast<RealType, forwarding_policy>( + detail::kurtosis_excess(static_cast<value_type>(v), static_cast<value_type>(l), forwarding_policy()), function); + } // kurtosis_excess + + template <class RealType, class Policy> + inline RealType kurtosis(const non_central_t_distribution<RealType, Policy>& dist) + { + return kurtosis_excess(dist) + 3; + } + + template <class RealType, class Policy> + inline RealType pdf(const non_central_t_distribution<RealType, Policy>& dist, const RealType& t) + { // Probability Density/Mass Function. + const char* function = "cdf(non_central_t_distribution<%1%>, %1%)"; + typedef typename policies::evaluation<RealType, Policy>::type value_type; + typedef typename policies::normalise< + Policy, + policies::promote_float<false>, + policies::promote_double<false>, + policies::discrete_quantile<>, + policies::assert_undefined<> >::type forwarding_policy; + + RealType v = dist.degrees_of_freedom(); + RealType l = dist.non_centrality(); + RealType r; + if(!detail::check_df( + function, + v, &r, Policy()) + || + !detail::check_finite( + function, + l, + &r, + Policy()) + || + !detail::check_x( + function, + t, + &r, + Policy())) + return (RealType)r; + return policies::checked_narrowing_cast<RealType, forwarding_policy>( + detail::non_central_t_pdf(static_cast<value_type>(v), + static_cast<value_type>(l), + static_cast<value_type>(t), + Policy()), + function); + } // pdf + + template <class RealType, class Policy> + RealType cdf(const non_central_t_distribution<RealType, Policy>& dist, const RealType& x) + { + const char* function = "boost::math::non_central_t_distribution<%1%>::cdf(%1%)"; + typedef typename policies::evaluation<RealType, Policy>::type value_type; + typedef typename policies::normalise< + Policy, + policies::promote_float<false>, + policies::promote_double<false>, + policies::discrete_quantile<>, + policies::assert_undefined<> >::type forwarding_policy; + + RealType v = dist.degrees_of_freedom(); + RealType l = dist.non_centrality(); + RealType r; + if(!detail::check_df( + function, + v, &r, Policy()) + || + !detail::check_finite( + function, + l, + &r, + Policy()) + || + !detail::check_x( + function, + x, + &r, + Policy())) + return (RealType)r; + + if(l == 0) + return cdf(students_t_distribution<RealType, Policy>(v), x); + + return policies::checked_narrowing_cast<RealType, forwarding_policy>( + detail::non_central_t_cdf( + static_cast<value_type>(v), + static_cast<value_type>(l), + static_cast<value_type>(x), + false, Policy()), + function); + } // cdf + + template <class RealType, class Policy> + RealType cdf(const complemented2_type<non_central_t_distribution<RealType, Policy>, RealType>& c) + { // Complemented Cumulative Distribution Function + const char* function = "boost::math::non_central_t_distribution<%1%>::cdf(%1%)"; + typedef typename policies::evaluation<RealType, Policy>::type value_type; + typedef typename policies::normalise< + Policy, + policies::promote_float<false>, + policies::promote_double<false>, + policies::discrete_quantile<>, + policies::assert_undefined<> >::type forwarding_policy; + + non_central_t_distribution<RealType, Policy> const& dist = c.dist; + RealType x = c.param; + RealType v = dist.degrees_of_freedom(); + RealType l = dist.non_centrality(); + RealType r; + if(!detail::check_df( + function, + v, &r, Policy()) + || + !detail::check_finite( + function, + l, + &r, + Policy()) + || + !detail::check_x( + function, + x, + &r, + Policy())) + return (RealType)r; + + if(l == 0) + return cdf(complement(students_t_distribution<RealType, Policy>(v), x)); + + return policies::checked_narrowing_cast<RealType, forwarding_policy>( + detail::non_central_t_cdf( + static_cast<value_type>(v), + static_cast<value_type>(l), + static_cast<value_type>(x), + true, Policy()), + function); + } // ccdf + + template <class RealType, class Policy> + inline RealType quantile(const non_central_t_distribution<RealType, Policy>& dist, const RealType& p) + { // Quantile (or Percent Point) function. + RealType v = dist.degrees_of_freedom(); + RealType l = dist.non_centrality(); + return detail::non_central_t_quantile(v, l, p, RealType(1-p), Policy()); + } // quantile + + template <class RealType, class Policy> + inline RealType quantile(const complemented2_type<non_central_t_distribution<RealType, Policy>, RealType>& c) + { // Quantile (or Percent Point) function. + non_central_t_distribution<RealType, Policy> const& dist = c.dist; + RealType q = c.param; + RealType v = dist.degrees_of_freedom(); + RealType l = dist.non_centrality(); + return detail::non_central_t_quantile(v, l, RealType(1-q), q, Policy()); + } // quantile complement. + + } // namespace math +} // namespace boost + +// This include must be at the end, *after* the accessors +// for this distribution have been defined, in order to +// keep compilers that support two-phase lookup happy. +#include <boost/math/distributions/detail/derived_accessors.hpp> + +#endif // BOOST_MATH_SPECIAL_NON_CENTRAL_T_HPP + diff --git a/Utilities/BGL/boost/math/distributions/normal.hpp b/Utilities/BGL/boost/math/distributions/normal.hpp new file mode 100644 index 0000000000000000000000000000000000000000..e41594c20fb5393c378cdb2a0b002b1a39fe682f --- /dev/null +++ b/Utilities/BGL/boost/math/distributions/normal.hpp @@ -0,0 +1,308 @@ +// Copyright John Maddock 2006, 2007. +// Copyright Paul A. Bristow 2006, 2007. + +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_STATS_NORMAL_HPP +#define BOOST_STATS_NORMAL_HPP + +// http://en.wikipedia.org/wiki/Normal_distribution +// http://www.itl.nist.gov/div898/handbook/eda/section3/eda3661.htm +// Also: +// Weisstein, Eric W. "Normal Distribution." +// From MathWorld--A Wolfram Web Resource. +// http://mathworld.wolfram.com/NormalDistribution.html + +#include <boost/math/distributions/fwd.hpp> +#include <boost/math/special_functions/erf.hpp> // for erf/erfc. +#include <boost/math/distributions/complement.hpp> +#include <boost/math/distributions/detail/common_error_handling.hpp> + +#include <utility> + +namespace boost{ namespace math{ + +template <class RealType = double, class Policy = policies::policy<> > +class normal_distribution +{ +public: + typedef RealType value_type; + typedef Policy policy_type; + + normal_distribution(RealType mean = 0, RealType sd = 1) + : m_mean(mean), m_sd(sd) + { // Default is a 'standard' normal distribution N01. + static const char* function = "boost::math::normal_distribution<%1%>::normal_distribution"; + + RealType result; + detail::check_scale(function, sd, &result, Policy()); + detail::check_location(function, mean, &result, Policy()); + } + + RealType mean()const + { // alias for location. + return m_mean; + } + + RealType standard_deviation()const + { // alias for scale. + return m_sd; + } + + // Synonyms, provided to allow generic use of find_location and find_scale. + RealType location()const + { // location. + return m_mean; + } + RealType scale()const + { // scale. + return m_sd; + } + +private: + // + // Data members: + // + RealType m_mean; // distribution mean or location. + RealType m_sd; // distribution standard deviation or scale. +}; // class normal_distribution + +typedef normal_distribution<double> normal; + +template <class RealType, class Policy> +inline const std::pair<RealType, RealType> range(const normal_distribution<RealType, Policy>& /*dist*/) +{ // Range of permissible values for random variable x. + using boost::math::tools::max_value; + return std::pair<RealType, RealType>(-max_value<RealType>(), max_value<RealType>()); // - to + max value. +} + +template <class RealType, class Policy> +inline const std::pair<RealType, RealType> support(const normal_distribution<RealType, Policy>& /*dist*/) +{ // Range of supported values for random variable x. + // This is range where cdf rises from 0 to 1, and outside it, the pdf is zero. + + using boost::math::tools::max_value; + return std::pair<RealType, RealType>(-max_value<RealType>(), max_value<RealType>()); // - to + max value. +} + +template <class RealType, class Policy> +inline RealType pdf(const normal_distribution<RealType, Policy>& dist, const RealType& x) +{ + BOOST_MATH_STD_USING // for ADL of std functions + + RealType sd = dist.standard_deviation(); + RealType mean = dist.mean(); + + static const char* function = "boost::math::pdf(const normal_distribution<%1%>&, %1%)"; + if((boost::math::isinf)(x)) + { + return 0; // pdf + and - infinity is zero. + } + // Below produces MSVC 4127 warnings, so the above used instead. + //if(std::numeric_limits<RealType>::has_infinity && abs(x) == std::numeric_limits<RealType>::infinity()) + //{ // pdf + and - infinity is zero. + // return 0; + //} + + RealType result; + if(false == detail::check_scale(function, sd, &result, Policy())) + { + return result; + } + if(false == detail::check_location(function, mean, &result, Policy())) + { + return result; + } + if(false == detail::check_x(function, x, &result, Policy())) + { + return result; + } + + RealType exponent = x - mean; + exponent *= -exponent; + exponent /= 2 * sd * sd; + + result = exp(exponent); + result /= sd * sqrt(2 * constants::pi<RealType>()); + + return result; +} // pdf + +template <class RealType, class Policy> +inline RealType cdf(const normal_distribution<RealType, Policy>& dist, const RealType& x) +{ + BOOST_MATH_STD_USING // for ADL of std functions + + RealType sd = dist.standard_deviation(); + RealType mean = dist.mean(); + static const char* function = "boost::math::cdf(const normal_distribution<%1%>&, %1%)"; + RealType result; + if(false == detail::check_scale(function, sd, &result, Policy())) + { + return result; + } + if(false == detail::check_location(function, mean, &result, Policy())) + { + return result; + } + if((boost::math::isinf)(x)) + { + if(x < 0) return 0; // -infinity + return 1; // + infinity + } + // These produce MSVC 4127 warnings, so the above used instead. + //if(std::numeric_limits<RealType>::has_infinity && x == std::numeric_limits<RealType>::infinity()) + //{ // cdf +infinity is unity. + // return 1; + //} + //if(std::numeric_limits<RealType>::has_infinity && x == -std::numeric_limits<RealType>::infinity()) + //{ // cdf -infinity is zero. + // return 0; + //} + if(false == detail::check_x(function, x, &result, Policy())) + { + return result; + } + RealType diff = (x - mean) / (sd * constants::root_two<RealType>()); + result = boost::math::erfc(-diff, Policy()) / 2; + return result; +} // cdf + +template <class RealType, class Policy> +inline RealType quantile(const normal_distribution<RealType, Policy>& dist, const RealType& p) +{ + BOOST_MATH_STD_USING // for ADL of std functions + + RealType sd = dist.standard_deviation(); + RealType mean = dist.mean(); + static const char* function = "boost::math::quantile(const normal_distribution<%1%>&, %1%)"; + + RealType result; + if(false == detail::check_scale(function, sd, &result, Policy())) + return result; + if(false == detail::check_location(function, mean, &result, Policy())) + return result; + if(false == detail::check_probability(function, p, &result, Policy())) + return result; + + result= boost::math::erfc_inv(2 * p, Policy()); + result = -result; + result *= sd * constants::root_two<RealType>(); + result += mean; + return result; +} // quantile + +template <class RealType, class Policy> +inline RealType cdf(const complemented2_type<normal_distribution<RealType, Policy>, RealType>& c) +{ + BOOST_MATH_STD_USING // for ADL of std functions + + RealType sd = c.dist.standard_deviation(); + RealType mean = c.dist.mean(); + RealType x = c.param; + static const char* function = "boost::math::cdf(const complement(normal_distribution<%1%>&), %1%)"; + + if((boost::math::isinf)(x)) + { + if(x < 0) return 1; // cdf complement -infinity is unity. + return 0; // cdf complement +infinity is zero + } + // These produce MSVC 4127 warnings, so the above used instead. + //if(std::numeric_limits<RealType>::has_infinity && x == std::numeric_limits<RealType>::infinity()) + //{ // cdf complement +infinity is zero. + // return 0; + //} + //if(std::numeric_limits<RealType>::has_infinity && x == -std::numeric_limits<RealType>::infinity()) + //{ // cdf complement -infinity is unity. + // return 1; + //} + RealType result; + if(false == detail::check_scale(function, sd, &result, Policy())) + return result; + if(false == detail::check_location(function, mean, &result, Policy())) + return result; + if(false == detail::check_x(function, x, &result, Policy())) + return result; + + RealType diff = (x - mean) / (sd * constants::root_two<RealType>()); + result = boost::math::erfc(diff, Policy()) / 2; + return result; +} // cdf complement + +template <class RealType, class Policy> +inline RealType quantile(const complemented2_type<normal_distribution<RealType, Policy>, RealType>& c) +{ + BOOST_MATH_STD_USING // for ADL of std functions + + RealType sd = c.dist.standard_deviation(); + RealType mean = c.dist.mean(); + static const char* function = "boost::math::quantile(const complement(normal_distribution<%1%>&), %1%)"; + RealType result; + if(false == detail::check_scale(function, sd, &result, Policy())) + return result; + if(false == detail::check_location(function, mean, &result, Policy())) + return result; + RealType q = c.param; + if(false == detail::check_probability(function, q, &result, Policy())) + return result; + result = boost::math::erfc_inv(2 * q, Policy()); + result *= sd * constants::root_two<RealType>(); + result += mean; + return result; +} // quantile + +template <class RealType, class Policy> +inline RealType mean(const normal_distribution<RealType, Policy>& dist) +{ + return dist.mean(); +} + +template <class RealType, class Policy> +inline RealType standard_deviation(const normal_distribution<RealType, Policy>& dist) +{ + return dist.standard_deviation(); +} + +template <class RealType, class Policy> +inline RealType mode(const normal_distribution<RealType, Policy>& dist) +{ + return dist.mean(); +} + +template <class RealType, class Policy> +inline RealType median(const normal_distribution<RealType, Policy>& dist) +{ + return dist.mean(); +} + +template <class RealType, class Policy> +inline RealType skewness(const normal_distribution<RealType, Policy>& /*dist*/) +{ + return 0; +} + +template <class RealType, class Policy> +inline RealType kurtosis(const normal_distribution<RealType, Policy>& /*dist*/) +{ + return 3; +} + +template <class RealType, class Policy> +inline RealType kurtosis_excess(const normal_distribution<RealType, Policy>& /*dist*/) +{ + return 0; +} + +} // namespace math +} // namespace boost + +// This include must be at the end, *after* the accessors +// for this distribution have been defined, in order to +// keep compilers that support two-phase lookup happy. +#include <boost/math/distributions/detail/derived_accessors.hpp> + +#endif // BOOST_STATS_NORMAL_HPP + + diff --git a/Utilities/BGL/boost/math/distributions/pareto.hpp b/Utilities/BGL/boost/math/distributions/pareto.hpp new file mode 100644 index 0000000000000000000000000000000000000000..5ef0fe3f2b79aaded2e4bdd4c4f962b416ca3d0c --- /dev/null +++ b/Utilities/BGL/boost/math/distributions/pareto.hpp @@ -0,0 +1,444 @@ +// Copyright John Maddock 2007. +// Copyright Paul A. Bristow 2007, 2009 +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_STATS_PARETO_HPP +#define BOOST_STATS_PARETO_HPP + +// http://en.wikipedia.org/wiki/Pareto_distribution +// http://www.itl.nist.gov/div898/handbook/eda/section3/eda3661.htm +// Also: +// Weisstein, Eric W. "Pareto Distribution." +// From MathWorld--A Wolfram Web Resource. +// http://mathworld.wolfram.com/ParetoDistribution.html +// Handbook of Statistical Distributions with Applications, K Krishnamoorthy, ISBN 1-58488-635-8, Chapter 23, pp 257 - 267. +// Caution KK's a and b are the reverse of Mathworld! + +#include <boost/math/distributions/fwd.hpp> +#include <boost/math/distributions/complement.hpp> +#include <boost/math/distributions/detail/common_error_handling.hpp> +#include <boost/math/special_functions/powm1.hpp> + +#include <utility> // for BOOST_CURRENT_VALUE? + +namespace boost +{ + namespace math + { + namespace detail + { // Parameter checking. + template <class RealType, class Policy> + inline bool check_pareto_scale( + const char* function, + RealType scale, + RealType* result, const Policy& pol) + { + if((boost::math::isfinite)(scale)) + { // any > 0 finite value is OK. + if (scale > 0) + { + return true; + } + else + { + *result = policies::raise_domain_error<RealType>( + function, + "Scale parameter is %1%, but must be > 0!", scale, pol); + return false; + } + } + else + { // Not finite. + *result = policies::raise_domain_error<RealType>( + function, + "Scale parameter is %1%, but must be finite!", scale, pol); + return false; + } + } // bool check_pareto_scale + + template <class RealType, class Policy> + inline bool check_pareto_shape( + const char* function, + RealType shape, + RealType* result, const Policy& pol) + { + if((boost::math::isfinite)(shape)) + { // Any finite value > 0 is OK. + if (shape > 0) + { + return true; + } + else + { + *result = policies::raise_domain_error<RealType>( + function, + "Shape parameter is %1%, but must be > 0!", shape, pol); + return false; + } + } + else + { // Not finite. + *result = policies::raise_domain_error<RealType>( + function, + "Shape parameter is %1%, but must be finite!", shape, pol); + return false; + } + } // bool check_pareto_shape( + + template <class RealType, class Policy> + inline bool check_pareto_x( + const char* function, + RealType const& x, + RealType* result, const Policy& pol) + { + if((boost::math::isfinite)(x)) + { // + if (x > 0) + { + return true; + } + else + { + *result = policies::raise_domain_error<RealType>( + function, + "x parameter is %1%, but must be > 0 !", x, pol); + return false; + } + } + else + { // Not finite.. + *result = policies::raise_domain_error<RealType>( + function, + "x parameter is %1%, but must be finite!", x, pol); + return false; + } + } // bool check_pareto_x + + template <class RealType, class Policy> + inline bool check_pareto( // distribution parameters. + const char* function, + RealType scale, + RealType shape, + RealType* result, const Policy& pol) + { + return check_pareto_scale(function, scale, result, pol) + && check_pareto_shape(function, shape, result, pol); + } // bool check_pareto( + + } // namespace detail + + template <class RealType = double, class Policy = policies::policy<> > + class pareto_distribution + { + public: + typedef RealType value_type; + typedef Policy policy_type; + + pareto_distribution(RealType scale = 1, RealType shape = 1) + : m_scale(scale), m_shape(shape) + { // Constructor. + RealType result; + detail::check_pareto("boost::math::pareto_distribution<%1%>::pareto_distribution", scale, shape, &result, Policy()); + } + + RealType scale()const + { // AKA Xm and Wolfram b and beta + return m_scale; + } + + RealType shape()const + { // AKA k and Wolfram a and alpha + return m_shape; + } + private: + // Data members: + RealType m_scale; // distribution scale (xm) or beta + RealType m_shape; // distribution shape (k) or alpha + }; + + typedef pareto_distribution<double> pareto; // Convenience to allow pareto(2., 3.); + + template <class RealType, class Policy> + inline const std::pair<RealType, RealType> range(const pareto_distribution<RealType, Policy>& /*dist*/) + { // Range of permissible values for random variable x. + using boost::math::tools::max_value; + return std::pair<RealType, RealType>(0, max_value<RealType>()); // scale zero to + infinity. + } // range + + template <class RealType, class Policy> + inline const std::pair<RealType, RealType> support(const pareto_distribution<RealType, Policy>& dist) + { // Range of supported values for random variable x. + // This is range where cdf rises from 0 to 1, and outside it, the pdf is zero. + using boost::math::tools::max_value; + return std::pair<RealType, RealType>(dist.scale(), max_value<RealType>() ); // scale to + infinity. + } // support + + template <class RealType, class Policy> + inline RealType pdf(const pareto_distribution<RealType, Policy>& dist, const RealType& x) + { + BOOST_MATH_STD_USING // for ADL of std function pow. + static const char* function = "boost::math::pdf(const pareto_distribution<%1%>&, %1%)"; + RealType scale = dist.scale(); + RealType shape = dist.shape(); + RealType result; + if(false == (detail::check_pareto_x(function, x, &result, Policy()) + && detail::check_pareto(function, scale, shape, &result, Policy()))) + return result; + if (x < scale) + { // regardless of shape, pdf is zero (or should be disallow x < scale and throw an exception?). + return 0; + } + result = shape * pow(scale, shape) / pow(x, shape+1); + return result; + } // pdf + + template <class RealType, class Policy> + inline RealType cdf(const pareto_distribution<RealType, Policy>& dist, const RealType& x) + { + BOOST_MATH_STD_USING // for ADL of std function pow. + static const char* function = "boost::math::cdf(const pareto_distribution<%1%>&, %1%)"; + RealType scale = dist.scale(); + RealType shape = dist.shape(); + RealType result; + + if(false == (detail::check_pareto_x(function, x, &result, Policy()) + && detail::check_pareto(function, scale, shape, &result, Policy()))) + return result; + + if (x <= scale) + { // regardless of shape, cdf is zero. + return 0; + } + + // result = RealType(1) - pow((scale / x), shape); + result = -boost::math::powm1(scale/x, shape, Policy()); // should be more accurate. + return result; + } // cdf + + template <class RealType, class Policy> + inline RealType quantile(const pareto_distribution<RealType, Policy>& dist, const RealType& p) + { + BOOST_MATH_STD_USING // for ADL of std function pow. + static const char* function = "boost::math::quantile(const pareto_distribution<%1%>&, %1%)"; + RealType result; + RealType scale = dist.scale(); + RealType shape = dist.shape(); + if(false == (detail::check_probability(function, p, &result, Policy()) + && detail::check_pareto(function, scale, shape, &result, Policy()))) + { + return result; + } + if (p == 0) + { + return scale; // x must be scale (or less). + } + if (p == 1) + { + return tools::max_value<RealType>(); // x = + infinity. + } + result = scale / + (pow((1 - p), 1 / shape)); + // K. Krishnamoorthy, ISBN 1-58488-635-8 eq 23.1.3 + return result; + } // quantile + + template <class RealType, class Policy> + inline RealType cdf(const complemented2_type<pareto_distribution<RealType, Policy>, RealType>& c) + { + BOOST_MATH_STD_USING // for ADL of std function pow. + static const char* function = "boost::math::cdf(const pareto_distribution<%1%>&, %1%)"; + RealType result; + RealType x = c.param; + RealType scale = c.dist.scale(); + RealType shape = c.dist.shape(); + if(false == (detail::check_pareto_x(function, x, &result, Policy()) + && detail::check_pareto(function, scale, shape, &result, Policy()))) + return result; + + if (x <= scale) + { // regardless of shape, cdf is zero, and complement is unity. + return 1; + } + result = pow((scale/x), shape); + + return result; + } // cdf complement + + template <class RealType, class Policy> + inline RealType quantile(const complemented2_type<pareto_distribution<RealType, Policy>, RealType>& c) + { + BOOST_MATH_STD_USING // for ADL of std function pow. + static const char* function = "boost::math::quantile(const pareto_distribution<%1%>&, %1%)"; + RealType result; + RealType q = c.param; + RealType scale = c.dist.scale(); + RealType shape = c.dist.shape(); + if(false == (detail::check_probability(function, q, &result, Policy()) + && detail::check_pareto(function, scale, shape, &result, Policy()))) + { + return result; + } + if (q == 1) + { + return scale; // x must be scale (or less). + } + if (q == 0) + { + return tools::max_value<RealType>(); // x = + infinity. + } + result = scale / (pow(q, 1 / shape)); + // K. Krishnamoorthy, ISBN 1-58488-635-8 eq 23.1.3 + return result; + } // quantile complement + + template <class RealType, class Policy> + inline RealType mean(const pareto_distribution<RealType, Policy>& dist) + { + RealType result; + static const char* function = "boost::math::mean(const pareto_distribution<%1%>&, %1%)"; + if(false == detail::check_pareto(function, dist.scale(), dist.shape(), &result, Policy())) + { + return result; + } + if (dist.shape() > RealType(1)) + { + return dist.shape() * dist.scale() / (dist.shape() - 1); + } + else + { + using boost::math::tools::max_value; + return max_value<RealType>(); // +infinity. + } + } // mean + + template <class RealType, class Policy> + inline RealType mode(const pareto_distribution<RealType, Policy>& dist) + { + return dist.scale(); + } // mode + + template <class RealType, class Policy> + inline RealType median(const pareto_distribution<RealType, Policy>& dist) + { + RealType result; + static const char* function = "boost::math::median(const pareto_distribution<%1%>&, %1%)"; + if(false == detail::check_pareto(function, dist.scale(), dist.shape(), &result, Policy())) + { + return result; + } + BOOST_MATH_STD_USING + return dist.scale() * pow(RealType(2), (1/dist.shape())); + } // median + + template <class RealType, class Policy> + inline RealType variance(const pareto_distribution<RealType, Policy>& dist) + { + RealType result; + RealType scale = dist.scale(); + RealType shape = dist.shape(); + static const char* function = "boost::math::variance(const pareto_distribution<%1%>&, %1%)"; + if(false == detail::check_pareto(function, scale, shape, &result, Policy())) + { + return result; + } + if (shape > 2) + { + result = (scale * scale * shape) / + ((shape - 1) * (shape - 1) * (shape - 2)); + } + else + { + result = policies::raise_domain_error<RealType>( + function, + "variance is undefined for shape <= 2, but got %1%.", dist.shape(), Policy()); + } + return result; + } // variance + + template <class RealType, class Policy> + inline RealType skewness(const pareto_distribution<RealType, Policy>& dist) + { + BOOST_MATH_STD_USING + RealType result; + RealType shape = dist.shape(); + static const char* function = "boost::math::pdf(const pareto_distribution<%1%>&, %1%)"; + if(false == detail::check_pareto(function, dist.scale(), shape, &result, Policy())) + { + return result; + } + if (shape > 3) + { + result = sqrt((shape - 2) / shape) * + 2 * (shape + 1) / + (shape - 3); + } + else + { + result = policies::raise_domain_error<RealType>( + function, + "skewness is undefined for shape <= 3, but got %1%.", dist.shape(), Policy()); + } + return result; + } // skewness + + template <class RealType, class Policy> + inline RealType kurtosis(const pareto_distribution<RealType, Policy>& dist) + { + RealType result; + RealType shape = dist.shape(); + static const char* function = "boost::math::pdf(const pareto_distribution<%1%>&, %1%)"; + if(false == detail::check_pareto(function, dist.scale(), shape, &result, Policy())) + { + return result; + } + if (shape > 4) + { + result = 3 * ((shape - 2) * (3 * shape * shape + shape + 2)) / + (shape * (shape - 3) * (shape - 4)); + } + else + { + result = policies::raise_domain_error<RealType>( + function, + "kurtosis_excess is undefined for shape <= 4, but got %1%.", shape, Policy()); + } + return result; + } // kurtosis + + template <class RealType, class Policy> + inline RealType kurtosis_excess(const pareto_distribution<RealType, Policy>& dist) + { + RealType result; + RealType shape = dist.shape(); + static const char* function = "boost::math::pdf(const pareto_distribution<%1%>&, %1%)"; + if(false == detail::check_pareto(function, dist.scale(), shape, &result, Policy())) + { + return result; + } + if (shape > 4) + { + result = 6 * ((shape * shape * shape) + (shape * shape) - 6 * shape - 2) / + (shape * (shape - 3) * (shape - 4)); + } + else + { + result = policies::raise_domain_error<RealType>( + function, + "kurtosis_excess is undefined for shape <= 4, but got %1%.", dist.shape(), Policy()); + } + return result; + } // kurtosis_excess + + } // namespace math + } // namespace boost + + // This include must be at the end, *after* the accessors + // for this distribution have been defined, in order to + // keep compilers that support two-phase lookup happy. +#include <boost/math/distributions/detail/derived_accessors.hpp> + +#endif // BOOST_STATS_PARETO_HPP + + diff --git a/Utilities/BGL/boost/math/distributions/poisson.hpp b/Utilities/BGL/boost/math/distributions/poisson.hpp new file mode 100644 index 0000000000000000000000000000000000000000..d0b77ea348e6dc99f41cd2a671798c3ad7109272 --- /dev/null +++ b/Utilities/BGL/boost/math/distributions/poisson.hpp @@ -0,0 +1,588 @@ +// boost\math\distributions\poisson.hpp + +// Copyright John Maddock 2006. +// Copyright Paul A. Bristow 2007. + +// Use, modification and distribution are subject to 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) + +// Poisson distribution is a discrete probability distribution. +// It expresses the probability of a number (k) of +// events, occurrences, failures or arrivals occurring in a fixed time, +// assuming these events occur with a known average or mean rate (lambda) +// and are independent of the time since the last event. +// The distribution was discovered by Simeon-Denis Poisson (1781-1840). + +// Parameter lambda is the mean number of events in the given time interval. +// The random variate k is the number of events, occurrences or arrivals. +// k argument may be integral, signed, or unsigned, or floating point. +// If necessary, it has already been promoted from an integral type. + +// Note that the Poisson distribution +// (like others including the binomial, negative binomial & Bernoulli) +// is strictly defined as a discrete function: +// only integral values of k are envisaged. +// However because the method of calculation uses a continuous gamma function, +// it is convenient to treat it as if a continous function, +// and permit non-integral values of k. +// To enforce the strict mathematical model, users should use floor or ceil functions +// on k outside this function to ensure that k is integral. + +// See http://en.wikipedia.org/wiki/Poisson_distribution +// http://documents.wolfram.com/v5/Add-onsLinks/StandardPackages/Statistics/DiscreteDistributions.html + +#ifndef BOOST_MATH_SPECIAL_POISSON_HPP +#define BOOST_MATH_SPECIAL_POISSON_HPP + +#include <boost/math/distributions/fwd.hpp> +#include <boost/math/special_functions/gamma.hpp> // for incomplete gamma. gamma_q +#include <boost/math/special_functions/trunc.hpp> // for incomplete gamma. gamma_q +#include <boost/math/distributions/complement.hpp> // complements +#include <boost/math/distributions/detail/common_error_handling.hpp> // error checks +#include <boost/math/special_functions/fpclassify.hpp> // isnan. +#include <boost/math/special_functions/factorials.hpp> // factorials. +#include <boost/math/tools/roots.hpp> // for root finding. +#include <boost/math/distributions/detail/inv_discrete_quantile.hpp> + +#include <utility> + +namespace boost +{ + namespace math + { + namespace detail{ + template <class Dist> + inline typename Dist::value_type + inverse_discrete_quantile( + const Dist& dist, + const typename Dist::value_type& p, + const typename Dist::value_type& guess, + const typename Dist::value_type& multiplier, + const typename Dist::value_type& adder, + const policies::discrete_quantile<policies::integer_round_nearest>&, + boost::uintmax_t& max_iter); + template <class Dist> + inline typename Dist::value_type + inverse_discrete_quantile( + const Dist& dist, + const typename Dist::value_type& p, + const typename Dist::value_type& guess, + const typename Dist::value_type& multiplier, + const typename Dist::value_type& adder, + const policies::discrete_quantile<policies::integer_round_up>&, + boost::uintmax_t& max_iter); + template <class Dist> + inline typename Dist::value_type + inverse_discrete_quantile( + const Dist& dist, + const typename Dist::value_type& p, + const typename Dist::value_type& guess, + const typename Dist::value_type& multiplier, + const typename Dist::value_type& adder, + const policies::discrete_quantile<policies::integer_round_down>&, + boost::uintmax_t& max_iter); + template <class Dist> + inline typename Dist::value_type + inverse_discrete_quantile( + const Dist& dist, + const typename Dist::value_type& p, + const typename Dist::value_type& guess, + const typename Dist::value_type& multiplier, + const typename Dist::value_type& adder, + const policies::discrete_quantile<policies::integer_round_outwards>&, + boost::uintmax_t& max_iter); + template <class Dist> + inline typename Dist::value_type + inverse_discrete_quantile( + const Dist& dist, + const typename Dist::value_type& p, + const typename Dist::value_type& guess, + const typename Dist::value_type& multiplier, + const typename Dist::value_type& adder, + const policies::discrete_quantile<policies::integer_round_inwards>&, + boost::uintmax_t& max_iter); + template <class Dist> + inline typename Dist::value_type + inverse_discrete_quantile( + const Dist& dist, + const typename Dist::value_type& p, + const typename Dist::value_type& guess, + const typename Dist::value_type& multiplier, + const typename Dist::value_type& adder, + const policies::discrete_quantile<policies::real>&, + boost::uintmax_t& max_iter); + } + namespace poisson_detail + { + // Common error checking routines for Poisson distribution functions. + // These are convoluted, & apparently redundant, to try to ensure that + // checks are always performed, even if exceptions are not enabled. + + template <class RealType, class Policy> + inline bool check_mean(const char* function, const RealType& mean, RealType* result, const Policy& pol) + { + if(!(boost::math::isfinite)(mean) || (mean < 0)) + { + *result = policies::raise_domain_error<RealType>( + function, + "Mean argument is %1%, but must be >= 0 !", mean, pol); + return false; + } + return true; + } // bool check_mean + + template <class RealType, class Policy> + inline bool check_mean_NZ(const char* function, const RealType& mean, RealType* result, const Policy& pol) + { // mean == 0 is considered an error. + if( !(boost::math::isfinite)(mean) || (mean <= 0)) + { + *result = policies::raise_domain_error<RealType>( + function, + "Mean argument is %1%, but must be > 0 !", mean, pol); + return false; + } + return true; + } // bool check_mean_NZ + + template <class RealType, class Policy> + inline bool check_dist(const char* function, const RealType& mean, RealType* result, const Policy& pol) + { // Only one check, so this is redundant really but should be optimized away. + return check_mean_NZ(function, mean, result, pol); + } // bool check_dist + + template <class RealType, class Policy> + inline bool check_k(const char* function, const RealType& k, RealType* result, const Policy& pol) + { + if((k < 0) || !(boost::math::isfinite)(k)) + { + *result = policies::raise_domain_error<RealType>( + function, + "Number of events k argument is %1%, but must be >= 0 !", k, pol); + return false; + } + return true; + } // bool check_k + + template <class RealType, class Policy> + inline bool check_dist_and_k(const char* function, RealType mean, RealType k, RealType* result, const Policy& pol) + { + if((check_dist(function, mean, result, pol) == false) || + (check_k(function, k, result, pol) == false)) + { + return false; + } + return true; + } // bool check_dist_and_k + + template <class RealType, class Policy> + inline bool check_prob(const char* function, const RealType& p, RealType* result, const Policy& pol) + { // Check 0 <= p <= 1 + if(!(boost::math::isfinite)(p) || (p < 0) || (p > 1)) + { + *result = policies::raise_domain_error<RealType>( + function, + "Probability argument is %1%, but must be >= 0 and <= 1 !", p, pol); + return false; + } + return true; + } // bool check_prob + + template <class RealType, class Policy> + inline bool check_dist_and_prob(const char* function, RealType mean, RealType p, RealType* result, const Policy& pol) + { + if((check_dist(function, mean, result, pol) == false) || + (check_prob(function, p, result, pol) == false)) + { + return false; + } + return true; + } // bool check_dist_and_prob + + } // namespace poisson_detail + + template <class RealType = double, class Policy = policies::policy<> > + class poisson_distribution + { + public: + typedef RealType value_type; + typedef Policy policy_type; + + poisson_distribution(RealType mean = 1) : m_l(mean) // mean (lambda). + { // Expected mean number of events that occur during the given interval. + RealType r; + poisson_detail::check_dist( + "boost::math::poisson_distribution<%1%>::poisson_distribution", + m_l, + &r, Policy()); + } // poisson_distribution constructor. + + RealType mean() const + { // Private data getter function. + return m_l; + } + private: + // Data member, initialized by constructor. + RealType m_l; // mean number of occurrences. + }; // template <class RealType, class Policy> class poisson_distribution + + typedef poisson_distribution<double> poisson; // Reserved name of type double. + + // Non-member functions to give properties of the distribution. + + template <class RealType, class Policy> + inline const std::pair<RealType, RealType> range(const poisson_distribution<RealType, Policy>& /* dist */) + { // Range of permissible values for random variable k. + using boost::math::tools::max_value; + return std::pair<RealType, RealType>(0, max_value<RealType>()); // Max integer? + } + + template <class RealType, class Policy> + inline const std::pair<RealType, RealType> support(const poisson_distribution<RealType, Policy>& /* dist */) + { // Range of supported values for random variable k. + // This is range where cdf rises from 0 to 1, and outside it, the pdf is zero. + using boost::math::tools::max_value; + return std::pair<RealType, RealType>(0, max_value<RealType>()); + } + + template <class RealType, class Policy> + inline RealType mean(const poisson_distribution<RealType, Policy>& dist) + { // Mean of poisson distribution = lambda. + return dist.mean(); + } // mean + + template <class RealType, class Policy> + inline RealType mode(const poisson_distribution<RealType, Policy>& dist) + { // mode. + BOOST_MATH_STD_USING // ADL of std functions. + return floor(dist.mean()); + } + + //template <class RealType, class Policy> + //inline RealType median(const poisson_distribution<RealType, Policy>& dist) + //{ // median = approximately lambda + 1/3 - 0.2/lambda + // RealType l = dist.mean(); + // return dist.mean() + static_cast<RealType>(0.3333333333333333333333333333333333333333333333) + // - static_cast<RealType>(0.2) / l; + //} // BUT this formula appears to be out-by-one compared to quantile(half) + // Query posted on Wikipedia. + // Now implemented via quantile(half) in derived accessors. + + template <class RealType, class Policy> + inline RealType variance(const poisson_distribution<RealType, Policy>& dist) + { // variance. + return dist.mean(); + } + + // RealType standard_deviation(const poisson_distribution<RealType, Policy>& dist) + // standard_deviation provided by derived accessors. + + template <class RealType, class Policy> + inline RealType skewness(const poisson_distribution<RealType, Policy>& dist) + { // skewness = sqrt(l). + BOOST_MATH_STD_USING // ADL of std functions. + return 1 / sqrt(dist.mean()); + } + + template <class RealType, class Policy> + inline RealType kurtosis_excess(const poisson_distribution<RealType, Policy>& dist) + { // skewness = sqrt(l). + return 1 / dist.mean(); // kurtosis_excess 1/mean from Wiki & MathWorld eq 31. + // http://mathworld.wolfram.com/Kurtosis.html explains that the kurtosis excess + // is more convenient because the kurtosis excess of a normal distribution is zero + // whereas the true kurtosis is 3. + } // RealType kurtosis_excess + + template <class RealType, class Policy> + inline RealType kurtosis(const poisson_distribution<RealType, Policy>& dist) + { // kurtosis is 4th moment about the mean = u4 / sd ^ 4 + // http://en.wikipedia.org/wiki/Curtosis + // kurtosis can range from -2 (flat top) to +infinity (sharp peak & heavy tails). + // http://www.itl.nist.gov/div898/handbook/eda/section3/eda35b.htm + return 3 + 1 / dist.mean(); // NIST. + // http://mathworld.wolfram.com/Kurtosis.html explains that the kurtosis excess + // is more convenient because the kurtosis excess of a normal distribution is zero + // whereas the true kurtosis is 3. + } // RealType kurtosis + + template <class RealType, class Policy> + RealType pdf(const poisson_distribution<RealType, Policy>& dist, const RealType& k) + { // Probability Density/Mass Function. + // Probability that there are EXACTLY k occurrences (or arrivals). + BOOST_FPU_EXCEPTION_GUARD + + BOOST_MATH_STD_USING // for ADL of std functions. + + RealType mean = dist.mean(); + // Error check: + RealType result; + if(false == poisson_detail::check_dist_and_k( + "boost::math::pdf(const poisson_distribution<%1%>&, %1%)", + mean, + k, + &result, Policy())) + { + return result; + } + + // Special case of mean zero, regardless of the number of events k. + if (mean == 0) + { // Probability for any k is zero. + return 0; + } + if (k == 0) + { // mean ^ k = 1, and k! = 1, so can simplify. + return exp(-mean); + } + return boost::math::gamma_p_derivative(k+1, mean, Policy()); + } // pdf + + template <class RealType, class Policy> + RealType cdf(const poisson_distribution<RealType, Policy>& dist, const RealType& k) + { // Cumulative Distribution Function Poisson. + // The random variate k is the number of occurrences(or arrivals) + // k argument may be integral, signed, or unsigned, or floating point. + // If necessary, it has already been promoted from an integral type. + // Returns the sum of the terms 0 through k of the Poisson Probability Density or Mass (pdf). + + // But note that the Poisson distribution + // (like others including the binomial, negative binomial & Bernoulli) + // is strictly defined as a discrete function: only integral values of k are envisaged. + // However because of the method of calculation using a continuous gamma function, + // it is convenient to treat it as if it is a continous function + // and permit non-integral values of k. + // To enforce the strict mathematical model, users should use floor or ceil functions + // outside this function to ensure that k is integral. + + // The terms are not summed directly (at least for larger k) + // instead the incomplete gamma integral is employed, + + BOOST_MATH_STD_USING // for ADL of std function exp. + + RealType mean = dist.mean(); + // Error checks: + RealType result; + if(false == poisson_detail::check_dist_and_k( + "boost::math::cdf(const poisson_distribution<%1%>&, %1%)", + mean, + k, + &result, Policy())) + { + return result; + } + // Special cases: + if (mean == 0) + { // Probability for any k is zero. + return 0; + } + if (k == 0) + { // return pdf(dist, static_cast<RealType>(0)); + // but mean (and k) have already been checked, + // so this avoids unnecessary repeated checks. + return exp(-mean); + } + // For small integral k could use a finite sum - + // it's cheaper than the gamma function. + // BUT this is now done efficiently by gamma_q function. + // Calculate poisson cdf using the gamma_q function. + return gamma_q(k+1, mean, Policy()); + } // binomial cdf + + template <class RealType, class Policy> + RealType cdf(const complemented2_type<poisson_distribution<RealType, Policy>, RealType>& c) + { // Complemented Cumulative Distribution Function Poisson + // The random variate k is the number of events, occurrences or arrivals. + // k argument may be integral, signed, or unsigned, or floating point. + // If necessary, it has already been promoted from an integral type. + // But note that the Poisson distribution + // (like others including the binomial, negative binomial & Bernoulli) + // is strictly defined as a discrete function: only integral values of k are envisaged. + // However because of the method of calculation using a continuous gamma function, + // it is convenient to treat it as is it is a continous function + // and permit non-integral values of k. + // To enforce the strict mathematical model, users should use floor or ceil functions + // outside this function to ensure that k is integral. + + // Returns the sum of the terms k+1 through inf of the Poisson Probability Density/Mass (pdf). + // The terms are not summed directly (at least for larger k) + // instead the incomplete gamma integral is employed, + + RealType const& k = c.param; + poisson_distribution<RealType, Policy> const& dist = c.dist; + + RealType mean = dist.mean(); + + // Error checks: + RealType result; + if(false == poisson_detail::check_dist_and_k( + "boost::math::cdf(const poisson_distribution<%1%>&, %1%)", + mean, + k, + &result, Policy())) + { + return result; + } + // Special case of mean, regardless of the number of events k. + if (mean == 0) + { // Probability for any k is unity, complement of zero. + return 1; + } + if (k == 0) + { // Avoid repeated checks on k and mean in gamma_p. + return -boost::math::expm1(-mean, Policy()); + } + // Unlike un-complemented cdf (sum from 0 to k), + // can't use finite sum from k+1 to infinity for small integral k, + // anyway it is now done efficiently by gamma_p. + return gamma_p(k + 1, mean, Policy()); // Calculate Poisson cdf using the gamma_p function. + // CCDF = gamma_p(k+1, lambda) + } // poisson ccdf + + template <class RealType, class Policy> + inline RealType quantile(const poisson_distribution<RealType, Policy>& dist, const RealType& p) + { // Quantile (or Percent Point) Poisson function. + // Return the number of expected events k for a given probability p. + RealType result; // of Argument checks: + if(false == poisson_detail::check_prob( + "boost::math::quantile(const poisson_distribution<%1%>&, %1%)", + p, + &result, Policy())) + { + return result; + } + // Special case: + if (dist.mean() == 0) + { // if mean = 0 then p = 0, so k can be anything? + if (false == poisson_detail::check_mean_NZ( + "boost::math::quantile(const poisson_distribution<%1%>&, %1%)", + dist.mean(), + &result, Policy())) + { + return result; + } + } + /* + BOOST_MATH_STD_USING // ADL of std functions. + // if(p == 0) NOT necessarily zero! + // Not necessarily any special value of k because is unlimited. + if (p <= exp(-dist.mean())) + { // if p <= cdf for 0 events (== pdf for 0 events), then quantile must be zero. + return 0; + } + return gamma_q_inva(dist.mean(), p, Policy()) - 1; + */ + typedef typename Policy::discrete_quantile_type discrete_type; + boost::uintmax_t max_iter = policies::get_max_root_iterations<Policy>(); + RealType guess, factor = 8; + RealType z = dist.mean(); + if(z < 1) + guess = z; + else + guess = boost::math::detail::inverse_poisson_cornish_fisher(z, p, RealType(1-p), Policy()); + if(z > 5) + { + if(z > 1000) + factor = 1.01f; + else if(z > 50) + factor = 1.1f; + else if(guess > 10) + factor = 1.25f; + else + factor = 2; + if(guess < 1.1) + factor = 8; + } + + return detail::inverse_discrete_quantile( + dist, + p, + 1-p, + guess, + factor, + RealType(1), + discrete_type(), + max_iter); + } // quantile + + template <class RealType, class Policy> + inline RealType quantile(const complemented2_type<poisson_distribution<RealType, Policy>, RealType>& c) + { // Quantile (or Percent Point) of Poisson function. + // Return the number of expected events k for a given + // complement of the probability q. + // + // Error checks: + RealType q = c.param; + const poisson_distribution<RealType, Policy>& dist = c.dist; + RealType result; // of argument checks. + if(false == poisson_detail::check_prob( + "boost::math::quantile(const poisson_distribution<%1%>&, %1%)", + q, + &result, Policy())) + { + return result; + } + // Special case: + if (dist.mean() == 0) + { // if mean = 0 then p = 0, so k can be anything? + if (false == poisson_detail::check_mean_NZ( + "boost::math::quantile(const poisson_distribution<%1%>&, %1%)", + dist.mean(), + &result, Policy())) + { + return result; + } + } + /* + if (-q <= boost::math::expm1(-dist.mean())) + { // if q <= cdf(complement for 0 events, then quantile must be zero. + return 0; + } + return gamma_p_inva(dist.mean(), q, Policy()) -1; + */ + typedef typename Policy::discrete_quantile_type discrete_type; + boost::uintmax_t max_iter = policies::get_max_root_iterations<Policy>(); + RealType guess, factor = 8; + RealType z = dist.mean(); + if(z < 1) + guess = z; + else + guess = boost::math::detail::inverse_poisson_cornish_fisher(z, RealType(1-q), q, Policy()); + if(z > 5) + { + if(z > 1000) + factor = 1.01f; + else if(z > 50) + factor = 1.1f; + else if(guess > 10) + factor = 1.25f; + else + factor = 2; + if(guess < 1.1) + factor = 8; + } + + return detail::inverse_discrete_quantile( + dist, + 1-q, + q, + guess, + factor, + RealType(1), + discrete_type(), + max_iter); + } // quantile complement. + + } // namespace math +} // namespace boost + +// This include must be at the end, *after* the accessors +// for this distribution have been defined, in order to +// keep compilers that support two-phase lookup happy. +#include <boost/math/distributions/detail/derived_accessors.hpp> +#include <boost/math/distributions/detail/inv_discrete_quantile.hpp> + +#endif // BOOST_MATH_SPECIAL_POISSON_HPP + + + diff --git a/Utilities/BGL/boost/math/distributions/rayleigh.hpp b/Utilities/BGL/boost/math/distributions/rayleigh.hpp new file mode 100644 index 0000000000000000000000000000000000000000..0b6b11ddd124982596323fe78ad8e798609402ee --- /dev/null +++ b/Utilities/BGL/boost/math/distributions/rayleigh.hpp @@ -0,0 +1,293 @@ +// Copyright Paul A. Bristow 2007. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_STATS_rayleigh_HPP +#define BOOST_STATS_rayleigh_HPP + +#include <boost/math/distributions/fwd.hpp> +#include <boost/math/constants/constants.hpp> +#include <boost/math/special_functions/log1p.hpp> +#include <boost/math/special_functions/expm1.hpp> +#include <boost/math/distributions/complement.hpp> +#include <boost/math/distributions/detail/common_error_handling.hpp> +#include <boost/config/no_tr1/cmath.hpp> + +#ifdef BOOST_MSVC +# pragma warning(push) +# pragma warning(disable: 4702) // unreachable code (return after domain_error throw). +#endif + +#include <utility> + +namespace boost{ namespace math{ + +namespace detail +{ // Error checks: + template <class RealType, class Policy> + inline bool verify_sigma(const char* function, RealType sigma, RealType* presult, const Policy& pol) + { + if(sigma <= 0) + { + *presult = policies::raise_domain_error<RealType>( + function, + "The scale parameter \"sigma\" must be > 0, but was: %1%.", sigma, pol); + return false; + } + return true; + } // bool verify_sigma + + template <class RealType, class Policy> + inline bool verify_rayleigh_x(const char* function, RealType x, RealType* presult, const Policy& pol) + { + if(x < 0) + { + *presult = policies::raise_domain_error<RealType>( + function, + "The random variable must be >= 0, but was: %1%.", x, pol); + return false; + } + return true; + } // bool verify_rayleigh_x +} // namespace detail + +template <class RealType = double, class Policy = policies::policy<> > +class rayleigh_distribution +{ +public: + typedef RealType value_type; + typedef Policy policy_type; + + rayleigh_distribution(RealType sigma = 1) + : m_sigma(sigma) + { + RealType err; + detail::verify_sigma("boost::math::rayleigh_distribution<%1%>::rayleigh_distribution", sigma, &err, Policy()); + } // rayleigh_distribution + + RealType sigma()const + { // Accessor. + return m_sigma; + } + +private: + RealType m_sigma; +}; // class rayleigh_distribution + +typedef rayleigh_distribution<double> rayleigh; + +template <class RealType, class Policy> +inline const std::pair<RealType, RealType> range(const rayleigh_distribution<RealType, Policy>& /*dist*/) +{ // Range of permissible values for random variable x. + using boost::math::tools::max_value; + return std::pair<RealType, RealType>(static_cast<RealType>(1), max_value<RealType>()); +} + +template <class RealType, class Policy> +inline const std::pair<RealType, RealType> support(const rayleigh_distribution<RealType, Policy>& /*dist*/) +{ // Range of supported values for random variable x. + // This is range where cdf rises from 0 to 1, and outside it, the pdf is zero. + using boost::math::tools::max_value; + return std::pair<RealType, RealType>((1), max_value<RealType>()); +} + +template <class RealType, class Policy> +inline RealType pdf(const rayleigh_distribution<RealType, Policy>& dist, const RealType& x) +{ + BOOST_MATH_STD_USING // for ADL of std function exp. + + RealType sigma = dist.sigma(); + RealType result; + static const char* function = "boost::math::pdf(const rayleigh_distribution<%1%>&, %1%)"; + if(false == detail::verify_sigma(function, sigma, &result, Policy())) + { + return result; + } + if(false == detail::verify_rayleigh_x(function, x, &result, Policy())) + { + return result; + } + RealType sigmasqr = sigma * sigma; + result = x * (exp(-(x * x) / ( 2 * sigmasqr))) / sigmasqr; + return result; +} // pdf + +template <class RealType, class Policy> +inline RealType cdf(const rayleigh_distribution<RealType, Policy>& dist, const RealType& x) +{ + BOOST_MATH_STD_USING // for ADL of std functions + + RealType result; + RealType sigma = dist.sigma(); + static const char* function = "boost::math::cdf(const rayleigh_distribution<%1%>&, %1%)"; + if(false == detail::verify_sigma(function, sigma, &result, Policy())) + { + return result; + } + if(false == detail::verify_rayleigh_x(function, x, &result, Policy())) + { + return result; + } + result = -boost::math::expm1(-x * x / ( 2 * sigma * sigma), Policy()); + return result; +} // cdf + +template <class RealType, class Policy> +inline RealType quantile(const rayleigh_distribution<RealType, Policy>& dist, const RealType& p) +{ + BOOST_MATH_STD_USING // for ADL of std functions + + RealType result; + RealType sigma = dist.sigma(); + static const char* function = "boost::math::quantile(const rayleigh_distribution<%1%>&, %1%)"; + if(false == detail::verify_sigma(function, sigma, &result, Policy())) + return result; + if(false == detail::check_probability(function, p, &result, Policy())) + return result; + + if(p == 0) + { + return 0; + } + if(p == 1) + { + return policies::raise_overflow_error<RealType>(function, 0, Policy()); + } + result = sqrt(-2 * sigma * sigma * boost::math::log1p(-p, Policy())); + return result; +} // quantile + +template <class RealType, class Policy> +inline RealType cdf(const complemented2_type<rayleigh_distribution<RealType, Policy>, RealType>& c) +{ + BOOST_MATH_STD_USING // for ADL of std functions + + RealType result; + RealType sigma = c.dist.sigma(); + static const char* function = "boost::math::cdf(const rayleigh_distribution<%1%>&, %1%)"; + if(false == detail::verify_sigma(function, sigma, &result, Policy())) + { + return result; + } + RealType x = c.param; + if(false == detail::verify_rayleigh_x(function, x, &result, Policy())) + { + return result; + } + result = exp(-x * x / ( 2 * sigma * sigma)); + return result; +} // cdf complement + +template <class RealType, class Policy> +inline RealType quantile(const complemented2_type<rayleigh_distribution<RealType, Policy>, RealType>& c) +{ + BOOST_MATH_STD_USING // for ADL of std functions, log & sqrt. + + RealType result; + RealType sigma = c.dist.sigma(); + static const char* function = "boost::math::quantile(const rayleigh_distribution<%1%>&, %1%)"; + if(false == detail::verify_sigma(function, sigma, &result, Policy())) + { + return result; + } + RealType q = c.param; + if(false == detail::check_probability(function, q, &result, Policy())) + { + return result; + } + if(q == 1) + { + return 0; + } + if(q == 0) + { + return policies::raise_overflow_error<RealType>(function, 0, Policy()); + } + result = sqrt(-2 * sigma * sigma * log(q)); + return result; +} // quantile complement + +template <class RealType, class Policy> +inline RealType mean(const rayleigh_distribution<RealType, Policy>& dist) +{ + RealType result; + RealType sigma = dist.sigma(); + static const char* function = "boost::math::mean(const rayleigh_distribution<%1%>&, %1%)"; + if(false == detail::verify_sigma(function, sigma, &result, Policy())) + { + return result; + } + using boost::math::constants::root_half_pi; + return sigma * root_half_pi<RealType>(); +} // mean + +template <class RealType, class Policy> +inline RealType variance(const rayleigh_distribution<RealType, Policy>& dist) +{ + RealType result; + RealType sigma = dist.sigma(); + static const char* function = "boost::math::variance(const rayleigh_distribution<%1%>&, %1%)"; + if(false == detail::verify_sigma(function, sigma, &result, Policy())) + { + return result; + } + using boost::math::constants::four_minus_pi; + return four_minus_pi<RealType>() * sigma * sigma / 2; +} // variance + +template <class RealType, class Policy> +inline RealType mode(const rayleigh_distribution<RealType, Policy>& dist) +{ + return dist.sigma(); +} + +template <class RealType, class Policy> +inline RealType median(const rayleigh_distribution<RealType, Policy>& dist) +{ + using boost::math::constants::root_ln_four; + return root_ln_four<RealType>() * dist.sigma(); +} + +template <class RealType, class Policy> +inline RealType skewness(const rayleigh_distribution<RealType, Policy>& /*dist*/) +{ + // using namespace boost::math::constants; + return static_cast<RealType>(0.63111065781893713819189935154422777984404221106391L); + // Computed using NTL at 150 bit, about 50 decimal digits. + // return 2 * root_pi<RealType>() * pi_minus_three<RealType>() / pow23_four_minus_pi<RealType>(); +} + +template <class RealType, class Policy> +inline RealType kurtosis(const rayleigh_distribution<RealType, Policy>& /*dist*/) +{ + // using namespace boost::math::constants; + return static_cast<RealType>(3.2450893006876380628486604106197544154170667057995L); + // Computed using NTL at 150 bit, about 50 decimal digits. + // return 3 - (6 * pi<RealType>() * pi<RealType>() - 24 * pi<RealType>() + 16) / + // (four_minus_pi<RealType>() * four_minus_pi<RealType>()); +} + +template <class RealType, class Policy> +inline RealType kurtosis_excess(const rayleigh_distribution<RealType, Policy>& /*dist*/) +{ + //using namespace boost::math::constants; + // Computed using NTL at 150 bit, about 50 decimal digits. + return static_cast<RealType>(0.2450893006876380628486604106197544154170667057995L); + // return -(6 * pi<RealType>() * pi<RealType>() - 24 * pi<RealType>() + 16) / + // (four_minus_pi<RealType>() * four_minus_pi<RealType>()); +} // kurtosis + +} // namespace math +} // namespace boost + +#ifdef BOOST_MSVC +# pragma warning(pop) +#endif + +// This include must be at the end, *after* the accessors +// for this distribution have been defined, in order to +// keep compilers that support two-phase lookup happy. +#include <boost/math/distributions/detail/derived_accessors.hpp> + +#endif // BOOST_STATS_rayleigh_HPP diff --git a/Utilities/BGL/boost/math/distributions/students_t.hpp b/Utilities/BGL/boost/math/distributions/students_t.hpp new file mode 100644 index 0000000000000000000000000000000000000000..77814c71124665f377c05ef191d6a1e819131525 --- /dev/null +++ b/Utilities/BGL/boost/math/distributions/students_t.hpp @@ -0,0 +1,374 @@ +// Copyright John Maddock 2006. +// Copyright Paul A. Bristow 2006. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_STATS_STUDENTS_T_HPP +#define BOOST_STATS_STUDENTS_T_HPP + +// http://en.wikipedia.org/wiki/Student%27s_t_distribution +// http://www.itl.nist.gov/div898/handbook/eda/section3/eda3664.htm + +#include <boost/math/distributions/fwd.hpp> +#include <boost/math/special_functions/beta.hpp> // for ibeta(a, b, x). +#include <boost/math/distributions/complement.hpp> +#include <boost/math/distributions/detail/common_error_handling.hpp> + +#include <utility> + +#ifdef BOOST_MSVC +# pragma warning(push) +# pragma warning(disable: 4702) // unreachable code (return after domain_error throw). +#endif + +namespace boost{ namespace math{ + +template <class RealType = double, class Policy = policies::policy<> > +class students_t_distribution +{ +public: + typedef RealType value_type; + typedef Policy policy_type; + + students_t_distribution(RealType i) : m_df(i) + { // Constructor. + RealType result; + detail::check_df( + "boost::math::students_t_distribution<%1%>::students_t_distribution", m_df, &result, Policy()); + } // students_t_distribution + + RealType degrees_of_freedom()const + { + return m_df; + } + + // Parameter estimation: + static RealType find_degrees_of_freedom( + RealType difference_from_mean, + RealType alpha, + RealType beta, + RealType sd, + RealType hint = 100); + +private: + // + // Data members: + // + RealType m_df; // degrees of freedom are a real number. +}; + +typedef students_t_distribution<double> students_t; + +template <class RealType, class Policy> +inline const std::pair<RealType, RealType> range(const students_t_distribution<RealType, Policy>& /*dist*/) +{ // Range of permissible values for random variable x. + using boost::math::tools::max_value; + return std::pair<RealType, RealType>(-max_value<RealType>(), max_value<RealType>()); +} + +template <class RealType, class Policy> +inline const std::pair<RealType, RealType> support(const students_t_distribution<RealType, Policy>& /*dist*/) +{ // Range of supported values for random variable x. + // This is range where cdf rises from 0 to 1, and outside it, the pdf is zero. + using boost::math::tools::max_value; + return std::pair<RealType, RealType>(-max_value<RealType>(), max_value<RealType>()); +} + +template <class RealType, class Policy> +inline RealType pdf(const students_t_distribution<RealType, Policy>& dist, const RealType& t) +{ + BOOST_FPU_EXCEPTION_GUARD + BOOST_MATH_STD_USING // for ADL of std functions + + RealType degrees_of_freedom = dist.degrees_of_freedom(); + // Error check: + RealType error_result; + if(false == detail::check_df( + "boost::math::pdf(const students_t_distribution<%1%>&, %1%)", degrees_of_freedom, &error_result, Policy())) + return error_result; + // Might conceivably permit df = +infinity and use normal distribution. + RealType result; + RealType basem1 = t * t / degrees_of_freedom; + if(basem1 < 0.125) + { + result = exp(-boost::math::log1p(basem1, Policy()) * (1+degrees_of_freedom) / 2); + } + else + { + result = pow(1 / (1 + basem1), (degrees_of_freedom + 1) / 2); + } + result /= sqrt(degrees_of_freedom) * boost::math::beta(degrees_of_freedom / 2, RealType(0.5f), Policy()); + return result; +} // pdf + +template <class RealType, class Policy> +inline RealType cdf(const students_t_distribution<RealType, Policy>& dist, const RealType& t) +{ + RealType degrees_of_freedom = dist.degrees_of_freedom(); + // Error check: + RealType error_result; + if(false == detail::check_df( + "boost::math::cdf(const students_t_distribution<%1%>&, %1%)", degrees_of_freedom, &error_result, Policy())) + return error_result; + + if (t == 0) + { + return 0.5; + } + // + // Calculate probability of Student's t using the incomplete beta function. + // probability = ibeta(degrees_of_freedom / 2, 1/2, degrees_of_freedom / (degrees_of_freedom + t*t)) + // + // However when t is small compared to the degrees of freedom, that formula + // suffers from rounding error, use the identity formula to work around + // the problem: + // + // I[x](a,b) = 1 - I[1-x](b,a) + // + // and: + // + // x = df / (df + t^2) + // + // so: + // + // 1 - x = t^2 / (df + t^2) + // + RealType t2 = t * t; + RealType probability; + if(degrees_of_freedom > 2 * t2) + { + RealType z = t2 / (degrees_of_freedom + t2); + probability = ibetac(static_cast<RealType>(0.5), degrees_of_freedom / 2, z, Policy()) / 2; + } + else + { + RealType z = degrees_of_freedom / (degrees_of_freedom + t2); + probability = ibeta(degrees_of_freedom / 2, static_cast<RealType>(0.5), z, Policy()) / 2; + } + return (t > 0 ? 1 - probability : probability); +} // cdf + +template <class RealType, class Policy> +inline RealType quantile(const students_t_distribution<RealType, Policy>& dist, const RealType& p) +{ + BOOST_MATH_STD_USING // for ADL of std functions + // + // Obtain parameters: + // + RealType degrees_of_freedom = dist.degrees_of_freedom(); + RealType probability = p; + // + // Check for domain errors: + // + static const char* function = "boost::math::quantile(const students_t_distribution<%1%>&, %1%)"; + RealType error_result; + if(false == detail::check_df( + function, degrees_of_freedom, &error_result, Policy()) + && detail::check_probability(function, probability, &error_result, Policy())) + return error_result; + + // Special cases, regardless of degrees_of_freedom. + if (probability == 0) + return -policies::raise_overflow_error<RealType>(function, 0, Policy()); + if (probability == 1) + return policies::raise_overflow_error<RealType>(function, 0, Policy()); + if (probability == static_cast<RealType>(0.5)) + return 0; + // + // This next block is disabled in favour of a faster method than + // incomplete beta inverse, code retained for future reference: + // +#if 0 + // + // Calculate quantile of Student's t using the incomplete beta function inverse: + // + probability = (probability > 0.5) ? 1 - probability : probability; + RealType t, x, y; + x = ibeta_inv(degrees_of_freedom / 2, RealType(0.5), 2 * probability, &y); + if(degrees_of_freedom * y > tools::max_value<RealType>() * x) + t = tools::overflow_error<RealType>(function); + else + t = sqrt(degrees_of_freedom * y / x); + // + // Figure out sign based on the size of p: + // + if(p < 0.5) + t = -t; + + return t; +#endif + // + // Depending on how many digits RealType has, this may forward + // to the incomplete beta inverse as above. Otherwise uses a + // faster method that is accurate to ~15 digits everywhere + // and a couple of epsilon at double precision and in the central + // region where most use cases will occur... + // + return boost::math::detail::fast_students_t_quantile(degrees_of_freedom, probability, Policy()); +} // quantile + +template <class RealType, class Policy> +inline RealType cdf(const complemented2_type<students_t_distribution<RealType, Policy>, RealType>& c) +{ + return cdf(c.dist, -c.param); +} + +template <class RealType, class Policy> +inline RealType quantile(const complemented2_type<students_t_distribution<RealType, Policy>, RealType>& c) +{ + return -quantile(c.dist, c.param); +} + +// +// Parameter estimation follows: +// +namespace detail{ +// +// Functors for finding degrees of freedom: +// +template <class RealType, class Policy> +struct sample_size_func +{ + sample_size_func(RealType a, RealType b, RealType s, RealType d) + : alpha(a), beta(b), ratio(s*s/(d*d)) {} + + RealType operator()(const RealType& df) + { + if(df <= tools::min_value<RealType>()) + return 1; + students_t_distribution<RealType, Policy> t(df); + RealType qa = quantile(complement(t, alpha)); + RealType qb = quantile(complement(t, beta)); + qa += qb; + qa *= qa; + qa *= ratio; + qa -= (df + 1); + return qa; + } + RealType alpha, beta, ratio; +}; + +} // namespace detail + +template <class RealType, class Policy> +RealType students_t_distribution<RealType, Policy>::find_degrees_of_freedom( + RealType difference_from_mean, + RealType alpha, + RealType beta, + RealType sd, + RealType hint) +{ + static const char* function = "boost::math::students_t_distribution<%1%>::find_degrees_of_freedom"; + // + // Check for domain errors: + // + RealType error_result; + if(false == detail::check_probability( + function, alpha, &error_result, Policy()) + && detail::check_probability(function, beta, &error_result, Policy())) + return error_result; + + if(hint <= 0) + hint = 1; + + detail::sample_size_func<RealType, Policy> f(alpha, beta, sd, difference_from_mean); + tools::eps_tolerance<RealType> tol(policies::digits<RealType, Policy>()); + boost::uintmax_t max_iter = policies::get_max_root_iterations<Policy>(); + std::pair<RealType, RealType> r = tools::bracket_and_solve_root(f, hint, RealType(2), false, tol, max_iter, Policy()); + RealType result = r.first + (r.second - r.first) / 2; + if(max_iter >= policies::get_max_root_iterations<Policy>()) + { + policies::raise_evaluation_error<RealType>(function, "Unable to locate solution in a reasonable time:" + " either there is no answer to how many degrees of freedom are required" + " or the answer is infinite. Current best guess is %1%", result, Policy()); + } + return result; +} + +template <class RealType, class Policy> +inline RealType mean(const students_t_distribution<RealType, Policy>& ) +{ + return 0; +} + +template <class RealType, class Policy> +inline RealType variance(const students_t_distribution<RealType, Policy>& dist) +{ + // Error check: + RealType error_result; + if(false == detail::check_df( + "boost::math::variance(students_t_distribution<%1%> const&, %1%)", dist.degrees_of_freedom(), &error_result, Policy())) + return error_result; + + RealType v = dist.degrees_of_freedom(); + return v / (v - 2); +} + +template <class RealType, class Policy> +inline RealType mode(const students_t_distribution<RealType, Policy>& /*dist*/) +{ + return 0; +} + +template <class RealType, class Policy> +inline RealType median(const students_t_distribution<RealType, Policy>& /*dist*/) +{ + return 0; +} + +template <class RealType, class Policy> +inline RealType skewness(const students_t_distribution<RealType, Policy>& dist) +{ + if(dist.degrees_of_freedom() <= 3) + { + policies::raise_domain_error<RealType>( + "boost::math::skewness(students_t_distribution<%1%> const&, %1%)", + "Skewness is undefined for degrees of freedom <= 3, but got %1%.", + dist.degrees_of_freedom(), Policy()); + } + return 0; +} + +template <class RealType, class Policy> +inline RealType kurtosis(const students_t_distribution<RealType, Policy>& dist) +{ + RealType df = dist.degrees_of_freedom(); + if(df <= 3) + { + policies::raise_domain_error<RealType>( + "boost::math::kurtosis(students_t_distribution<%1%> const&, %1%)", + "Skewness is undefined for degrees of freedom <= 3, but got %1%.", + df, Policy()); + } + return 3 * (df - 2) / (df - 4); +} + +template <class RealType, class Policy> +inline RealType kurtosis_excess(const students_t_distribution<RealType, Policy>& dist) +{ + // see http://mathworld.wolfram.com/Kurtosis.html + RealType df = dist.degrees_of_freedom(); + if(df <= 3) + { + policies::raise_domain_error<RealType>( + "boost::math::kurtosis_excess(students_t_distribution<%1%> const&, %1%)", + "Skewness is undefined for degrees of freedom <= 3, but got %1%.", + df, Policy()); + } + return 6 / (df - 4); +} + +} // namespace math +} // namespace boost + +#ifdef BOOST_MSVC +# pragma warning(pop) +#endif + +// This include must be at the end, *after* the accessors +// for this distribution have been defined, in order to +// keep compilers that support two-phase lookup happy. +#include <boost/math/distributions/detail/derived_accessors.hpp> + +#endif // BOOST_STATS_STUDENTS_T_HPP diff --git a/Utilities/BGL/boost/math/distributions/triangular.hpp b/Utilities/BGL/boost/math/distributions/triangular.hpp new file mode 100644 index 0000000000000000000000000000000000000000..5e36bb5c8c253d86ba11200d2defa51a3b5feffb --- /dev/null +++ b/Utilities/BGL/boost/math/distributions/triangular.hpp @@ -0,0 +1,523 @@ +// Copyright John Maddock 2006, 2007. +// Copyright Paul A. Bristow 2006, 2007. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_STATS_TRIANGULAR_HPP +#define BOOST_STATS_TRIANGULAR_HPP + +// http://mathworld.wolfram.com/TriangularDistribution.html +// http://en.wikipedia.org/wiki/Triangular_distribution + +#include <boost/math/distributions/fwd.hpp> +#include <boost/math/special_functions/expm1.hpp> +#include <boost/math/distributions/detail/common_error_handling.hpp> +#include <boost/math/distributions/complement.hpp> +#include <boost/math/constants/constants.hpp> + +#include <utility> + +namespace boost{ namespace math +{ + namespace detail + { + template <class RealType, class Policy> + inline bool check_triangular_lower( + const char* function, + RealType lower, + RealType* result, const Policy& pol) + { + if((boost::math::isfinite)(lower)) + { // Any finite value is OK. + return true; + } + else + { // Not finite: infinity or NaN. + *result = policies::raise_domain_error<RealType>( + function, + "Lower parameter is %1%, but must be finite!", lower, pol); + return false; + } + } // bool check_triangular_lower( + + template <class RealType, class Policy> + inline bool check_triangular_mode( + const char* function, + RealType mode, + RealType* result, const Policy& pol) + { + if((boost::math::isfinite)(mode)) + { // any finite value is OK. + return true; + } + else + { // Not finite: infinity or NaN. + *result = policies::raise_domain_error<RealType>( + function, + "Mode parameter is %1%, but must be finite!", mode, pol); + return false; + } + } // bool check_triangular_mode( + + template <class RealType, class Policy> + inline bool check_triangular_upper( + const char* function, + RealType upper, + RealType* result, const Policy& pol) + { + if((boost::math::isfinite)(upper)) + { // any finite value is OK. + return true; + } + else + { // Not finite: infinity or NaN. + *result = policies::raise_domain_error<RealType>( + function, + "Upper parameter is %1%, but must be finite!", upper, pol); + return false; + } + } // bool check_triangular_upper( + + template <class RealType, class Policy> + inline bool check_triangular_x( + const char* function, + RealType const& x, + RealType* result, const Policy& pol) + { + if((boost::math::isfinite)(x)) + { // Any finite value is OK + return true; + } + else + { // Not finite: infinity or NaN. + *result = policies::raise_domain_error<RealType>( + function, + "x parameter is %1%, but must be finite!", x, pol); + return false; + } + } // bool check_triangular_x + + template <class RealType, class Policy> + inline bool check_triangular( + const char* function, + RealType lower, + RealType mode, + RealType upper, + RealType* result, const Policy& pol) + { + if ((check_triangular_lower(function, lower, result, pol) == false) + || (check_triangular_mode(function, mode, result, pol) == false) + || (check_triangular_upper(function, upper, result, pol) == false)) + { // Some parameter not finite. + return false; + } + else if (lower >= upper) // lower == upper NOT useful. + { // lower >= upper. + *result = policies::raise_domain_error<RealType>( + function, + "lower parameter is %1%, but must be less than upper!", lower, pol); + return false; + } + else + { // Check lower <= mode <= upper. + if (mode < lower) + { + *result = policies::raise_domain_error<RealType>( + function, + "mode parameter is %1%, but must be >= than lower!", lower, pol); + return false; + } + if (mode > upper) + { + *result = policies::raise_domain_error<RealType>( + function, + "mode parameter is %1%, but must be <= than upper!", upper, pol); + return false; + } + return true; // All OK. + } + } // bool check_triangular + } // namespace detail + + template <class RealType = double, class Policy = policies::policy<> > + class triangular_distribution + { + public: + typedef RealType value_type; + typedef Policy policy_type; + + triangular_distribution(RealType lower = -1, RealType mode = 0, RealType upper = 1) + : m_lower(lower), m_mode(mode), m_upper(upper) // Constructor. + { // Evans says 'standard triangular' is lower 0, mode 1/2, upper 1, + // has median sqrt(c/2) for c <=1/2 and 1 - sqrt(1-c)/2 for c >= 1/2 + // But this -1, 0, 1 is more useful in most applications to approximate normal distribution, + // where the central value is the most likely and deviations either side equally likely. + RealType result; + detail::check_triangular("boost::math::triangular_distribution<%1%>::triangular_distribution",lower, mode, upper, &result, Policy()); + } + // Accessor functions. + RealType lower()const + { + return m_lower; + } + RealType mode()const + { + return m_mode; + } + RealType upper()const + { + return m_upper; + } + private: + // Data members: + RealType m_lower; // distribution lower aka a + RealType m_mode; // distribution mode aka c + RealType m_upper; // distribution upper aka b + }; // class triangular_distribution + + typedef triangular_distribution<double> triangular; + + template <class RealType, class Policy> + inline const std::pair<RealType, RealType> range(const triangular_distribution<RealType, Policy>& /* dist */) + { // Range of permissible values for random variable x. + using boost::math::tools::max_value; + return std::pair<RealType, RealType>(-max_value<RealType>(), max_value<RealType>()); + } + + template <class RealType, class Policy> + inline const std::pair<RealType, RealType> support(const triangular_distribution<RealType, Policy>& dist) + { // Range of supported values for random variable x. + // This is range where cdf rises from 0 to 1, and outside it, the pdf is zero. + return std::pair<RealType, RealType>(dist.lower(), dist.upper()); + } + + template <class RealType, class Policy> + RealType pdf(const triangular_distribution<RealType, Policy>& dist, const RealType& x) + { + static const char* function = "boost::math::pdf(const triangular_distribution<%1%>&, %1%)"; + RealType lower = dist.lower(); + RealType mode = dist.mode(); + RealType upper = dist.upper(); + RealType result; // of checks. + if(false == detail::check_triangular(function, lower, mode, upper, &result, Policy())) + { + return result; + } + if(false == detail::check_triangular_x(function, x, &result, Policy())) + { + return result; + } + if((x < lower) || (x > upper)) + { + return 0; + } + if (x == lower) + { // (mode - lower) == 0 which would lead to divide by zero! + return (mode == lower) ? 2 / (upper - lower) : RealType(0); + } + else if (x == upper) + { + return (mode == upper) ? 2 / (upper - lower) : RealType(0); + } + else if (x <= mode) + { + return 2 * (x - lower) / ((upper - lower) * (mode - lower)); + } + else + { // (x > mode) + return 2 * (upper - x) / ((upper - lower) * (upper - mode)); + } + } // RealType pdf(const triangular_distribution<RealType, Policy>& dist, const RealType& x) + + template <class RealType, class Policy> + inline RealType cdf(const triangular_distribution<RealType, Policy>& dist, const RealType& x) + { + static const char* function = "boost::math::cdf(const triangular_distribution<%1%>&, %1%)"; + RealType lower = dist.lower(); + RealType mode = dist.mode(); + RealType upper = dist.upper(); + RealType result; // of checks. + if(false == detail::check_triangular(function, lower, mode, upper, &result, Policy())) + { + return result; + } + if(false == detail::check_triangular_x(function, x, &result, Policy())) + { + return result; + } + if((x <= lower)) + { + return 0; + } + if (x >= upper) + { + return 1; + } + // else lower < x < upper + if (x <= mode) + { + return ((x - lower) * (x - lower)) / ((upper - lower) * (mode - lower)); + } + else + { + return 1 - (upper - x) * (upper - x) / ((upper - lower) * (upper - mode)); + } + } // RealType cdf(const triangular_distribution<RealType, Policy>& dist, const RealType& x) + + template <class RealType, class Policy> + RealType quantile(const triangular_distribution<RealType, Policy>& dist, const RealType& p) + { + BOOST_MATH_STD_USING // for ADL of std functions (sqrt). + static const char* function = "boost::math::quantile(const triangular_distribution<%1%>&, %1%)"; + RealType lower = dist.lower(); + RealType mode = dist.mode(); + RealType upper = dist.upper(); + RealType result; // of checks + if(false == detail::check_triangular(function,lower, mode, upper, &result, Policy())) + { + return result; + } + if(false == detail::check_probability(function, p, &result, Policy())) + { + return result; + } + if(p == 0) + { + return lower; + } + if(p == 1) + { + return upper; + } + RealType p0 = (mode - lower) / (upper - lower); + RealType q = 1 - p; + if (p < p0) + { + result = sqrt((upper - lower) * (mode - lower) * p) + lower; + } + else if (p == p0) + { + result = mode; + } + else // p > p0 + { + result = upper - sqrt((upper - lower) * (upper - mode) * q); + } + return result; + + } // RealType quantile(const triangular_distribution<RealType, Policy>& dist, const RealType& q) + + template <class RealType, class Policy> + RealType cdf(const complemented2_type<triangular_distribution<RealType, Policy>, RealType>& c) + { + static const char* function = "boost::math::cdf(const triangular_distribution<%1%>&, %1%)"; + RealType lower = c.dist.lower(); + RealType mode = c.dist.mode(); + RealType upper = c.dist.upper(); + RealType x = c.param; + RealType result; // of checks. + if(false == detail::check_triangular(function, lower, mode, upper, &result, Policy())) + { + return result; + } + if(false == detail::check_triangular_x(function, x, &result, Policy())) + { + return result; + } + if (x <= lower) + { + return 1; + } + if (x >= upper) + { + return 0; + } + if (x <= mode) + { + return 1 - ((x - lower) * (x - lower)) / ((upper - lower) * (mode - lower)); + } + else + { + return (upper - x) * (upper - x) / ((upper - lower) * (upper - mode)); + } + } // RealType cdf(const complemented2_type<triangular_distribution<RealType, Policy>, RealType>& c) + + template <class RealType, class Policy> + RealType quantile(const complemented2_type<triangular_distribution<RealType, Policy>, RealType>& c) + { + BOOST_MATH_STD_USING // Aid ADL for sqrt. + static const char* function = "boost::math::quantile(const triangular_distribution<%1%>&, %1%)"; + RealType l = c.dist.lower(); + RealType m = c.dist.mode(); + RealType u = c.dist.upper(); + RealType q = c.param; // probability 0 to 1. + RealType result; // of checks. + if(false == detail::check_triangular(function, l, m, u, &result, Policy())) + { + return result; + } + if(false == detail::check_probability(function, q, &result, Policy())) + { + return result; + } + if(q == 0) + { + return u; + } + if(q == 1) + { + return l; + } + RealType lower = c.dist.lower(); + RealType mode = c.dist.mode(); + RealType upper = c.dist.upper(); + + RealType p = 1 - q; + RealType p0 = (mode - lower) / (upper - lower); + if(p < p0) + { + RealType s = (upper - lower) * (mode - lower); + s *= p; + result = sqrt((upper - lower) * (mode - lower) * p) + lower; + } + else if (p == p0) + { + result = mode; + } + else // p > p0 + { + result = upper - sqrt((upper - lower) * (upper - mode) * q); + } + return result; + } // RealType quantile(const complemented2_type<triangular_distribution<RealType, Policy>, RealType>& c) + + template <class RealType, class Policy> + inline RealType mean(const triangular_distribution<RealType, Policy>& dist) + { + static const char* function = "boost::math::mean(const triangular_distribution<%1%>&)"; + RealType lower = dist.lower(); + RealType mode = dist.mode(); + RealType upper = dist.upper(); + RealType result; // of checks. + if(false == detail::check_triangular(function, lower, mode, upper, &result, Policy())) + { + return result; + } + return (lower + upper + mode) / 3; + } // RealType mean(const triangular_distribution<RealType, Policy>& dist) + + + template <class RealType, class Policy> + inline RealType variance(const triangular_distribution<RealType, Policy>& dist) + { + static const char* function = "boost::math::mean(const triangular_distribution<%1%>&)"; + RealType lower = dist.lower(); + RealType mode = dist.mode(); + RealType upper = dist.upper(); + RealType result; // of checks. + if(false == detail::check_triangular(function, lower, mode, upper, &result, Policy())) + { + return result; + } + return (lower * lower + upper * upper + mode * mode - lower * upper - lower * mode - upper * mode) / 18; + } // RealType variance(const triangular_distribution<RealType, Policy>& dist) + + template <class RealType, class Policy> + inline RealType mode(const triangular_distribution<RealType, Policy>& dist) + { + static const char* function = "boost::math::mode(const triangular_distribution<%1%>&)"; + RealType mode = dist.mode(); + RealType result; // of checks. + if(false == detail::check_triangular_mode(function, mode, &result, Policy())) + { // This should never happen! + return result; + } + return mode; + } // RealType mode + + template <class RealType, class Policy> + inline RealType median(const triangular_distribution<RealType, Policy>& dist) + { + BOOST_MATH_STD_USING // ADL of std functions. + static const char* function = "boost::math::median(const triangular_distribution<%1%>&)"; + RealType mode = dist.mode(); + RealType result; // of checks. + if(false == detail::check_triangular_mode(function, mode, &result, Policy())) + { // This should never happen! + return result; + } + RealType lower = dist.lower(); + RealType upper = dist.upper(); + if (mode < (upper - lower) / 2) + { + return lower + sqrt((upper - lower) * (mode - lower)) / constants::root_two<RealType>(); + } + else + { + return upper - sqrt((upper - lower) * (upper - mode)) / constants::root_two<RealType>(); + } + } // RealType mode + + template <class RealType, class Policy> + inline RealType skewness(const triangular_distribution<RealType, Policy>& dist) + { + BOOST_MATH_STD_USING // for ADL of std functions + using namespace boost::math::constants; // for root_two + static const char* function = "boost::math::skewness(const triangular_distribution<%1%>&)"; + + RealType lower = dist.lower(); + RealType mode = dist.mode(); + RealType upper = dist.upper(); + RealType result; // of checks. + if(false == detail::check_triangular(function,lower, mode, upper, &result, Policy())) + { + return result; + } + return root_two<RealType>() * (lower + upper - 2 * mode) * (2 * lower - upper - mode) * (lower - 2 * upper + mode) / + (5 * pow((lower * lower + upper + upper + mode * mode - lower * upper - lower * mode - upper * mode), RealType(3)/RealType(2))); + } // RealType skewness(const triangular_distribution<RealType, Policy>& dist) + + template <class RealType, class Policy> + inline RealType kurtosis(const triangular_distribution<RealType, Policy>& dist) + { // These checks may be belt and braces as should have been checked on construction? + static const char* function = "boost::math::kurtosis(const triangular_distribution<%1%>&)"; + RealType lower = dist.lower(); + RealType upper = dist.upper(); + RealType mode = dist.mode(); + RealType result; // of checks. + if(false == detail::check_triangular(function,lower, mode, upper, &result, Policy())) + { + return result; + } + return static_cast<RealType>(12)/5; // 12/5 = 2.4; + } // RealType kurtosis_excess(const triangular_distribution<RealType, Policy>& dist) + + template <class RealType, class Policy> + inline RealType kurtosis_excess(const triangular_distribution<RealType, Policy>& dist) + { // These checks may be belt and braces as should have been checked on construction? + static const char* function = "boost::math::kurtosis_excess(const triangular_distribution<%1%>&)"; + RealType lower = dist.lower(); + RealType upper = dist.upper(); + RealType mode = dist.mode(); + RealType result; // of checks. + if(false == detail::check_triangular(function,lower, mode, upper, &result, Policy())) + { + return result; + } + return static_cast<RealType>(-3)/5; // - 3/5 = -0.6 + // Assuming mathworld really means kurtosis excess? Wikipedia now corrected to match this. + } + +} // namespace math +} // namespace boost + +// This include must be at the end, *after* the accessors +// for this distribution have been defined, in order to +// keep compilers that support two-phase lookup happy. +#include <boost/math/distributions/detail/derived_accessors.hpp> + +#endif // BOOST_STATS_TRIANGULAR_HPP + + + diff --git a/Utilities/BGL/boost/math/distributions/uniform.hpp b/Utilities/BGL/boost/math/distributions/uniform.hpp new file mode 100644 index 0000000000000000000000000000000000000000..833e0637d699afb5813a477dd3060736aa9c507c --- /dev/null +++ b/Utilities/BGL/boost/math/distributions/uniform.hpp @@ -0,0 +1,379 @@ +// Copyright John Maddock 2006. +// Copyright Paul A. Bristow 2006. +// Use, modification and distribution are subject to 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) + +// TODO deal with infinity as special better - or remove. +// + +#ifndef BOOST_STATS_UNIFORM_HPP +#define BOOST_STATS_UNIFORM_HPP + +// http://www.itl.nist.gov/div898/handbook/eda/section3/eda3668.htm +// http://mathworld.wolfram.com/UniformDistribution.html +// http://documents.wolfram.com/calculationcenter/v2/Functions/ListsMatrices/Statistics/UniformDistribution.html +// http://en.wikipedia.org/wiki/Uniform_distribution_%28continuous%29 + +#include <boost/math/distributions/fwd.hpp> +#include <boost/math/distributions/detail/common_error_handling.hpp> +#include <boost/math/distributions/complement.hpp> + +#include <utility> + +namespace boost{ namespace math +{ + namespace detail + { + template <class RealType, class Policy> + inline bool check_uniform_lower( + const char* function, + RealType lower, + RealType* result, const Policy& pol) + { + if((boost::math::isfinite)(lower)) + { // any finite value is OK. + return true; + } + else + { // Not finite. + *result = policies::raise_domain_error<RealType>( + function, + "Lower parameter is %1%, but must be finite!", lower, pol); + return false; + } + } // bool check_uniform_lower( + + template <class RealType, class Policy> + inline bool check_uniform_upper( + const char* function, + RealType upper, + RealType* result, const Policy& pol) + { + if((boost::math::isfinite)(upper)) + { // Any finite value is OK. + return true; + } + else + { // Not finite. + *result = policies::raise_domain_error<RealType>( + function, + "Upper parameter is %1%, but must be finite!", upper, pol); + return false; + } + } // bool check_uniform_upper( + + template <class RealType, class Policy> + inline bool check_uniform_x( + const char* function, + RealType const& x, + RealType* result, const Policy& pol) + { + if((boost::math::isfinite)(x)) + { // Any finite value is OK + return true; + } + else + { // Not finite.. + *result = policies::raise_domain_error<RealType>( + function, + "x parameter is %1%, but must be finite!", x, pol); + return false; + } + } // bool check_uniform_x + + template <class RealType, class Policy> + inline bool check_uniform( + const char* function, + RealType lower, + RealType upper, + RealType* result, const Policy& pol) + { + if((check_uniform_lower(function, lower, result, pol) == false) + || (check_uniform_upper(function, upper, result, pol) == false)) + { + return false; + } + else if (lower >= upper) // If lower == upper then 1 / (upper-lower) = 1/0 = +infinity! + { // upper and lower have been checked before, so must be lower >= upper. + *result = policies::raise_domain_error<RealType>( + function, + "lower parameter is %1%, but must be less than upper!", lower, pol); + return false; + } + else + { // All OK, + return true; + } + } // bool check_uniform( + + } // namespace detail + + template <class RealType = double, class Policy = policies::policy<> > + class uniform_distribution + { + public: + typedef RealType value_type; + typedef Policy policy_type; + + uniform_distribution(RealType lower = 0, RealType upper = 1) // Constructor. + : m_lower(lower), m_upper(upper) // Default is standard uniform distribution. + { + RealType result; + detail::check_uniform("boost::math::uniform_distribution<%1%>::uniform_distribution", lower, upper, &result, Policy()); + } + // Accessor functions. + RealType lower()const + { + return m_lower; + } + + RealType upper()const + { + return m_upper; + } + private: + // Data members: + RealType m_lower; // distribution lower aka a. + RealType m_upper; // distribution upper aka b. + }; // class uniform_distribution + + typedef uniform_distribution<double> uniform; + + template <class RealType, class Policy> + inline const std::pair<RealType, RealType> range(const uniform_distribution<RealType, Policy>& /* dist */) + { // Range of permissible values for random variable x. + using boost::math::tools::max_value; + return std::pair<RealType, RealType>(-max_value<RealType>(), max_value<RealType>()); // - to + 'infinity'. + // Note RealType infinity is NOT permitted, only max_value. + } + + template <class RealType, class Policy> + inline const std::pair<RealType, RealType> support(const uniform_distribution<RealType, Policy>& dist) + { // Range of supported values for random variable x. + // This is range where cdf rises from 0 to 1, and outside it, the pdf is zero. + using boost::math::tools::max_value; + return std::pair<RealType, RealType>(dist.lower(), dist.upper()); + } + + template <class RealType, class Policy> + inline RealType pdf(const uniform_distribution<RealType, Policy>& dist, const RealType& x) + { + RealType lower = dist.lower(); + RealType upper = dist.upper(); + RealType result; // of checks. + if(false == detail::check_uniform("boost::math::pdf(const uniform_distribution<%1%>&, %1%)", lower, upper, &result, Policy())) + { + return result; + } + if(false == detail::check_uniform_x("boost::math::pdf(const uniform_distribution<%1%>&, %1%)", x, &result, Policy())) + { + return result; + } + + if((x < lower) || (x > upper) ) + { + return 0; + } + else + { + return 1 / (upper - lower); + } + } // RealType pdf(const uniform_distribution<RealType, Policy>& dist, const RealType& x) + + template <class RealType, class Policy> + inline RealType cdf(const uniform_distribution<RealType, Policy>& dist, const RealType& x) + { + RealType lower = dist.lower(); + RealType upper = dist.upper(); + RealType result; // of checks. + if(false == detail::check_uniform("boost::math::cdf(const uniform_distribution<%1%>&, %1%)",lower, upper, &result, Policy())) + { + return result; + } + if(false == detail::check_uniform_x("boost::math::cdf(const uniform_distribution<%1%>&, %1%)", x, &result, Policy())) + { + return result; + } + if (x < lower) + { + return 0; + } + if (x > upper) + { + return 1; + } + return (x - lower) / (upper - lower); // lower <= x <= upper + } // RealType cdf(const uniform_distribution<RealType, Policy>& dist, const RealType& x) + + template <class RealType, class Policy> + inline RealType quantile(const uniform_distribution<RealType, Policy>& dist, const RealType& p) + { + RealType lower = dist.lower(); + RealType upper = dist.upper(); + RealType result; // of checks + if(false == detail::check_uniform("boost::math::quantile(const uniform_distribution<%1%>&, %1%)",lower, upper, &result, Policy())) + { + return result; + } + if(false == detail::check_probability("boost::math::quantile(const uniform_distribution<%1%>&, %1%)", p, &result, Policy())) + { + return result; + } + if(p == 0) + { + return lower; + } + if(p == 1) + { + return upper; + } + return p * (upper - lower) + lower; + } // RealType quantile(const uniform_distribution<RealType, Policy>& dist, const RealType& p) + + template <class RealType, class Policy> + inline RealType cdf(const complemented2_type<uniform_distribution<RealType, Policy>, RealType>& c) + { + RealType lower = c.dist.lower(); + RealType upper = c.dist.upper(); + RealType x = c.param; + RealType result; // of checks. + if(false == detail::check_uniform("boost::math::cdf(const uniform_distribution<%1%>&, %1%)", lower, upper, &result, Policy())) + { + return result; + } + if(false == detail::check_uniform_x("boost::math::cdf(const uniform_distribution<%1%>&, %1%)", x, &result, Policy())) + { + return result; + } + if (x < lower) + { + return 0; + } + if (x > upper) + { + return 1; + } + return (upper - x) / (upper - lower); + } // RealType cdf(const complemented2_type<uniform_distribution<RealType, Policy>, RealType>& c) + + template <class RealType, class Policy> + inline RealType quantile(const complemented2_type<uniform_distribution<RealType, Policy>, RealType>& c) + { + RealType lower = c.dist.lower(); + RealType upper = c.dist.upper(); + RealType q = c.param; + RealType result; // of checks. + if(false == detail::check_uniform("boost::math::quantile(const uniform_distribution<%1%>&, %1%)", lower, upper, &result, Policy())) + { + return result; + } + if(false == detail::check_probability("boost::math::quantile(const uniform_distribution<%1%>&, %1%)", q, &result, Policy())) + if(q == 0) + { + return lower; + } + if(q == 1) + { + return upper; + } + return -q * (upper - lower) + upper; + } // RealType quantile(const complemented2_type<uniform_distribution<RealType, Policy>, RealType>& c) + + template <class RealType, class Policy> + inline RealType mean(const uniform_distribution<RealType, Policy>& dist) + { + RealType lower = dist.lower(); + RealType upper = dist.upper(); + RealType result; // of checks. + if(false == detail::check_uniform("boost::math::mean(const uniform_distribution<%1%>&)", lower, upper, &result, Policy())) + { + return result; + } + return (lower + upper ) / 2; + } // RealType mean(const uniform_distribution<RealType, Policy>& dist) + + template <class RealType, class Policy> + inline RealType variance(const uniform_distribution<RealType, Policy>& dist) + { + RealType lower = dist.lower(); + RealType upper = dist.upper(); + RealType result; // of checks. + if(false == detail::check_uniform("boost::math::variance(const uniform_distribution<%1%>&)", lower, upper, &result, Policy())) + { + return result; + } + return (upper - lower) * ( upper - lower) / 12; + // for standard uniform = 0.833333333333333333333333333333333333333333; + } // RealType variance(const uniform_distribution<RealType, Policy>& dist) + + template <class RealType, class Policy> + inline RealType mode(const uniform_distribution<RealType, Policy>& dist) + { + RealType lower = dist.lower(); + RealType upper = dist.upper(); + RealType result; // of checks. + if(false == detail::check_uniform("boost::math::mode(const uniform_distribution<%1%>&)", lower, upper, &result, Policy())) + { + return result; + } + result = lower; // Any value [lower, upper] but arbitrarily choose lower. + return result; + } + + template <class RealType, class Policy> + inline RealType median(const uniform_distribution<RealType, Policy>& dist) + { + RealType lower = dist.lower(); + RealType upper = dist.upper(); + RealType result; // of checks. + if(false == detail::check_uniform("boost::math::median(const uniform_distribution<%1%>&)", lower, upper, &result, Policy())) + { + return result; + } + return (lower + upper) / 2; // + } + template <class RealType, class Policy> + inline RealType skewness(const uniform_distribution<RealType, Policy>& dist) + { + RealType lower = dist.lower(); + RealType upper = dist.upper(); + RealType result; // of checks. + if(false == detail::check_uniform("boost::math::skewness(const uniform_distribution<%1%>&)",lower, upper, &result, Policy())) + { + return result; + } + return 0; + } // RealType skewness(const uniform_distribution<RealType, Policy>& dist) + + template <class RealType, class Policy> + inline RealType kurtosis_excess(const uniform_distribution<RealType, Policy>& dist) + { + RealType lower = dist.lower(); + RealType upper = dist.upper(); + RealType result; // of checks. + if(false == detail::check_uniform("boost::math::kurtosis_execess(const uniform_distribution<%1%>&)", lower, upper, &result, Policy())) + { + return result; + } + return static_cast<RealType>(-6)/5; // -6/5 = -1.2; + } // RealType kurtosis_excess(const uniform_distribution<RealType, Policy>& dist) + + template <class RealType, class Policy> + inline RealType kurtosis(const uniform_distribution<RealType, Policy>& dist) + { + return kurtosis_excess(dist) + 3; + } + +} // namespace math +} // namespace boost + +// This include must be at the end, *after* the accessors +// for this distribution have been defined, in order to +// keep compilers that support two-phase lookup happy. +#include <boost/math/distributions/detail/derived_accessors.hpp> + +#endif // BOOST_STATS_UNIFORM_HPP + + + diff --git a/Utilities/BGL/boost/math/distributions/weibull.hpp b/Utilities/BGL/boost/math/distributions/weibull.hpp new file mode 100644 index 0000000000000000000000000000000000000000..c8eb20cefdd4faa89b621808597eb30078377afb --- /dev/null +++ b/Utilities/BGL/boost/math/distributions/weibull.hpp @@ -0,0 +1,387 @@ +// Copyright John Maddock 2006. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_STATS_WEIBULL_HPP +#define BOOST_STATS_WEIBULL_HPP + +// http://www.itl.nist.gov/div898/handbook/eda/section3/eda3668.htm +// http://mathworld.wolfram.com/WeibullDistribution.html + +#include <boost/math/distributions/fwd.hpp> +#include <boost/math/special_functions/gamma.hpp> +#include <boost/math/special_functions/log1p.hpp> +#include <boost/math/special_functions/expm1.hpp> +#include <boost/math/distributions/detail/common_error_handling.hpp> +#include <boost/math/distributions/complement.hpp> + +#include <utility> + +namespace boost{ namespace math +{ +namespace detail{ + +template <class RealType, class Policy> +inline bool check_weibull_shape( + const char* function, + RealType shape, + RealType* result, const Policy& pol) +{ + if((shape < 0) || !(boost::math::isfinite)(shape)) + { + *result = policies::raise_domain_error<RealType>( + function, + "Shape parameter is %1%, but must be > 0 !", shape, pol); + return false; + } + return true; +} + +template <class RealType, class Policy> +inline bool check_weibull_x( + const char* function, + RealType const& x, + RealType* result, const Policy& pol) +{ + if((x < 0) || !(boost::math::isfinite)(x)) + { + *result = policies::raise_domain_error<RealType>( + function, + "Random variate is %1% but must be >= 0 !", x, pol); + return false; + } + return true; +} + +template <class RealType, class Policy> +inline bool check_weibull( + const char* function, + RealType scale, + RealType shape, + RealType* result, const Policy& pol) +{ + return check_scale(function, scale, result, pol) && check_weibull_shape(function, shape, result, pol); +} + +} // namespace detail + +template <class RealType = double, class Policy = policies::policy<> > +class weibull_distribution +{ +public: + typedef RealType value_type; + typedef Policy policy_type; + + weibull_distribution(RealType shape, RealType scale = 1) + : m_shape(shape), m_scale(scale) + { + RealType result; + detail::check_weibull("boost::math::weibull_distribution<%1%>::weibull_distribution", scale, shape, &result, Policy()); + } + + RealType shape()const + { + return m_shape; + } + + RealType scale()const + { + return m_scale; + } +private: + // + // Data members: + // + RealType m_shape; // distribution shape + RealType m_scale; // distribution scale +}; + +typedef weibull_distribution<double> weibull; + +template <class RealType, class Policy> +inline const std::pair<RealType, RealType> range(const weibull_distribution<RealType, Policy>& /*dist*/) +{ // Range of permissible values for random variable x. + using boost::math::tools::max_value; + return std::pair<RealType, RealType>(0, max_value<RealType>()); +} + +template <class RealType, class Policy> +inline const std::pair<RealType, RealType> support(const weibull_distribution<RealType, Policy>& /*dist*/) +{ // Range of supported values for random variable x. + // This is range where cdf rises from 0 to 1, and outside it, the pdf is zero. + using boost::math::tools::max_value; + using boost::math::tools::min_value; + return std::pair<RealType, RealType>(min_value<RealType>(), max_value<RealType>()); + // A discontinuity at x == 0, so only support down to min_value. +} + +template <class RealType, class Policy> +inline RealType pdf(const weibull_distribution<RealType, Policy>& dist, const RealType& x) +{ + BOOST_MATH_STD_USING // for ADL of std functions + + static const char* function = "boost::math::pdf(const weibull_distribution<%1%>, %1%)"; + + RealType shape = dist.shape(); + RealType scale = dist.scale(); + + RealType result; + if(false == detail::check_weibull(function, scale, shape, &result, Policy())) + return result; + if(false == detail::check_weibull_x(function, x, &result, Policy())) + return result; + + if(x == 0) + { // Special case, but x == min, pdf = 1 for shape = 1, + return 0; + } + result = exp(-pow(x / scale, shape)); + result *= pow(x / scale, shape) * shape / x; + + return result; +} + +template <class RealType, class Policy> +inline RealType cdf(const weibull_distribution<RealType, Policy>& dist, const RealType& x) +{ + BOOST_MATH_STD_USING // for ADL of std functions + + static const char* function = "boost::math::cdf(const weibull_distribution<%1%>, %1%)"; + + RealType shape = dist.shape(); + RealType scale = dist.scale(); + + RealType result; + if(false == detail::check_weibull(function, scale, shape, &result, Policy())) + return result; + if(false == detail::check_weibull_x(function, x, &result, Policy())) + return result; + + result = -boost::math::expm1(-pow(x / scale, shape), Policy()); + + return result; +} + +template <class RealType, class Policy> +inline RealType quantile(const weibull_distribution<RealType, Policy>& dist, const RealType& p) +{ + BOOST_MATH_STD_USING // for ADL of std functions + + static const char* function = "boost::math::quantile(const weibull_distribution<%1%>, %1%)"; + + RealType shape = dist.shape(); + RealType scale = dist.scale(); + + RealType result; + if(false == detail::check_weibull(function, scale, shape, &result, Policy())) + return result; + if(false == detail::check_probability(function, p, &result, Policy())) + return result; + + if(p == 1) + return policies::raise_overflow_error<RealType>(function, 0, Policy()); + + result = scale * pow(-boost::math::log1p(-p, Policy()), 1 / shape); + + return result; +} + +template <class RealType, class Policy> +inline RealType cdf(const complemented2_type<weibull_distribution<RealType, Policy>, RealType>& c) +{ + BOOST_MATH_STD_USING // for ADL of std functions + + static const char* function = "boost::math::cdf(const weibull_distribution<%1%>, %1%)"; + + RealType shape = c.dist.shape(); + RealType scale = c.dist.scale(); + + RealType result; + if(false == detail::check_weibull(function, scale, shape, &result, Policy())) + return result; + if(false == detail::check_weibull_x(function, c.param, &result, Policy())) + return result; + + result = exp(-pow(c.param / scale, shape)); + + return result; +} + +template <class RealType, class Policy> +inline RealType quantile(const complemented2_type<weibull_distribution<RealType, Policy>, RealType>& c) +{ + BOOST_MATH_STD_USING // for ADL of std functions + + static const char* function = "boost::math::quantile(const weibull_distribution<%1%>, %1%)"; + + RealType shape = c.dist.shape(); + RealType scale = c.dist.scale(); + RealType q = c.param; + + RealType result; + if(false == detail::check_weibull(function, scale, shape, &result, Policy())) + return result; + if(false == detail::check_probability(function, q, &result, Policy())) + return result; + + if(q == 0) + return policies::raise_overflow_error<RealType>(function, 0, Policy()); + + result = scale * pow(-log(q), 1 / shape); + + return result; +} + +template <class RealType, class Policy> +inline RealType mean(const weibull_distribution<RealType, Policy>& dist) +{ + BOOST_MATH_STD_USING // for ADL of std functions + + static const char* function = "boost::math::mean(const weibull_distribution<%1%>)"; + + RealType shape = dist.shape(); + RealType scale = dist.scale(); + + RealType result; + if(false == detail::check_weibull(function, scale, shape, &result, Policy())) + return result; + + result = scale * boost::math::tgamma(1 + 1 / shape, Policy()); + return result; +} + +template <class RealType, class Policy> +inline RealType variance(const weibull_distribution<RealType, Policy>& dist) +{ + RealType shape = dist.shape(); + RealType scale = dist.scale(); + + static const char* function = "boost::math::variance(const weibull_distribution<%1%>)"; + + RealType result; + if(false == detail::check_weibull(function, scale, shape, &result, Policy())) + { + return result; + } + result = boost::math::tgamma(1 + 1 / shape, Policy()); + result *= -result; + result += boost::math::tgamma(1 + 2 / shape, Policy()); + result *= scale * scale; + return result; +} + +template <class RealType, class Policy> +inline RealType mode(const weibull_distribution<RealType, Policy>& dist) +{ + BOOST_MATH_STD_USING // for ADL of std function pow. + + static const char* function = "boost::math::mode(const weibull_distribution<%1%>)"; + + RealType shape = dist.shape(); + RealType scale = dist.scale(); + + RealType result; + if(false == detail::check_weibull(function, scale, shape, &result, Policy())) + { + return result; + } + if(shape <= 1) + return 0; + result = scale * pow((shape - 1) / shape, 1 / shape); + return result; +} + +template <class RealType, class Policy> +inline RealType median(const weibull_distribution<RealType, Policy>& dist) +{ + BOOST_MATH_STD_USING // for ADL of std function pow. + + static const char* function = "boost::math::median(const weibull_distribution<%1%>)"; + + RealType shape = dist.shape(); // Wikipedia k + RealType scale = dist.scale(); // Wikipedia lambda + + RealType result; + if(false == detail::check_weibull(function, scale, shape, &result, Policy())) + { + return result; + } + using boost::math::constants::ln_two; + result = scale * pow(ln_two<RealType>(), 1 / shape); + return result; +} + +template <class RealType, class Policy> +inline RealType skewness(const weibull_distribution<RealType, Policy>& dist) +{ + BOOST_MATH_STD_USING // for ADL of std functions + + static const char* function = "boost::math::skewness(const weibull_distribution<%1%>)"; + + RealType shape = dist.shape(); + RealType scale = dist.scale(); + + RealType result; + if(false == detail::check_weibull(function, scale, shape, &result, Policy())) + { + return result; + } + RealType g1, g2, g3, d; + + g1 = boost::math::tgamma(1 + 1 / shape, Policy()); + g2 = boost::math::tgamma(1 + 2 / shape, Policy()); + g3 = boost::math::tgamma(1 + 3 / shape, Policy()); + d = pow(g2 - g1 * g1, RealType(1.5)); + + result = (2 * g1 * g1 * g1 - 3 * g1 * g2 + g3) / d; + return result; +} + +template <class RealType, class Policy> +inline RealType kurtosis_excess(const weibull_distribution<RealType, Policy>& dist) +{ + BOOST_MATH_STD_USING // for ADL of std functions + + static const char* function = "boost::math::kurtosis_excess(const weibull_distribution<%1%>)"; + + RealType shape = dist.shape(); + RealType scale = dist.scale(); + + RealType result; + if(false == detail::check_weibull(function, scale, shape, &result, Policy())) + return result; + + RealType g1, g2, g3, g4, d, g1_2, g1_4; + + g1 = boost::math::tgamma(1 + 1 / shape, Policy()); + g2 = boost::math::tgamma(1 + 2 / shape, Policy()); + g3 = boost::math::tgamma(1 + 3 / shape, Policy()); + g4 = boost::math::tgamma(1 + 4 / shape, Policy()); + g1_2 = g1 * g1; + g1_4 = g1_2 * g1_2; + d = g2 - g1_2; + d *= d; + + result = -6 * g1_4 + 12 * g1_2 * g2 - 3 * g2 * g2 - 4 * g1 * g3 + g4; + result /= d; + return result; +} + +template <class RealType, class Policy> +inline RealType kurtosis(const weibull_distribution<RealType, Policy>& dist) +{ + return kurtosis_excess(dist) + 3; +} + +} // namespace math +} // namespace boost + +// This include must be at the end, *after* the accessors +// for this distribution have been defined, in order to +// keep compilers that support two-phase lookup happy. +#include <boost/math/distributions/detail/derived_accessors.hpp> + +#endif // BOOST_STATS_WEIBULL_HPP + + diff --git a/Utilities/BGL/boost/math/octonion.hpp b/Utilities/BGL/boost/math/octonion.hpp new file mode 100644 index 0000000000000000000000000000000000000000..a985f50127aa82827e20c28e650b619dceea0efa --- /dev/null +++ b/Utilities/BGL/boost/math/octonion.hpp @@ -0,0 +1,4754 @@ +// boost octonion.hpp header file + +// (C) Copyright Hubert Holin 2001. +// 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) + +// See http://www.boost.org for updates, documentation, and revision history. + + +#ifndef BOOST_OCTONION_HPP +#define BOOST_OCTONION_HPP + +#include <boost/math/quaternion.hpp> + + +namespace boost +{ + namespace math + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + // gcc 2.95.x uses expression templates for valarray calculations, but + // the result is not conforming. We need BOOST_GET_VALARRAY to get an + // actual valarray result when we need to call a member function + #define BOOST_GET_VALARRAY(T,x) ::std::valarray<T>(x) + // gcc 2.95.x has an "std::ios" class that is similar to + // "std::ios_base", so we just use a #define + #define BOOST_IOS_BASE ::std::ios + // gcc 2.x ignores function scope using declarations, + // put them in the scope of the enclosing namespace instead: + using ::std::valarray; + using ::std::sqrt; + using ::std::cos; + using ::std::sin; + using ::std::exp; + using ::std::cosh; +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + +#define BOOST_OCTONION_ACCESSOR_GENERATOR(type) \ + type real() const \ + { \ + return(a); \ + } \ + \ + octonion<type> unreal() const \ + { \ + return( octonion<type>(static_cast<type>(0),b,c,d,e,f,g,h)); \ + } \ + \ + type R_component_1() const \ + { \ + return(a); \ + } \ + \ + type R_component_2() const \ + { \ + return(b); \ + } \ + \ + type R_component_3() const \ + { \ + return(c); \ + } \ + \ + type R_component_4() const \ + { \ + return(d); \ + } \ + \ + type R_component_5() const \ + { \ + return(e); \ + } \ + \ + type R_component_6() const \ + { \ + return(f); \ + } \ + \ + type R_component_7() const \ + { \ + return(g); \ + } \ + \ + type R_component_8() const \ + { \ + return(h); \ + } \ + \ + ::std::complex<type> C_component_1() const \ + { \ + return(::std::complex<type>(a,b)); \ + } \ + \ + ::std::complex<type> C_component_2() const \ + { \ + return(::std::complex<type>(c,d)); \ + } \ + \ + ::std::complex<type> C_component_3() const \ + { \ + return(::std::complex<type>(e,f)); \ + } \ + \ + ::std::complex<type> C_component_4() const \ + { \ + return(::std::complex<type>(g,h)); \ + } \ + \ + ::boost::math::quaternion<type> H_component_1() const \ + { \ + return(::boost::math::quaternion<type>(a,b,c,d)); \ + } \ + \ + ::boost::math::quaternion<type> H_component_2() const \ + { \ + return(::boost::math::quaternion<type>(e,f,g,h)); \ + } + + +#define BOOST_OCTONION_MEMBER_ASSIGNMENT_GENERATOR(type) \ + template<typename X> \ + octonion<type> & operator = (octonion<X> const & a_affecter) \ + { \ + a = static_cast<type>(a_affecter.R_component_1()); \ + b = static_cast<type>(a_affecter.R_component_2()); \ + c = static_cast<type>(a_affecter.R_component_3()); \ + d = static_cast<type>(a_affecter.R_component_4()); \ + e = static_cast<type>(a_affecter.R_component_5()); \ + f = static_cast<type>(a_affecter.R_component_6()); \ + g = static_cast<type>(a_affecter.R_component_7()); \ + h = static_cast<type>(a_affecter.R_component_8()); \ + \ + return(*this); \ + } \ + \ + octonion<type> & operator = (octonion<type> const & a_affecter) \ + { \ + a = a_affecter.a; \ + b = a_affecter.b; \ + c = a_affecter.c; \ + d = a_affecter.d; \ + e = a_affecter.e; \ + f = a_affecter.f; \ + g = a_affecter.g; \ + h = a_affecter.h; \ + \ + return(*this); \ + } \ + \ + octonion<type> & operator = (type const & a_affecter) \ + { \ + a = a_affecter; \ + \ + b = c = d = e = f= g = h = static_cast<type>(0); \ + \ + return(*this); \ + } \ + \ + octonion<type> & operator = (::std::complex<type> const & a_affecter) \ + { \ + a = a_affecter.real(); \ + b = a_affecter.imag(); \ + \ + c = d = e = f = g = h = static_cast<type>(0); \ + \ + return(*this); \ + } \ + \ + octonion<type> & operator = (::boost::math::quaternion<type> const & a_affecter) \ + { \ + a = a_affecter.R_component_1(); \ + b = a_affecter.R_component_2(); \ + c = a_affecter.R_component_3(); \ + d = a_affecter.R_component_4(); \ + \ + e = f = g = h = static_cast<type>(0); \ + \ + return(*this); \ + } + + +#define BOOST_OCTONION_MEMBER_DATA_GENERATOR(type) \ + type a; \ + type b; \ + type c; \ + type d; \ + type e; \ + type f; \ + type g; \ + type h; \ + + + template<typename T> + class octonion + { + public: + + typedef T value_type; + + // constructor for O seen as R^8 + // (also default constructor) + + explicit octonion( T const & requested_a = T(), + T const & requested_b = T(), + T const & requested_c = T(), + T const & requested_d = T(), + T const & requested_e = T(), + T const & requested_f = T(), + T const & requested_g = T(), + T const & requested_h = T()) + : a(requested_a), + b(requested_b), + c(requested_c), + d(requested_d), + e(requested_e), + f(requested_f), + g(requested_g), + h(requested_h) + { + // nothing to do! + } + + + // constructor for H seen as C^4 + + explicit octonion( ::std::complex<T> const & z0, + ::std::complex<T> const & z1 = ::std::complex<T>(), + ::std::complex<T> const & z2 = ::std::complex<T>(), + ::std::complex<T> const & z3 = ::std::complex<T>()) + : a(z0.real()), + b(z0.imag()), + c(z1.real()), + d(z1.imag()), + e(z2.real()), + f(z2.imag()), + g(z3.real()), + h(z3.imag()) + { + // nothing to do! + } + + + // constructor for O seen as H^2 + + explicit octonion( ::boost::math::quaternion<T> const & q0, + ::boost::math::quaternion<T> const & q1 = ::boost::math::quaternion<T>()) + : a(q0.R_component_1()), + b(q0.R_component_2()), + c(q0.R_component_3()), + d(q0.R_component_4()), + e(q1.R_component_1()), + f(q1.R_component_2()), + g(q1.R_component_3()), + h(q1.R_component_4()) + { + // nothing to do! + } + + + // UNtemplated copy constructor + // (this is taken care of by the compiler itself) + + + // templated copy constructor + + template<typename X> + explicit octonion(octonion<X> const & a_recopier) + : a(static_cast<T>(a_recopier.R_component_1())), + b(static_cast<T>(a_recopier.R_component_2())), + c(static_cast<T>(a_recopier.R_component_3())), + d(static_cast<T>(a_recopier.R_component_4())), + e(static_cast<T>(a_recopier.R_component_5())), + f(static_cast<T>(a_recopier.R_component_6())), + g(static_cast<T>(a_recopier.R_component_7())), + h(static_cast<T>(a_recopier.R_component_8())) + { + // nothing to do! + } + + + // destructor + // (this is taken care of by the compiler itself) + + + // accessors + // + // Note: Like complex number, octonions do have a meaningful notion of "real part", + // but unlike them there is no meaningful notion of "imaginary part". + // Instead there is an "unreal part" which itself is an octonion, and usually + // nothing simpler (as opposed to the complex number case). + // However, for practicallity, there are accessors for the other components + // (these are necessary for the templated copy constructor, for instance). + + BOOST_OCTONION_ACCESSOR_GENERATOR(T) + + // assignment operators + + BOOST_OCTONION_MEMBER_ASSIGNMENT_GENERATOR(T) + + // other assignment-related operators + // + // NOTE: Octonion multiplication is *NOT* commutative; + // symbolically, "q *= rhs;" means "q = q * rhs;" + // and "q /= rhs;" means "q = q * inverse_of(rhs);"; + // octonion multiplication is also *NOT* associative + + octonion<T> & operator += (T const & rhs) + { + T at = a + rhs; // exception guard + + a = at; + + return(*this); + } + + + octonion<T> & operator += (::std::complex<T> const & rhs) + { + T at = a + rhs.real(); // exception guard + T bt = b + rhs.imag(); // exception guard + + a = at; + b = bt; + + return(*this); + } + + + octonion<T> & operator += (::boost::math::quaternion<T> const & rhs) + { + T at = a + rhs.R_component_1(); // exception guard + T bt = b + rhs.R_component_2(); // exception guard + T ct = c + rhs.R_component_3(); // exception guard + T dt = d + rhs.R_component_4(); // exception guard + + a = at; + b = bt; + c = ct; + d = dt; + + return(*this); + } + + + template<typename X> + octonion<T> & operator += (octonion<X> const & rhs) + { + T at = a + static_cast<T>(rhs.R_component_1()); // exception guard + T bt = b + static_cast<T>(rhs.R_component_2()); // exception guard + T ct = c + static_cast<T>(rhs.R_component_3()); // exception guard + T dt = d + static_cast<T>(rhs.R_component_4()); // exception guard + T et = e + static_cast<T>(rhs.R_component_5()); // exception guard + T ft = f + static_cast<T>(rhs.R_component_6()); // exception guard + T gt = g + static_cast<T>(rhs.R_component_7()); // exception guard + T ht = h + static_cast<T>(rhs.R_component_8()); // exception guard + + a = at; + b = bt; + c = ct; + d = dt; + e = et; + f = ft; + g = gt; + h = ht; + + return(*this); + } + + + + octonion<T> & operator -= (T const & rhs) + { + T at = a - rhs; // exception guard + + a = at; + + return(*this); + } + + + octonion<T> & operator -= (::std::complex<T> const & rhs) + { + T at = a - rhs.real(); // exception guard + T bt = b - rhs.imag(); // exception guard + + a = at; + b = bt; + + return(*this); + } + + + octonion<T> & operator -= (::boost::math::quaternion<T> const & rhs) + { + T at = a - rhs.R_component_1(); // exception guard + T bt = b - rhs.R_component_2(); // exception guard + T ct = c - rhs.R_component_3(); // exception guard + T dt = d - rhs.R_component_4(); // exception guard + + a = at; + b = bt; + c = ct; + d = dt; + + return(*this); + } + + + template<typename X> + octonion<T> & operator -= (octonion<X> const & rhs) + { + T at = a - static_cast<T>(rhs.R_component_1()); // exception guard + T bt = b - static_cast<T>(rhs.R_component_2()); // exception guard + T ct = c - static_cast<T>(rhs.R_component_3()); // exception guard + T dt = d - static_cast<T>(rhs.R_component_4()); // exception guard + T et = e - static_cast<T>(rhs.R_component_5()); // exception guard + T ft = f - static_cast<T>(rhs.R_component_6()); // exception guard + T gt = g - static_cast<T>(rhs.R_component_7()); // exception guard + T ht = h - static_cast<T>(rhs.R_component_8()); // exception guard + + a = at; + b = bt; + c = ct; + d = dt; + e = et; + f = ft; + g = gt; + h = ht; + + return(*this); + } + + + octonion<T> & operator *= (T const & rhs) + { + T at = a * rhs; // exception guard + T bt = b * rhs; // exception guard + T ct = c * rhs; // exception guard + T dt = d * rhs; // exception guard + T et = e * rhs; // exception guard + T ft = f * rhs; // exception guard + T gt = g * rhs; // exception guard + T ht = h * rhs; // exception guard + + a = at; + b = bt; + c = ct; + d = dt; + e = et; + f = ft; + g = gt; + h = ht; + + return(*this); + } + + + octonion<T> & operator *= (::std::complex<T> const & rhs) + { + T ar = rhs.real(); + T br = rhs.imag(); + + T at = +a*ar-b*br; + T bt = +a*br+b*ar; + T ct = +c*ar+d*br; + T dt = -c*br+d*ar; + T et = +e*ar+f*br; + T ft = -e*br+f*ar; + T gt = +g*ar-h*br; + T ht = +g*br+h*ar; + + a = at; + b = bt; + c = ct; + d = dt; + e = et; + f = ft; + g = gt; + h = ht; + + return(*this); + } + + + octonion<T> & operator *= (::boost::math::quaternion<T> const & rhs) + { + T ar = rhs.R_component_1(); + T br = rhs.R_component_2(); + T cr = rhs.R_component_2(); + T dr = rhs.R_component_2(); + + T at = +a*ar-b*br-c*cr-d*dr; + T bt = +a*br+b*ar+c*dr-d*cr; + T ct = +a*cr-b*dr+c*ar+d*br; + T dt = +a*dr+b*cr-c*br+d*ar; + T et = +e*ar+f*br+g*cr+h*dr; + T ft = -e*br+f*ar-g*dr+h*cr; + T gt = -e*cr+f*dr+g*ar-h*br; + T ht = -e*dr-f*cr+g*br+h*ar; + + a = at; + b = bt; + c = ct; + d = dt; + e = et; + f = ft; + g = gt; + h = ht; + + return(*this); + } + + + template<typename X> + octonion<T> & operator *= (octonion<X> const & rhs) + { + T ar = static_cast<T>(rhs.R_component_1()); + T br = static_cast<T>(rhs.R_component_2()); + T cr = static_cast<T>(rhs.R_component_3()); + T dr = static_cast<T>(rhs.R_component_4()); + T er = static_cast<T>(rhs.R_component_5()); + T fr = static_cast<T>(rhs.R_component_6()); + T gr = static_cast<T>(rhs.R_component_7()); + T hr = static_cast<T>(rhs.R_component_8()); + + T at = +a*ar-b*br-c*cr-d*dr-e*er-f*fr-g*gr-h*hr; + T bt = +a*br+b*ar+c*dr-d*cr+e*fr-f*er-g*hr+h*gr; + T ct = +a*cr-b*dr+c*ar+d*br+e*gr+f*hr-g*er-h*fr; + T dt = +a*dr+b*cr-c*br+d*ar+e*hr-f*gr+g*fr-h*er; + T et = +a*er-b*fr-c*gr-d*hr+e*ar+f*br+g*cr+h*dr; + T ft = +a*fr+b*er-c*hr+d*gr-e*br+f*ar-g*dr+h*cr; + T gt = +a*gr+b*hr+c*er-d*fr-e*cr+f*dr+g*ar-h*br; + T ht = +a*hr-b*gr+c*fr+d*er-e*dr-f*cr+g*br+h*ar; + + a = at; + b = bt; + c = ct; + d = dt; + e = et; + f = ft; + g = gt; + h = ht; + + return(*this); + } + + + octonion<T> & operator /= (T const & rhs) + { + T at = a / rhs; // exception guard + T bt = b / rhs; // exception guard + T ct = c / rhs; // exception guard + T dt = d / rhs; // exception guard + T et = e / rhs; // exception guard + T ft = f / rhs; // exception guard + T gt = g / rhs; // exception guard + T ht = h / rhs; // exception guard + + a = at; + b = bt; + c = ct; + d = dt; + e = et; + f = ft; + g = gt; + h = ht; + + return(*this); + } + + + octonion<T> & operator /= (::std::complex<T> const & rhs) + { + T ar = rhs.real(); + T br = rhs.imag(); + + T denominator = ar*ar+br*br; + + T at = (+a*ar-b*br)/denominator; + T bt = (-a*br+b*ar)/denominator; + T ct = (+c*ar-d*br)/denominator; + T dt = (+c*br+d*ar)/denominator; + T et = (+e*ar-f*br)/denominator; + T ft = (+e*br+f*ar)/denominator; + T gt = (+g*ar+h*br)/denominator; + T ht = (+g*br+h*ar)/denominator; + + a = at; + b = bt; + c = ct; + d = dt; + e = et; + f = ft; + g = gt; + h = ht; + + return(*this); + } + + + octonion<T> & operator /= (::boost::math::quaternion<T> const & rhs) + { + T ar = rhs.R_component_1(); + T br = rhs.R_component_2(); + T cr = rhs.R_component_2(); + T dr = rhs.R_component_2(); + + T denominator = ar*ar+br*br+cr*cr+dr*dr; + + T at = (+a*ar+b*br+c*cr+d*dr)/denominator; + T bt = (-a*br+b*ar-c*dr+d*cr)/denominator; + T ct = (-a*cr+b*dr+c*ar-d*br)/denominator; + T dt = (-a*dr-b*cr+c*br+d*ar)/denominator; + T et = (+e*ar-f*br-g*cr-h*dr)/denominator; + T ft = (+e*br+f*ar+g*dr-h*cr)/denominator; + T gt = (+e*cr-f*dr+g*ar+h*br)/denominator; + T ht = (+e*dr+f*cr-g*br+h*ar)/denominator; + + a = at; + b = bt; + c = ct; + d = dt; + e = et; + f = ft; + g = gt; + h = ht; + + return(*this); + } + + + template<typename X> + octonion<T> & operator /= (octonion<X> const & rhs) + { + T ar = static_cast<T>(rhs.R_component_1()); + T br = static_cast<T>(rhs.R_component_2()); + T cr = static_cast<T>(rhs.R_component_3()); + T dr = static_cast<T>(rhs.R_component_4()); + T er = static_cast<T>(rhs.R_component_5()); + T fr = static_cast<T>(rhs.R_component_6()); + T gr = static_cast<T>(rhs.R_component_7()); + T hr = static_cast<T>(rhs.R_component_8()); + + T denominator = ar*ar+br*br+cr*cr+dr*dr+er*er+fr*fr+gr*gr+hr*hr; + + T at = (+a*ar+b*br+c*cr+d*dr+e*er+f*fr+g*gr+h*hr)/denominator; + T bt = (-a*br+b*ar-c*dr+d*cr-e*fr+f*er+g*hr-h*gr)/denominator; + T ct = (-a*cr+b*dr+c*ar-d*br-e*gr-f*hr+g*er+h*fr)/denominator; + T dt = (-a*dr-b*cr+c*br+d*ar-e*hr+f*gr-g*fr+h*er)/denominator; + T et = (-a*er+b*fr+c*gr+d*hr+e*ar-f*br-g*cr-h*dr)/denominator; + T ft = (-a*fr-b*er+c*hr-d*gr+e*br+f*ar+g*dr-h*cr)/denominator; + T gt = (-a*gr-b*hr-c*er+d*fr+e*cr-f*dr+g*ar+h*br)/denominator; + T ht = (-a*hr+b*gr-c*fr-d*er+e*dr+f*cr-g*br+h*ar)/denominator; + + a = at; + b = bt; + c = ct; + d = dt; + e = et; + f = ft; + g = gt; + h = ht; + + return(*this); + } + + + protected: + + BOOST_OCTONION_MEMBER_DATA_GENERATOR(T) + + + private: + + }; + + + // declaration of octonion specialization + + template<> class octonion<float>; + template<> class octonion<double>; + template<> class octonion<long double>; + + + // helper templates for converting copy constructors (declaration) + + namespace detail + { + + template< typename T, + typename U + > + octonion<T> octonion_type_converter(octonion<U> const & rhs); + } + + + // implementation of octonion specialization + + +#define BOOST_OCTONION_CONSTRUCTOR_GENERATOR(type) \ + explicit octonion( type const & requested_a = static_cast<type>(0), \ + type const & requested_b = static_cast<type>(0), \ + type const & requested_c = static_cast<type>(0), \ + type const & requested_d = static_cast<type>(0), \ + type const & requested_e = static_cast<type>(0), \ + type const & requested_f = static_cast<type>(0), \ + type const & requested_g = static_cast<type>(0), \ + type const & requested_h = static_cast<type>(0)) \ + : a(requested_a), \ + b(requested_b), \ + c(requested_c), \ + d(requested_d), \ + e(requested_e), \ + f(requested_f), \ + g(requested_g), \ + h(requested_h) \ + { \ + } \ + \ + explicit octonion( ::std::complex<type> const & z0, \ + ::std::complex<type> const & z1 = ::std::complex<type>(), \ + ::std::complex<type> const & z2 = ::std::complex<type>(), \ + ::std::complex<type> const & z3 = ::std::complex<type>()) \ + : a(z0.real()), \ + b(z0.imag()), \ + c(z1.real()), \ + d(z1.imag()), \ + e(z2.real()), \ + f(z2.imag()), \ + g(z3.real()), \ + h(z3.imag()) \ + { \ + } \ + \ + explicit octonion( ::boost::math::quaternion<type> const & q0, \ + ::boost::math::quaternion<type> const & q1 = ::boost::math::quaternion<type>()) \ + : a(q0.R_component_1()), \ + b(q0.R_component_2()), \ + c(q0.R_component_3()), \ + d(q0.R_component_4()), \ + e(q1.R_component_1()), \ + f(q1.R_component_2()), \ + g(q1.R_component_3()), \ + h(q1.R_component_4()) \ + { \ + } + + +#define BOOST_OCTONION_MEMBER_ADD_GENERATOR_1(type) \ + octonion<type> & operator += (type const & rhs) \ + { \ + a += rhs; \ + \ + return(*this); \ + } + +#define BOOST_OCTONION_MEMBER_ADD_GENERATOR_2(type) \ + octonion<type> & operator += (::std::complex<type> const & rhs) \ + { \ + a += rhs.real(); \ + b += rhs.imag(); \ + \ + return(*this); \ + } + +#define BOOST_OCTONION_MEMBER_ADD_GENERATOR_3(type) \ + octonion<type> & operator += (::boost::math::quaternion<type> const & rhs) \ + { \ + a += rhs.R_component_1(); \ + b += rhs.R_component_2(); \ + c += rhs.R_component_3(); \ + d += rhs.R_component_4(); \ + \ + return(*this); \ + } + +#define BOOST_OCTONION_MEMBER_ADD_GENERATOR_4(type) \ + template<typename X> \ + octonion<type> & operator += (octonion<X> const & rhs) \ + { \ + a += static_cast<type>(rhs.R_component_1()); \ + b += static_cast<type>(rhs.R_component_2()); \ + c += static_cast<type>(rhs.R_component_3()); \ + d += static_cast<type>(rhs.R_component_4()); \ + e += static_cast<type>(rhs.R_component_5()); \ + f += static_cast<type>(rhs.R_component_6()); \ + g += static_cast<type>(rhs.R_component_7()); \ + h += static_cast<type>(rhs.R_component_8()); \ + \ + return(*this); \ + } + +#define BOOST_OCTONION_MEMBER_SUB_GENERATOR_1(type) \ + octonion<type> & operator -= (type const & rhs) \ + { \ + a -= rhs; \ + \ + return(*this); \ + } + +#define BOOST_OCTONION_MEMBER_SUB_GENERATOR_2(type) \ + octonion<type> & operator -= (::std::complex<type> const & rhs) \ + { \ + a -= rhs.real(); \ + b -= rhs.imag(); \ + \ + return(*this); \ + } + +#define BOOST_OCTONION_MEMBER_SUB_GENERATOR_3(type) \ + octonion<type> & operator -= (::boost::math::quaternion<type> const & rhs) \ + { \ + a -= rhs.R_component_1(); \ + b -= rhs.R_component_2(); \ + c -= rhs.R_component_3(); \ + d -= rhs.R_component_4(); \ + \ + return(*this); \ + } + +#define BOOST_OCTONION_MEMBER_SUB_GENERATOR_4(type) \ + template<typename X> \ + octonion<type> & operator -= (octonion<X> const & rhs) \ + { \ + a -= static_cast<type>(rhs.R_component_1()); \ + b -= static_cast<type>(rhs.R_component_2()); \ + c -= static_cast<type>(rhs.R_component_3()); \ + d -= static_cast<type>(rhs.R_component_4()); \ + e -= static_cast<type>(rhs.R_component_5()); \ + f -= static_cast<type>(rhs.R_component_6()); \ + g -= static_cast<type>(rhs.R_component_7()); \ + h -= static_cast<type>(rhs.R_component_8()); \ + \ + return(*this); \ + } + +#define BOOST_OCTONION_MEMBER_MUL_GENERATOR_1(type) \ + octonion<type> & operator *= (type const & rhs) \ + { \ + a *= rhs; \ + b *= rhs; \ + c *= rhs; \ + d *= rhs; \ + e *= rhs; \ + f *= rhs; \ + g *= rhs; \ + h *= rhs; \ + \ + return(*this); \ + } + +#define BOOST_OCTONION_MEMBER_MUL_GENERATOR_2(type) \ + octonion<type> & operator *= (::std::complex<type> const & rhs) \ + { \ + type ar = rhs.real(); \ + type br = rhs.imag(); \ + \ + type at = +a*ar-b*br; \ + type bt = +a*br+b*ar; \ + type ct = +c*ar+d*br; \ + type dt = -c*br+d*ar; \ + type et = +e*ar+f*br; \ + type ft = -e*br+f*ar; \ + type gt = +g*ar-h*br; \ + type ht = +g*br+h*ar; \ + \ + a = at; \ + b = bt; \ + c = ct; \ + d = dt; \ + e = et; \ + f = ft; \ + g = gt; \ + h = ht; \ + \ + return(*this); \ + } + +#define BOOST_OCTONION_MEMBER_MUL_GENERATOR_3(type) \ + octonion<type> & operator *= (::boost::math::quaternion<type> const & rhs) \ + { \ + type ar = rhs.R_component_1(); \ + type br = rhs.R_component_2(); \ + type cr = rhs.R_component_2(); \ + type dr = rhs.R_component_2(); \ + \ + type at = +a*ar-b*br-c*cr-d*dr; \ + type bt = +a*br+b*ar+c*dr-d*cr; \ + type ct = +a*cr-b*dr+c*ar+d*br; \ + type dt = +a*dr+b*cr-c*br+d*ar; \ + type et = +e*ar+f*br+g*cr+h*dr; \ + type ft = -e*br+f*ar-g*dr+h*cr; \ + type gt = -e*cr+f*dr+g*ar-h*br; \ + type ht = -e*dr-f*cr+g*br+h*ar; \ + \ + a = at; \ + b = bt; \ + c = ct; \ + d = dt; \ + e = et; \ + f = ft; \ + g = gt; \ + h = ht; \ + \ + return(*this); \ + } + +#define BOOST_OCTONION_MEMBER_MUL_GENERATOR_4(type) \ + template<typename X> \ + octonion<type> & operator *= (octonion<X> const & rhs) \ + { \ + type ar = static_cast<type>(rhs.R_component_1()); \ + type br = static_cast<type>(rhs.R_component_2()); \ + type cr = static_cast<type>(rhs.R_component_3()); \ + type dr = static_cast<type>(rhs.R_component_4()); \ + type er = static_cast<type>(rhs.R_component_5()); \ + type fr = static_cast<type>(rhs.R_component_6()); \ + type gr = static_cast<type>(rhs.R_component_7()); \ + type hr = static_cast<type>(rhs.R_component_8()); \ + \ + type at = +a*ar-b*br-c*cr-d*dr-e*er-f*fr-g*gr-h*hr; \ + type bt = +a*br+b*ar+c*dr-d*cr+e*fr-f*er-g*hr+h*gr; \ + type ct = +a*cr-b*dr+c*ar+d*br+e*gr+f*hr-g*er-h*fr; \ + type dt = +a*dr+b*cr-c*br+d*ar+e*hr-f*gr+g*fr-h*er; \ + type et = +a*er-b*fr-c*gr-d*hr+e*ar+f*br+g*cr+h*dr; \ + type ft = +a*fr+b*er-c*hr+d*gr-e*br+f*ar-g*dr+h*cr; \ + type gt = +a*gr+b*hr+c*er-d*fr-e*cr+f*dr+g*ar-h*br; \ + type ht = +a*hr-b*gr+c*fr+d*er-e*dr-f*cr+g*br+h*ar; \ + \ + a = at; \ + b = bt; \ + c = ct; \ + d = dt; \ + e = et; \ + f = ft; \ + g = gt; \ + h = ht; \ + \ + return(*this); \ + } + +// There is quite a lot of repetition in the code below. This is intentional. +// The last conditional block is the normal form, and the others merely +// consist of workarounds for various compiler deficiencies. Hopefuly, when +// more compilers are conformant and we can retire support for those that are +// not, we will be able to remove the clutter. This is makes the situation +// (painfully) explicit. + +#define BOOST_OCTONION_MEMBER_DIV_GENERATOR_1(type) \ + octonion<type> & operator /= (type const & rhs) \ + { \ + a /= rhs; \ + b /= rhs; \ + c /= rhs; \ + d /= rhs; \ + \ + return(*this); \ + } + +#if defined(__GNUC__) && (__GNUC__ < 3) + #define BOOST_OCTONION_MEMBER_DIV_GENERATOR_2(type) \ + octonion<type> & operator /= (::std::complex<type> const & rhs) \ + { \ + using ::std::valarray; \ + \ + valarray<type> tr(2); \ + \ + tr[0] = rhs.real(); \ + tr[1] = rhs.imag(); \ + \ + type mixam = (BOOST_GET_VALARRAY(type,static_cast<type>(1)/abs(tr)).max)(); \ + \ + tr *= mixam; \ + \ + valarray<type> tt(8); \ + \ + tt[0] = +a*tr[0]-b*tr[1]; \ + tt[1] = -a*tr[1]+b*tr[0]; \ + tt[2] = +c*tr[0]-d*tr[1]; \ + tt[3] = +c*tr[1]+d*tr[0]; \ + tt[4] = +e*tr[0]-f*tr[1]; \ + tt[5] = +e*tr[1]+f*tr[0]; \ + tt[6] = +g*tr[0]+h*tr[1]; \ + tt[7] = +g*tr[1]+h*tr[0]; \ + \ + tr *= tr; \ + \ + tt *= (mixam/tr.sum()); \ + \ + a = tt[0]; \ + b = tt[1]; \ + c = tt[2]; \ + d = tt[3]; \ + e = tt[4]; \ + f = tt[5]; \ + g = tt[6]; \ + h = tt[7]; \ + \ + return(*this); \ + } +#elif defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP) + #define BOOST_OCTONION_MEMBER_DIV_GENERATOR_2(type) \ + octonion<type> & operator /= (::std::complex<type> const & rhs) \ + { \ + using ::std::valarray; \ + using ::std::abs; \ + \ + valarray<type> tr(2); \ + \ + tr[0] = rhs.real(); \ + tr[1] = rhs.imag(); \ + \ + type mixam = static_cast<type>(1)/(abs(tr).max)(); \ + \ + tr *= mixam; \ + \ + valarray<type> tt(8); \ + \ + tt[0] = +a*tr[0]-b*tr[1]; \ + tt[1] = -a*tr[1]+b*tr[0]; \ + tt[2] = +c*tr[0]-d*tr[1]; \ + tt[3] = +c*tr[1]+d*tr[0]; \ + tt[4] = +e*tr[0]-f*tr[1]; \ + tt[5] = +e*tr[1]+f*tr[0]; \ + tt[6] = +g*tr[0]+h*tr[1]; \ + tt[7] = +g*tr[1]+h*tr[0]; \ + \ + tr *= tr; \ + \ + tt *= (mixam/tr.sum()); \ + \ + a = tt[0]; \ + b = tt[1]; \ + c = tt[2]; \ + d = tt[3]; \ + e = tt[4]; \ + f = tt[5]; \ + g = tt[6]; \ + h = tt[7]; \ + \ + return(*this); \ + } +#else + #define BOOST_OCTONION_MEMBER_DIV_GENERATOR_2(type) \ + octonion<type> & operator /= (::std::complex<type> const & rhs) \ + { \ + using ::std::valarray; \ + \ + valarray<type> tr(2); \ + \ + tr[0] = rhs.real(); \ + tr[1] = rhs.imag(); \ + \ + type mixam = static_cast<type>(1)/(abs(tr).max)(); \ + \ + tr *= mixam; \ + \ + valarray<type> tt(8); \ + \ + tt[0] = +a*tr[0]-b*tr[1]; \ + tt[1] = -a*tr[1]+b*tr[0]; \ + tt[2] = +c*tr[0]-d*tr[1]; \ + tt[3] = +c*tr[1]+d*tr[0]; \ + tt[4] = +e*tr[0]-f*tr[1]; \ + tt[5] = +e*tr[1]+f*tr[0]; \ + tt[6] = +g*tr[0]+h*tr[1]; \ + tt[7] = +g*tr[1]+h*tr[0]; \ + \ + tr *= tr; \ + \ + tt *= (mixam/tr.sum()); \ + \ + a = tt[0]; \ + b = tt[1]; \ + c = tt[2]; \ + d = tt[3]; \ + e = tt[4]; \ + f = tt[5]; \ + g = tt[6]; \ + h = tt[7]; \ + \ + return(*this); \ + } +#endif /* defined(__GNUC__) && (__GNUC__ < 3) */ /* BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP */ + +#if defined(__GNUC__) && (__GNUC__ < 3) + #define BOOST_OCTONION_MEMBER_DIV_GENERATOR_3(type) \ + octonion<type> & operator /= (::boost::math::quaternion<type> const & rhs) \ + { \ + using ::std::valarray; \ + \ + valarray<type> tr(4); \ + \ + tr[0] = static_cast<type>(rhs.R_component_1()); \ + tr[1] = static_cast<type>(rhs.R_component_2()); \ + tr[2] = static_cast<type>(rhs.R_component_3()); \ + tr[3] = static_cast<type>(rhs.R_component_4()); \ + \ + type mixam = (BOOST_GET_VALARRAY(type,static_cast<type>(1)/abs(tr)).max)();\ + \ + tr *= mixam; \ + \ + valarray<type> tt(8); \ + \ + tt[0] = +a*tr[0]+b*tr[1]+c*tr[2]+d*tr[3]; \ + tt[1] = -a*tr[1]+b*tr[0]-c*tr[3]+d*tr[2]; \ + tt[2] = -a*tr[2]+b*tr[3]+c*tr[0]-d*tr[1]; \ + tt[3] = -a*tr[3]-b*tr[2]+c*tr[1]+d*tr[0]; \ + tt[4] = +e*tr[0]-f*tr[1]-g*tr[2]-h*tr[3]; \ + tt[5] = +e*tr[1]+f*tr[0]+g*tr[3]-h*tr[2]; \ + tt[6] = +e*tr[2]-f*tr[3]+g*tr[0]+h*tr[1]; \ + tt[7] = +e*tr[3]+f*tr[2]-g*tr[1]+h*tr[0]; \ + \ + tr *= tr; \ + \ + tt *= (mixam/tr.sum()); \ + \ + a = tt[0]; \ + b = tt[1]; \ + c = tt[2]; \ + d = tt[3]; \ + e = tt[4]; \ + f = tt[5]; \ + g = tt[6]; \ + h = tt[7]; \ + \ + return(*this); \ + } +#elif defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP) + #define BOOST_OCTONION_MEMBER_DIV_GENERATOR_3(type) \ + octonion<type> & operator /= (::boost::math::quaternion<type> const & rhs) \ + { \ + using ::std::valarray; \ + using ::std::abs; \ + \ + valarray<type> tr(4); \ + \ + tr[0] = static_cast<type>(rhs.R_component_1()); \ + tr[1] = static_cast<type>(rhs.R_component_2()); \ + tr[2] = static_cast<type>(rhs.R_component_3()); \ + tr[3] = static_cast<type>(rhs.R_component_4()); \ + \ + type mixam = static_cast<type>(1)/(abs(tr).max)(); \ + \ + tr *= mixam; \ + \ + valarray<type> tt(8); \ + \ + tt[0] = +a*tr[0]+b*tr[1]+c*tr[2]+d*tr[3]; \ + tt[1] = -a*tr[1]+b*tr[0]-c*tr[3]+d*tr[2]; \ + tt[2] = -a*tr[2]+b*tr[3]+c*tr[0]-d*tr[1]; \ + tt[3] = -a*tr[3]-b*tr[2]+c*tr[1]+d*tr[0]; \ + tt[4] = +e*tr[0]-f*tr[1]-g*tr[2]-h*tr[3]; \ + tt[5] = +e*tr[1]+f*tr[0]+g*tr[3]-h*tr[2]; \ + tt[6] = +e*tr[2]-f*tr[3]+g*tr[0]+h*tr[1]; \ + tt[7] = +e*tr[3]+f*tr[2]-g*tr[1]+h*tr[0]; \ + \ + tr *= tr; \ + \ + tt *= (mixam/tr.sum()); \ + \ + a = tt[0]; \ + b = tt[1]; \ + c = tt[2]; \ + d = tt[3]; \ + e = tt[4]; \ + f = tt[5]; \ + g = tt[6]; \ + h = tt[7]; \ + \ + return(*this); \ + } +#else + #define BOOST_OCTONION_MEMBER_DIV_GENERATOR_3(type) \ + octonion<type> & operator /= (::boost::math::quaternion<type> const & rhs) \ + { \ + using ::std::valarray; \ + \ + valarray<type> tr(4); \ + \ + tr[0] = static_cast<type>(rhs.R_component_1()); \ + tr[1] = static_cast<type>(rhs.R_component_2()); \ + tr[2] = static_cast<type>(rhs.R_component_3()); \ + tr[3] = static_cast<type>(rhs.R_component_4()); \ + \ + type mixam = static_cast<type>(1)/(abs(tr).max)(); \ + \ + tr *= mixam; \ + \ + valarray<type> tt(8); \ + \ + tt[0] = +a*tr[0]+b*tr[1]+c*tr[2]+d*tr[3]; \ + tt[1] = -a*tr[1]+b*tr[0]-c*tr[3]+d*tr[2]; \ + tt[2] = -a*tr[2]+b*tr[3]+c*tr[0]-d*tr[1]; \ + tt[3] = -a*tr[3]-b*tr[2]+c*tr[1]+d*tr[0]; \ + tt[4] = +e*tr[0]-f*tr[1]-g*tr[2]-h*tr[3]; \ + tt[5] = +e*tr[1]+f*tr[0]+g*tr[3]-h*tr[2]; \ + tt[6] = +e*tr[2]-f*tr[3]+g*tr[0]+h*tr[1]; \ + tt[7] = +e*tr[3]+f*tr[2]-g*tr[1]+h*tr[0]; \ + \ + tr *= tr; \ + \ + tt *= (mixam/tr.sum()); \ + \ + a = tt[0]; \ + b = tt[1]; \ + c = tt[2]; \ + d = tt[3]; \ + e = tt[4]; \ + f = tt[5]; \ + g = tt[6]; \ + h = tt[7]; \ + \ + return(*this); \ + } +#endif /* defined(__GNUC__) && (__GNUC__ < 3) */ /* BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP */ + +#if defined(__GNUC__) && (__GNUC__ < 3) + #define BOOST_OCTONION_MEMBER_DIV_GENERATOR_4(type) \ + template<typename X> \ + octonion<type> & operator /= (octonion<X> const & rhs) \ + { \ + using ::std::valarray; \ + \ + valarray<type> tr(8); \ + \ + tr[0] = static_cast<type>(rhs.R_component_1()); \ + tr[1] = static_cast<type>(rhs.R_component_2()); \ + tr[2] = static_cast<type>(rhs.R_component_3()); \ + tr[3] = static_cast<type>(rhs.R_component_4()); \ + tr[4] = static_cast<type>(rhs.R_component_5()); \ + tr[5] = static_cast<type>(rhs.R_component_6()); \ + tr[6] = static_cast<type>(rhs.R_component_7()); \ + tr[7] = static_cast<type>(rhs.R_component_8()); \ + \ + type mixam = (BOOST_GET_VALARRAY(type,static_cast<type>(1)/abs(tr)).max)();\ + \ + tr *= mixam; \ + \ + valarray<type> tt(8); \ + \ + tt[0] = +a*tr[0]+b*tr[1]+c*tr[2]+d*tr[3]+e*tr[4]+f*tr[5]+g*tr[6]+h*tr[7]; \ + tt[1] = -a*tr[1]+b*tr[0]-c*tr[3]+d*tr[2]-e*tr[5]+f*tr[4]+g*tr[7]-h*tr[6]; \ + tt[2] = -a*tr[2]+b*tr[3]+c*tr[0]-d*tr[1]-e*tr[6]-f*tr[7]+g*tr[4]+h*tr[5]; \ + tt[3] = -a*tr[3]-b*tr[2]+c*tr[1]+d*tr[0]-e*tr[7]+f*tr[6]-g*tr[5]+h*tr[4]; \ + tt[4] = -a*tr[4]+b*tr[5]+c*tr[6]+d*tr[7]+e*tr[0]-f*tr[1]-g*tr[2]-h*tr[3]; \ + tt[5] = -a*tr[5]-b*tr[4]+c*tr[7]-d*tr[6]+e*tr[1]+f*tr[0]+g*tr[3]-h*tr[2]; \ + tt[6] = -a*tr[6]-b*tr[7]-c*tr[4]+d*tr[5]+e*tr[2]-f*tr[3]+g*tr[0]+h*tr[1]; \ + tt[7] = -a*tr[7]+b*tr[6]-c*tr[5]-d*tr[4]+e*tr[3]+f*tr[2]-g*tr[1]+h*tr[0]; \ + \ + tr *= tr; \ + \ + tt *= (mixam/tr.sum()); \ + \ + a = tt[0]; \ + b = tt[1]; \ + c = tt[2]; \ + d = tt[3]; \ + e = tt[4]; \ + f = tt[5]; \ + g = tt[6]; \ + h = tt[7]; \ + \ + return(*this); \ + } +#elif defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP) + #define BOOST_OCTONION_MEMBER_DIV_GENERATOR_4(type) \ + template<typename X> \ + octonion<type> & operator /= (octonion<X> const & rhs) \ + { \ + using ::std::valarray; \ + using ::std::abs; \ + \ + valarray<type> tr(8); \ + \ + tr[0] = static_cast<type>(rhs.R_component_1()); \ + tr[1] = static_cast<type>(rhs.R_component_2()); \ + tr[2] = static_cast<type>(rhs.R_component_3()); \ + tr[3] = static_cast<type>(rhs.R_component_4()); \ + tr[4] = static_cast<type>(rhs.R_component_5()); \ + tr[5] = static_cast<type>(rhs.R_component_6()); \ + tr[6] = static_cast<type>(rhs.R_component_7()); \ + tr[7] = static_cast<type>(rhs.R_component_8()); \ + \ + type mixam = static_cast<type>(1)/(abs(tr).max)(); \ + \ + tr *= mixam; \ + \ + valarray<type> tt(8); \ + \ + tt[0] = +a*tr[0]+b*tr[1]+c*tr[2]+d*tr[3]+e*tr[4]+f*tr[5]+g*tr[6]+h*tr[7]; \ + tt[1] = -a*tr[1]+b*tr[0]-c*tr[3]+d*tr[2]-e*tr[5]+f*tr[4]+g*tr[7]-h*tr[6]; \ + tt[2] = -a*tr[2]+b*tr[3]+c*tr[0]-d*tr[1]-e*tr[6]-f*tr[7]+g*tr[4]+h*tr[5]; \ + tt[3] = -a*tr[3]-b*tr[2]+c*tr[1]+d*tr[0]-e*tr[7]+f*tr[6]-g*tr[5]+h*tr[4]; \ + tt[4] = -a*tr[4]+b*tr[5]+c*tr[6]+d*tr[7]+e*tr[0]-f*tr[1]-g*tr[2]-h*tr[3]; \ + tt[5] = -a*tr[5]-b*tr[4]+c*tr[7]-d*tr[6]+e*tr[1]+f*tr[0]+g*tr[3]-h*tr[2]; \ + tt[6] = -a*tr[6]-b*tr[7]-c*tr[4]+d*tr[5]+e*tr[2]-f*tr[3]+g*tr[0]+h*tr[1]; \ + tt[7] = -a*tr[7]+b*tr[6]-c*tr[5]-d*tr[4]+e*tr[3]+f*tr[2]-g*tr[1]+h*tr[0]; \ + \ + tr *= tr; \ + \ + tt *= (mixam/tr.sum()); \ + \ + a = tt[0]; \ + b = tt[1]; \ + c = tt[2]; \ + d = tt[3]; \ + e = tt[4]; \ + f = tt[5]; \ + g = tt[6]; \ + h = tt[7]; \ + \ + return(*this); \ + } +#else + #define BOOST_OCTONION_MEMBER_DIV_GENERATOR_4(type) \ + template<typename X> \ + octonion<type> & operator /= (octonion<X> const & rhs) \ + { \ + using ::std::valarray; \ + \ + valarray<type> tr(8); \ + \ + tr[0] = static_cast<type>(rhs.R_component_1()); \ + tr[1] = static_cast<type>(rhs.R_component_2()); \ + tr[2] = static_cast<type>(rhs.R_component_3()); \ + tr[3] = static_cast<type>(rhs.R_component_4()); \ + tr[4] = static_cast<type>(rhs.R_component_5()); \ + tr[5] = static_cast<type>(rhs.R_component_6()); \ + tr[6] = static_cast<type>(rhs.R_component_7()); \ + tr[7] = static_cast<type>(rhs.R_component_8()); \ + \ + type mixam = static_cast<type>(1)/(abs(tr).max)(); \ + \ + tr *= mixam; \ + \ + valarray<type> tt(8); \ + \ + tt[0] = +a*tr[0]+b*tr[1]+c*tr[2]+d*tr[3]+e*tr[4]+f*tr[5]+g*tr[6]+h*tr[7]; \ + tt[1] = -a*tr[1]+b*tr[0]-c*tr[3]+d*tr[2]-e*tr[5]+f*tr[4]+g*tr[7]-h*tr[6]; \ + tt[2] = -a*tr[2]+b*tr[3]+c*tr[0]-d*tr[1]-e*tr[6]-f*tr[7]+g*tr[4]+h*tr[5]; \ + tt[3] = -a*tr[3]-b*tr[2]+c*tr[1]+d*tr[0]-e*tr[7]+f*tr[6]-g*tr[5]+h*tr[4]; \ + tt[4] = -a*tr[4]+b*tr[5]+c*tr[6]+d*tr[7]+e*tr[0]-f*tr[1]-g*tr[2]-h*tr[3]; \ + tt[5] = -a*tr[5]-b*tr[4]+c*tr[7]-d*tr[6]+e*tr[1]+f*tr[0]+g*tr[3]-h*tr[2]; \ + tt[6] = -a*tr[6]-b*tr[7]-c*tr[4]+d*tr[5]+e*tr[2]-f*tr[3]+g*tr[0]+h*tr[1]; \ + tt[7] = -a*tr[7]+b*tr[6]-c*tr[5]-d*tr[4]+e*tr[3]+f*tr[2]-g*tr[1]+h*tr[0]; \ + \ + tr *= tr; \ + \ + tt *= (mixam/tr.sum()); \ + \ + a = tt[0]; \ + b = tt[1]; \ + c = tt[2]; \ + d = tt[3]; \ + e = tt[4]; \ + f = tt[5]; \ + g = tt[6]; \ + h = tt[7]; \ + \ + return(*this); \ + } +#endif /* defined(__GNUC__) && (__GNUC__ < 3) */ /* BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP */ + + +#define BOOST_OCTONION_MEMBER_ADD_GENERATOR(type) \ + BOOST_OCTONION_MEMBER_ADD_GENERATOR_1(type) \ + BOOST_OCTONION_MEMBER_ADD_GENERATOR_2(type) \ + BOOST_OCTONION_MEMBER_ADD_GENERATOR_3(type) \ + BOOST_OCTONION_MEMBER_ADD_GENERATOR_4(type) + +#define BOOST_OCTONION_MEMBER_SUB_GENERATOR(type) \ + BOOST_OCTONION_MEMBER_SUB_GENERATOR_1(type) \ + BOOST_OCTONION_MEMBER_SUB_GENERATOR_2(type) \ + BOOST_OCTONION_MEMBER_SUB_GENERATOR_3(type) \ + BOOST_OCTONION_MEMBER_SUB_GENERATOR_4(type) + +#define BOOST_OCTONION_MEMBER_MUL_GENERATOR(type) \ + BOOST_OCTONION_MEMBER_MUL_GENERATOR_1(type) \ + BOOST_OCTONION_MEMBER_MUL_GENERATOR_2(type) \ + BOOST_OCTONION_MEMBER_MUL_GENERATOR_3(type) \ + BOOST_OCTONION_MEMBER_MUL_GENERATOR_4(type) + +#define BOOST_OCTONION_MEMBER_DIV_GENERATOR(type) \ + BOOST_OCTONION_MEMBER_DIV_GENERATOR_1(type) \ + BOOST_OCTONION_MEMBER_DIV_GENERATOR_2(type) \ + BOOST_OCTONION_MEMBER_DIV_GENERATOR_3(type) \ + BOOST_OCTONION_MEMBER_DIV_GENERATOR_4(type) + +#define BOOST_OCTONION_MEMBER_ALGEBRAIC_GENERATOR(type) \ + BOOST_OCTONION_MEMBER_ADD_GENERATOR(type) \ + BOOST_OCTONION_MEMBER_SUB_GENERATOR(type) \ + BOOST_OCTONION_MEMBER_MUL_GENERATOR(type) \ + BOOST_OCTONION_MEMBER_DIV_GENERATOR(type) + + + template<> + class octonion<float> + { + public: + + typedef float value_type; + + BOOST_OCTONION_CONSTRUCTOR_GENERATOR(float) + + // UNtemplated copy constructor + // (this is taken care of by the compiler itself) + + // explicit copy constructors (precision-loosing converters) + + explicit octonion(octonion<double> const & a_recopier) + { + *this = detail::octonion_type_converter<float, double>(a_recopier); + } + + explicit octonion(octonion<long double> const & a_recopier) + { + *this = detail::octonion_type_converter<float, long double>(a_recopier); + } + + // destructor + // (this is taken care of by the compiler itself) + + // accessors + // + // Note: Like complex number, octonions do have a meaningful notion of "real part", + // but unlike them there is no meaningful notion of "imaginary part". + // Instead there is an "unreal part" which itself is an octonion, and usually + // nothing simpler (as opposed to the complex number case). + // However, for practicallity, there are accessors for the other components + // (these are necessary for the templated copy constructor, for instance). + + BOOST_OCTONION_ACCESSOR_GENERATOR(float) + + // assignment operators + + BOOST_OCTONION_MEMBER_ASSIGNMENT_GENERATOR(float) + + // other assignment-related operators + // + // NOTE: Octonion multiplication is *NOT* commutative; + // symbolically, "q *= rhs;" means "q = q * rhs;" + // and "q /= rhs;" means "q = q * inverse_of(rhs);"; + // octonion multiplication is also *NOT* associative + + BOOST_OCTONION_MEMBER_ALGEBRAIC_GENERATOR(float) + + + protected: + + BOOST_OCTONION_MEMBER_DATA_GENERATOR(float) + + + private: + + }; + + + template<> + class octonion<double> + { + public: + + typedef double value_type; + + BOOST_OCTONION_CONSTRUCTOR_GENERATOR(double) + + // UNtemplated copy constructor + // (this is taken care of by the compiler itself) + + // converting copy constructor + + explicit octonion(octonion<float> const & a_recopier) + { + *this = detail::octonion_type_converter<double, float>(a_recopier); + } + + // explicit copy constructors (precision-loosing converters) + + explicit octonion(octonion<long double> const & a_recopier) + { + *this = detail::octonion_type_converter<double, long double>(a_recopier); + } + + // destructor + // (this is taken care of by the compiler itself) + + // accessors + // + // Note: Like complex number, octonions do have a meaningful notion of "real part", + // but unlike them there is no meaningful notion of "imaginary part". + // Instead there is an "unreal part" which itself is an octonion, and usually + // nothing simpler (as opposed to the complex number case). + // However, for practicallity, there are accessors for the other components + // (these are necessary for the templated copy constructor, for instance). + + BOOST_OCTONION_ACCESSOR_GENERATOR(double) + + // assignment operators + + BOOST_OCTONION_MEMBER_ASSIGNMENT_GENERATOR(double) + + // other assignment-related operators + // + // NOTE: Octonion multiplication is *NOT* commutative; + // symbolically, "q *= rhs;" means "q = q * rhs;" + // and "q /= rhs;" means "q = q * inverse_of(rhs);"; + // octonion multiplication is also *NOT* associative + + BOOST_OCTONION_MEMBER_ALGEBRAIC_GENERATOR(double) + + + protected: + + BOOST_OCTONION_MEMBER_DATA_GENERATOR(double) + + + private: + + }; + + + template<> + class octonion<long double> + { + public: + + typedef long double value_type; + + BOOST_OCTONION_CONSTRUCTOR_GENERATOR(long double) + + // UNtemplated copy constructor + // (this is taken care of by the compiler itself) + + // converting copy constructor + + explicit octonion(octonion<float> const & a_recopier) + { + *this = detail::octonion_type_converter<long double, float>(a_recopier); + } + + + explicit octonion(octonion<double> const & a_recopier) + { + *this = detail::octonion_type_converter<long double, double>(a_recopier); + } + + + // destructor + // (this is taken care of by the compiler itself) + + // accessors + // + // Note: Like complex number, octonions do have a meaningful notion of "real part", + // but unlike them there is no meaningful notion of "imaginary part". + // Instead there is an "unreal part" which itself is an octonion, and usually + // nothing simpler (as opposed to the complex number case). + // However, for practicallity, there are accessors for the other components + // (these are necessary for the templated copy constructor, for instance). + + BOOST_OCTONION_ACCESSOR_GENERATOR(long double) + + // assignment operators + + BOOST_OCTONION_MEMBER_ASSIGNMENT_GENERATOR(long double) + + // other assignment-related operators + // + // NOTE: Octonion multiplication is *NOT* commutative; + // symbolically, "q *= rhs;" means "q = q * rhs;" + // and "q /= rhs;" means "q = q * inverse_of(rhs);"; + // octonion multiplication is also *NOT* associative + + BOOST_OCTONION_MEMBER_ALGEBRAIC_GENERATOR(long double) + + + protected: + + BOOST_OCTONION_MEMBER_DATA_GENERATOR(long double) + + + private: + + }; + + +#undef BOOST_OCTONION_CONSTRUCTOR_GENERATOR + +#undef BOOST_OCTONION_MEMBER_ALGEBRAIC_GENERATOR + +#undef BOOST_OCTONION_MEMBER_ADD_GENERATOR +#undef BOOST_OCTONION_MEMBER_SUB_GENERATOR +#undef BOOST_OCTONION_MEMBER_MUL_GENERATOR +#undef BOOST_OCTONION_MEMBER_DIV_GENERATOR + +#undef BOOST_OCTONION_MEMBER_ADD_GENERATOR_1 +#undef BOOST_OCTONION_MEMBER_ADD_GENERATOR_2 +#undef BOOST_OCTONION_MEMBER_ADD_GENERATOR_3 +#undef BOOST_OCTONION_MEMBER_ADD_GENERATOR_4 +#undef BOOST_OCTONION_MEMBER_SUB_GENERATOR_1 +#undef BOOST_OCTONION_MEMBER_SUB_GENERATOR_2 +#undef BOOST_OCTONION_MEMBER_SUB_GENERATOR_3 +#undef BOOST_OCTONION_MEMBER_SUB_GENERATOR_4 +#undef BOOST_OCTONION_MEMBER_MUL_GENERATOR_1 +#undef BOOST_OCTONION_MEMBER_MUL_GENERATOR_2 +#undef BOOST_OCTONION_MEMBER_MUL_GENERATOR_3 +#undef BOOST_OCTONION_MEMBER_MUL_GENERATOR_4 +#undef BOOST_OCTONION_MEMBER_DIV_GENERATOR_1 +#undef BOOST_OCTONION_MEMBER_DIV_GENERATOR_2 +#undef BOOST_OCTONION_MEMBER_DIV_GENERATOR_3 +#undef BOOST_OCTONION_MEMBER_DIV_GENERATOR_4 + + +#undef BOOST_OCTONION_MEMBER_DATA_GENERATOR + +#undef BOOST_OCTONION_MEMBER_ASSIGNMENT_GENERATOR + +#undef BOOST_OCTONION_ACCESSOR_GENERATOR + + + // operators + +#define BOOST_OCTONION_OPERATOR_GENERATOR_BODY(op) \ + { \ + octonion<T> res(lhs); \ + res op##= rhs; \ + return(res); \ + } + +#define BOOST_OCTONION_OPERATOR_GENERATOR_1_L(op) \ + template<typename T> \ + inline octonion<T> operator op (T const & lhs, octonion<T> const & rhs) \ + BOOST_OCTONION_OPERATOR_GENERATOR_BODY(op) + +#define BOOST_OCTONION_OPERATOR_GENERATOR_1_R(op) \ + template<typename T> \ + inline octonion<T> operator op (octonion<T> const & lhs, T const & rhs) \ + BOOST_OCTONION_OPERATOR_GENERATOR_BODY(op) + +#define BOOST_OCTONION_OPERATOR_GENERATOR_2_L(op) \ + template<typename T> \ + inline octonion<T> operator op (::std::complex<T> const & lhs, octonion<T> const & rhs) \ + BOOST_OCTONION_OPERATOR_GENERATOR_BODY(op) + +#define BOOST_OCTONION_OPERATOR_GENERATOR_2_R(op) \ + template<typename T> \ + inline octonion<T> operator op (octonion<T> const & lhs, ::std::complex<T> const & rhs) \ + BOOST_OCTONION_OPERATOR_GENERATOR_BODY(op) + +#define BOOST_OCTONION_OPERATOR_GENERATOR_3_L(op) \ + template<typename T> \ + inline octonion<T> operator op (::boost::math::quaternion<T> const & lhs, octonion<T> const & rhs) \ + BOOST_OCTONION_OPERATOR_GENERATOR_BODY(op) + +#define BOOST_OCTONION_OPERATOR_GENERATOR_3_R(op) \ + template<typename T> \ + inline octonion<T> operator op (octonion<T> const & lhs, ::boost::math::quaternion<T> const & rhs) \ + BOOST_OCTONION_OPERATOR_GENERATOR_BODY(op) + +#define BOOST_OCTONION_OPERATOR_GENERATOR_4(op) \ + template<typename T> \ + inline octonion<T> operator op (octonion<T> const & lhs, octonion<T> const & rhs) \ + BOOST_OCTONION_OPERATOR_GENERATOR_BODY(op) + +#define BOOST_OCTONION_OPERATOR_GENERATOR(op) \ + BOOST_OCTONION_OPERATOR_GENERATOR_1_L(op) \ + BOOST_OCTONION_OPERATOR_GENERATOR_1_R(op) \ + BOOST_OCTONION_OPERATOR_GENERATOR_2_L(op) \ + BOOST_OCTONION_OPERATOR_GENERATOR_2_R(op) \ + BOOST_OCTONION_OPERATOR_GENERATOR_3_L(op) \ + BOOST_OCTONION_OPERATOR_GENERATOR_3_R(op) \ + BOOST_OCTONION_OPERATOR_GENERATOR_4(op) + + + BOOST_OCTONION_OPERATOR_GENERATOR(+) + BOOST_OCTONION_OPERATOR_GENERATOR(-) + BOOST_OCTONION_OPERATOR_GENERATOR(*) + BOOST_OCTONION_OPERATOR_GENERATOR(/) + + +#undef BOOST_OCTONION_OPERATOR_GENERATOR + +#undef BOOST_OCTONION_OPERATOR_GENERATOR_1_L +#undef BOOST_OCTONION_OPERATOR_GENERATOR_1_R +#undef BOOST_OCTONION_OPERATOR_GENERATOR_2_L +#undef BOOST_OCTONION_OPERATOR_GENERATOR_2_R +#undef BOOST_OCTONION_OPERATOR_GENERATOR_3_L +#undef BOOST_OCTONION_OPERATOR_GENERATOR_3_R +#undef BOOST_OCTONION_OPERATOR_GENERATOR_4 + +#undef BOOST_OCTONION_OPERATOR_GENERATOR_BODY + + + template<typename T> + inline octonion<T> operator + (octonion<T> const & o) + { + return(o); + } + + + template<typename T> + inline octonion<T> operator - (octonion<T> const & o) + { + return(octonion<T>(-o.R_component_1(),-o.R_component_2(),-o.R_component_3(),-o.R_component_4(),-o.R_component_5(),-o.R_component_6(),-o.R_component_7(),-o.R_component_8())); + } + + + template<typename T> + inline bool operator == (T const & lhs, octonion<T> const & rhs) + { + return( + (rhs.R_component_1() == lhs)&& + (rhs.R_component_2() == static_cast<T>(0))&& + (rhs.R_component_3() == static_cast<T>(0))&& + (rhs.R_component_4() == static_cast<T>(0))&& + (rhs.R_component_5() == static_cast<T>(0))&& + (rhs.R_component_6() == static_cast<T>(0))&& + (rhs.R_component_7() == static_cast<T>(0))&& + (rhs.R_component_8() == static_cast<T>(0)) + ); + } + + + template<typename T> + inline bool operator == (octonion<T> const & lhs, T const & rhs) + { + return( + (lhs.R_component_1() == rhs)&& + (lhs.R_component_2() == static_cast<T>(0))&& + (lhs.R_component_3() == static_cast<T>(0))&& + (lhs.R_component_4() == static_cast<T>(0))&& + (lhs.R_component_5() == static_cast<T>(0))&& + (lhs.R_component_6() == static_cast<T>(0))&& + (lhs.R_component_7() == static_cast<T>(0))&& + (lhs.R_component_8() == static_cast<T>(0)) + ); + } + + + template<typename T> + inline bool operator == (::std::complex<T> const & lhs, octonion<T> const & rhs) + { + return( + (rhs.R_component_1() == lhs.real())&& + (rhs.R_component_2() == lhs.imag())&& + (rhs.R_component_3() == static_cast<T>(0))&& + (rhs.R_component_4() == static_cast<T>(0))&& + (rhs.R_component_5() == static_cast<T>(0))&& + (rhs.R_component_6() == static_cast<T>(0))&& + (rhs.R_component_7() == static_cast<T>(0))&& + (rhs.R_component_8() == static_cast<T>(0)) + ); + } + + + template<typename T> + inline bool operator == (octonion<T> const & lhs, ::std::complex<T> const & rhs) + { + return( + (lhs.R_component_1() == rhs.real())&& + (lhs.R_component_2() == rhs.imag())&& + (lhs.R_component_3() == static_cast<T>(0))&& + (lhs.R_component_4() == static_cast<T>(0))&& + (lhs.R_component_5() == static_cast<T>(0))&& + (lhs.R_component_6() == static_cast<T>(0))&& + (lhs.R_component_7() == static_cast<T>(0))&& + (lhs.R_component_8() == static_cast<T>(0)) + ); + } + + + template<typename T> + inline bool operator == (::boost::math::quaternion<T> const & lhs, octonion<T> const & rhs) + { + return( + (rhs.R_component_1() == lhs.R_component_1())&& + (rhs.R_component_2() == lhs.R_component_2())&& + (rhs.R_component_3() == lhs.R_component_3())&& + (rhs.R_component_4() == lhs.R_component_4())&& + (rhs.R_component_5() == static_cast<T>(0))&& + (rhs.R_component_6() == static_cast<T>(0))&& + (rhs.R_component_7() == static_cast<T>(0))&& + (rhs.R_component_8() == static_cast<T>(0)) + ); + } + + + template<typename T> + inline bool operator == (octonion<T> const & lhs, ::boost::math::quaternion<T> const & rhs) + { + return( + (lhs.R_component_1() == rhs.R_component_1())&& + (lhs.R_component_2() == rhs.R_component_2())&& + (lhs.R_component_3() == rhs.R_component_3())&& + (lhs.R_component_4() == rhs.R_component_4())&& + (lhs.R_component_5() == static_cast<T>(0))&& + (lhs.R_component_6() == static_cast<T>(0))&& + (lhs.R_component_7() == static_cast<T>(0))&& + (lhs.R_component_8() == static_cast<T>(0)) + ); + } + + + template<typename T> + inline bool operator == (octonion<T> const & lhs, octonion<T> const & rhs) + { + return( + (rhs.R_component_1() == lhs.R_component_1())&& + (rhs.R_component_2() == lhs.R_component_2())&& + (rhs.R_component_3() == lhs.R_component_3())&& + (rhs.R_component_4() == lhs.R_component_4())&& + (rhs.R_component_5() == lhs.R_component_5())&& + (rhs.R_component_6() == lhs.R_component_6())&& + (rhs.R_component_7() == lhs.R_component_7())&& + (rhs.R_component_8() == lhs.R_component_8()) + ); + } + + +#define BOOST_OCTONION_NOT_EQUAL_GENERATOR \ + { \ + return(!(lhs == rhs)); \ + } + + template<typename T> + inline bool operator != (T const & lhs, octonion<T> const & rhs) + BOOST_OCTONION_NOT_EQUAL_GENERATOR + + template<typename T> + inline bool operator != (octonion<T> const & lhs, T const & rhs) + BOOST_OCTONION_NOT_EQUAL_GENERATOR + + template<typename T> + inline bool operator != (::std::complex<T> const & lhs, octonion<T> const & rhs) + BOOST_OCTONION_NOT_EQUAL_GENERATOR + + template<typename T> + inline bool operator != (octonion<T> const & lhs, ::std::complex<T> const & rhs) + BOOST_OCTONION_NOT_EQUAL_GENERATOR + + template<typename T> + inline bool operator != (::boost::math::quaternion<T> const & lhs, octonion<T> const & rhs) + BOOST_OCTONION_NOT_EQUAL_GENERATOR + + template<typename T> + inline bool operator != (octonion<T> const & lhs, ::boost::math::quaternion<T> const & rhs) + BOOST_OCTONION_NOT_EQUAL_GENERATOR + + template<typename T> + inline bool operator != (octonion<T> const & lhs, octonion<T> const & rhs) + BOOST_OCTONION_NOT_EQUAL_GENERATOR + + #undef BOOST_OCTONION_NOT_EQUAL_GENERATOR + + + // Note: the default values in the constructors of the complex and quaternions make for + // a very complex and ambiguous situation; we have made choices to disambiguate. + +#if BOOST_WORKAROUND(__GNUC__, < 3) + template<typename T> + ::std::istream & operator >> ( ::std::istream & is, + octonion<T>& o) +#else + template<typename T, typename charT, class traits> + ::std::basic_istream<charT,traits> & operator >> ( ::std::basic_istream<charT,traits> & is, + octonion<T> & o) +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + typedef char charT; +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + +#ifdef BOOST_NO_STD_LOCALE +#else + const ::std::ctype<charT> & ct = ::std::use_facet< ::std::ctype<charT> >(is.getloc()); +#endif /* BOOST_NO_STD_LOCALE */ + + T a = T(); + T b = T(); + T c = T(); + T d = T(); + T e = T(); + T f = T(); + T g = T(); + T h = T(); + + ::std::complex<T> u = ::std::complex<T>(); + ::std::complex<T> v = ::std::complex<T>(); + ::std::complex<T> x = ::std::complex<T>(); + ::std::complex<T> y = ::std::complex<T>(); + + ::boost::math::quaternion<T> p = ::boost::math::quaternion<T>(); + ::boost::math::quaternion<T> q = ::boost::math::quaternion<T>(); + + charT ch = charT(); + char cc; + + is >> ch; // get the first lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == '(') // read "(" + { + is >> ch; // get the second lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == '(') // read "((" + { + is >> ch; // get the third lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == '(') // read "(((" + { + is.putback(ch); + + is >> u; // read "((u" + + if (!is.good()) goto finish; + + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "((u)" + { + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // format: (((a))), (((a,b))) + { + o = octonion<T>(u); + } + else if (cc == ',') // read "((u)," + { + p = ::boost::math::quaternion<T>(u); + + is >> q; // read "((u),q" + + if (!is.good()) goto finish; + + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // format: (((a)),q), (((a,b)),q) + { + o = octonion<T>(p,q); + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else if (cc ==',') // read "((u," + { + is >> v; // read "((u,v" + + if (!is.good()) goto finish; + + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "((u,v)" + { + p = ::boost::math::quaternion<T>(u,v); + + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // format: (((a),v)), (((a,b),v)) + { + o = octonion<T>(p); + } + else if (cc == ',') // read "((u,v)," + { + is >> q; // read "(p,q" + + if (!is.good()) goto finish; + + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // format: (((a),v),q), (((a,b),v),q) + { + o = octonion<T>(p,q); + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else // read "((a" + { + is.putback(ch); + + is >> a; // we extract the first component + + if (!is.good()) goto finish; + + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "((a)" + { + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "((a))" + { + o = octonion<T>(a); + } + else if (cc == ',') // read "((a)," + { + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == '(') // read "((a),(" + { + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == '(') // read "((a),((" + { + is.putback(ch); + + is.putback(ch); // we backtrack twice, with the same value! + + is >> q; // read "((a),q" + + if (!is.good()) goto finish; + + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "((a),q)" + { + p = ::boost::math::quaternion<T>(a); + + o = octonion<T>(p,q); + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else // read "((a),(c" or "((a),(e" + { + is.putback(ch); + + is >> c; + + if (!is.good()) goto finish; + + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "((a),(c)" (ambiguity resolution) + { + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "((a),(c))" + { + o = octonion<T>(a,b,c); + } + else if (cc == ',') // read "((a),(c)," + { + u = ::std::complex<T>(a); + + v = ::std::complex<T>(c); + + is >> x; // read "((a),(c),x" + + if (!is.good()) goto finish; + + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "((a),(c),x)" + { + o = octonion<T>(u,v,x); + } + else if (cc == ',') // read "((a),(c),x," + { + is >> y; // read "((a),(c),x,y" + + if (!is.good()) goto finish; + + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "((a),(c),x,y)" + { + o = octonion<T>(u,v,x,y); + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else if (cc == ',') // read "((a),(c," or "((a),(e," + { + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == '(') // read "((a),(e,(" (ambiguity resolution) + { + p = ::boost::math::quaternion<T>(a); + + x = ::std::complex<T>(c); // "c" was actually "e" + + is.putback(ch); // we can only backtrace once + + is >> y; // read "((a),(e,y" + + if (!is.good()) goto finish; + + is >> ch; // get the next lexeme + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "((a),(e,y)" + { + q = ::boost::math::quaternion<T>(x,y); + + is >> ch; // get the next lexeme + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "((a),(e,y))" + { + o = octonion<T>(p,q); + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else // read "((a),(c,d" or "((a),(e,f" + { + is.putback(ch); + + is >> d; + + if (!is.good()) goto finish; + + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "((a),(c,d)" (ambiguity resolution) + { + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "((a),(c,d))" + { + o = octonion<T>(a,b,c,d); + } + else if (cc == ',') // read "((a),(c,d)," + { + u = ::std::complex<T>(a); + + v = ::std::complex<T>(c,d); + + is >> x; // read "((a),(c,d),x" + + if (!is.good()) goto finish; + + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "((a),(c,d),x)" + { + o = octonion<T>(u,v,x); + } + else if (cc == ',') // read "((a),(c,d),x," + { + is >> y; // read "((a),(c,d),x,y" + + if (!is.good()) goto finish; + + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "((a),(c,d),x,y)" + { + o = octonion<T>(u,v,x,y); + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else if (cc == ',') // read "((a),(e,f," (ambiguity resolution) + { + p = ::boost::math::quaternion<T>(a); + + is >> g; // read "((a),(e,f,g" (too late to backtrack) + + if (!is.good()) goto finish; + + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "((a),(e,f,g)" + { + q = ::boost::math::quaternion<T>(c,d,g); // "c" was actually "e", and "d" was actually "f" + + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "((a),(e,f,g))" + { + o = octonion<T>(p,q); + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else if (cc == ',') // read "((a),(e,f,g," + { + is >> h; // read "((a),(e,f,g,h" + + if (!is.good()) goto finish; + + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "((a),(e,f,g,h)" + { + q = ::boost::math::quaternion<T>(c,d,g,h); // "c" was actually "e", and "d" was actually "f" + + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "((a),(e,f,g,h))" + { + o = octonion<T>(p,q); + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + } + else // read "((a),c" (ambiguity resolution) + { + is.putback(ch); + + is >> c; // we extract the third component + + if (!is.good()) goto finish; + + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "((a),c)" + { + o = octonion<T>(a,b,c); + } + else if (cc == ',') // read "((a),c," + { + is >> x; // read "((a),c,x" + + if (!is.good()) goto finish; + + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "((a),c,x)" + { + o = octonion<T>(a,b,c,d,x.real(),x.imag()); + } + else if (cc == ',') // read "((a),c,x," + { + is >> y;if (!is.good()) goto finish; // read "((a),c,x,y" + + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "((a),c,x,y)" + { + o = octonion<T>(a,b,c,d,x.real(),x.imag(),y.real(),y.imag()); + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else if (cc ==',') // read "((a," + { + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == '(') // read "((a,(" + { + u = ::std::complex<T>(a); + + is.putback(ch); // can only backtrack so much + + is >> v; // read "((a,v" + + if (!is.good()) goto finish; + + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "((a,v)" + { + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "((a,v))" + { + o = octonion<T>(u,v); + } + else if (cc == ',') // read "((a,v)," + { + p = ::boost::math::quaternion<T>(u,v); + + is >> q; // read "((a,v),q" + + if (!is.good()) goto finish; + + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "((a,v),q)" + { + o = octonion<T>(p,q); + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else + { + is.putback(ch); + + is >> b; // read "((a,b" + + if (!is.good()) goto finish; + + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "((a,b)" + { + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "((a,b))" + { + o = octonion<T>(a,b); + } + else if (cc == ',') // read "((a,b)," + { + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == '(') // read "((a,b),(" + { + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == '(') // read "((a,b),((" + { + p = ::boost::math::quaternion<T>(a,b); + + is.putback(ch); + + is.putback(ch); // we backtrack twice, with the same value + + is >> q; // read "((a,b),q" + + if (!is.good()) goto finish; + + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "((a,b),q)" + { + o = octonion<T>(p,q); + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else // read "((a,b),(c" or "((a,b),(e" + { + is.putback(ch); + + is >> c; + + if (!is.good()) goto finish; + + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "((a,b),(c)" (ambiguity resolution) + { + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "((a,b),(c))" + { + o = octonion<T>(a,b,c); + } + else if (cc == ',') // read "((a,b),(c)," + { + u = ::std::complex<T>(a,b); + + v = ::std::complex<T>(c); + + is >> x; // read "((a,b),(c),x" + + if (!is.good()) goto finish; + + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "((a,b),(c),x)" + { + o = octonion<T>(u,v,x); + } + else if (cc == ',') // read "((a,b),(c),x," + { + is >> y; // read "((a,b),(c),x,y" + + if (!is.good()) goto finish; + + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "((a,b),(c),x,y)" + { + o = octonion<T>(u,v,x,y); + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else if (cc == ',') // read "((a,b),(c," or "((a,b),(e," + { + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == '(') // read "((a,b),(e,(" (ambiguity resolution) + { + u = ::std::complex<T>(a,b); + + x = ::std::complex<T>(c); // "c" is actually "e" + + is.putback(ch); + + is >> y; // read "((a,b),(e,y" + + if (!is.good()) goto finish; + + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "((a,b),(e,y)" + { + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "((a,b),(e,y))" + { + o = octonion<T>(u,v,x,y); + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else // read "((a,b),(c,d" or "((a,b),(e,f" + { + is.putback(ch); + + is >> d; + + if (!is.good()) goto finish; + + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "((a,b),(c,d)" (ambiguity resolution) + { + u = ::std::complex<T>(a,b); + + v = ::std::complex<T>(c,d); + + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "((a,b),(c,d))" + { + o = octonion<T>(u,v); + } + else if (cc == ',') // read "((a,b),(c,d)," + { + is >> x; // read "((a,b),(c,d),x + + if (!is.good()) goto finish; + + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "((a,b),(c,d),x)" + { + o = octonion<T>(u,v,x); + } + else if (cc == ',') // read "((a,b),(c,d),x," + { + is >> y; // read "((a,b),(c,d),x,y" + + if (!is.good()) goto finish; + + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "((a,b),(c,d),x,y)" + { + o = octonion<T>(u,v,x,y); + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else if (cc == ',') // read "((a,b),(e,f," (ambiguity resolution) + { + p = ::boost::math::quaternion<T>(a,b); // too late to backtrack + + is >> g; // read "((a,b),(e,f,g" + + if (!is.good()) goto finish; + + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "((a,b),(e,f,g)" + { + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "((a,b),(e,f,g))" + { + q = ::boost::math::quaternion<T>(c,d,g); // "c" is actually "e" and "d" is actually "f" + + o = octonion<T>(p,q); + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else if (cc == ',') // read "((a,b),(e,f,g," + { + is >> h; // read "((a,b),(e,f,g,h" + + if (!is.good()) goto finish; + + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "((a,b),(e,f,g,h)" + { + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read ((a,b),(e,f,g,h))" + { + q = ::boost::math::quaternion<T>(c,d,g,h); // "c" is actually "e" and "d" is actually "f" + + o = octonion<T>(p,q); + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else if (cc == ',') // read "((a,b," + { + is >> c; // read "((a,b,c" + + if (!is.good()) goto finish; + + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "((a,b,c)" + { + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "((a,b,c))" + { + o = octonion<T>(a,b,c); + } + else if (cc == ',') // read "((a,b,c)," + { + p = ::boost::math::quaternion<T>(a,b,c); + + is >> q; // read "((a,b,c),q" + + if (!is.good()) goto finish; + + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "((a,b,c),q)" + { + o = octonion<T>(p,q); + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else if (cc == ',') // read "((a,b,c," + { + is >> d; // read "((a,b,c,d" + + if (!is.good()) goto finish; + + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "((a,b,c,d)" + { + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "((a,b,c,d))" + { + o = octonion<T>(a,b,c,d); + } + else if (cc == ',') // read "((a,b,c,d)," + { + p = ::boost::math::quaternion<T>(a,b,c,d); + + is >> q; // read "((a,b,c,d),q" + + if (!is.good()) goto finish; + + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "((a,b,c,d),q)" + { + o = octonion<T>(p,q); + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + } + else // read "(a" + { + is.putback(ch); + + is >> a; // we extract the first component + + if (!is.good()) goto finish; + + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "(a)" + { + o = octonion<T>(a); + } + else if (cc == ',') // read "(a," + { + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == '(') // read "(a,(" + { + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == '(') // read "(a,((" + { + p = ::boost::math::quaternion<T>(a); + + is.putback(ch); + + is.putback(ch); // we backtrack twice, with the same value + + is >> q; // read "(a,q" + + if (!is.good()) goto finish; + + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "(a,q)" + { + o = octonion<T>(p,q); + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else // read "(a,(c" or "(a,(e" + { + is.putback(ch); + + is >> c; + + if (!is.good()) goto finish; + + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "(a,(c)" (ambiguity resolution) + { + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "(a,(c))" + { + o = octonion<T>(a,b,c); + } + else if (cc == ',') // read "(a,(c)," + { + u = ::std::complex<T>(a); + + v = ::std::complex<T>(c); + + is >> x; // read "(a,(c),x" + + if (!is.good()) goto finish; + + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "(a,(c),x)" + { + o = octonion<T>(u,v,x); + } + else if (cc == ',') // read "(a,(c),x," + { + is >> y; // read "(a,(c),x,y" + + if (!is.good()) goto finish; + + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "(a,(c),x,y)" + { + o = octonion<T>(u,v,x,y); + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else if (cc == ',') // read "(a,(c," or "(a,(e," + { + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == '(') // read "(a,(e,(" (ambiguity resolution) + { + u = ::std::complex<T>(a); + + x = ::std::complex<T>(c); // "c" is actually "e" + + is.putback(ch); // we backtrack + + is >> y; // read "(a,(e,y" + + if (!is.good()) goto finish; + + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "(a,(e,y)" + { + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "(a,(e,y))" + { + o = octonion<T>(u,v,x,y); + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else // read "(a,(c,d" or "(a,(e,f" + { + is.putback(ch); + + is >> d; + + if (!is.good()) goto finish; + + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "(a,(c,d)" (ambiguity resolution) + { + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "(a,(c,d))" + { + o = octonion<T>(a,b,c,d); + } + else if (cc == ',') // read "(a,(c,d)," + { + u = ::std::complex<T>(a); + + v = ::std::complex<T>(c,d); + + is >> x; // read "(a,(c,d),x" + + if (!is.good()) goto finish; + + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "(a,(c,d),x)" + { + o = octonion<T>(u,v,x); + } + else if (cc == ',') // read "(a,(c,d),x," + { + is >> y; // read "(a,(c,d),x,y" + + if (!is.good()) goto finish; + + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "(a,(c,d),x,y)" + { + o = octonion<T>(u,v,x,y); + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else if (cc == ',') // read "(a,(e,f," (ambiguity resolution) + { + p = ::boost::math::quaternion<T>(a); + + is >> g; // read "(a,(e,f,g" + + if (!is.good()) goto finish; + + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "(a,(e,f,g)" + { + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "(a,(e,f,g))" + { + q = ::boost::math::quaternion<T>(c,d,g); // "c" is actually "e" and "d" is actually "f" + + o = octonion<T>(p,q); + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else if (cc == ',') // read "(a,(e,f,g," + { + is >> h; // read "(a,(e,f,g,h" + + if (!is.good()) goto finish; + + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "(a,(e,f,g,h)" + { + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "(a,(e,f,g,h))" + { + q = ::boost::math::quaternion<T>(c,d,g,h); // "c" is actually "e" and "d" is actually "f" + + o = octonion<T>(p,q); + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + } + else // read "(a,b" or "(a,c" (ambiguity resolution) + { + is.putback(ch); + + is >> b; + + if (!is.good()) goto finish; + + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "(a,b)" (ambiguity resolution) + { + o = octonion<T>(a,b); + } + else if (cc == ',') // read "(a,b," or "(a,c," + { + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == '(') // read "(a,c,(" (ambiguity resolution) + { + u = ::std::complex<T>(a); + + v = ::std::complex<T>(b); // "b" is actually "c" + + is.putback(ch); // we backtrack + + is >> x; // read "(a,c,x" + + if (!is.good()) goto finish; + + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "(a,c,x)" + { + o = octonion<T>(u,v,x); + } + else if (cc == ',') // read "(a,c,x," + { + is >> y; // read "(a,c,x,y" // read "(a,c,x" + + if (!is.good()) goto finish; + + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "(a,c,x,y)" + { + o = octonion<T>(u,v,x,y); + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else // read "(a,b,c" or "(a,c,e" + { + is.putback(ch); + + is >> c; + + if (!is.good()) goto finish; + + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "(a,b,c)" (ambiguity resolution) + { + o = octonion<T>(a,b,c); + } + else if (cc == ',') // read "(a,b,c," or "(a,c,e," + { + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == '(') // read "(a,c,e,(") (ambiguity resolution) + { + u = ::std::complex<T>(a); + + v = ::std::complex<T>(b); // "b" is actually "c" + + x = ::std::complex<T>(c); // "c" is actually "e" + + is.putback(ch); // we backtrack + + is >> y; // read "(a,c,e,y" + + if (!is.good()) goto finish; + + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "(a,c,e,y)" + { + o = octonion<T>(u,v,x,y); + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else // read "(a,b,c,d" (ambiguity resolution) + { + is.putback(ch); // we backtrack + + is >> d; + + if (!is.good()) goto finish; + + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "(a,b,c,d)" + { + o = octonion<T>(a,b,c,d); + } + else if (cc == ',') // read "(a,b,c,d," + { + is >> e; // read "(a,b,c,d,e" + + if (!is.good()) goto finish; + + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "(a,b,c,d,e)" + { + o = octonion<T>(a,b,c,d,e); + } + else if (cc == ',') // read "(a,b,c,d,e," + { + is >> f; // read "(a,b,c,d,e,f" + + if (!is.good()) goto finish; + + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "(a,b,c,d,e,f)" + { + o = octonion<T>(a,b,c,d,e,f); + } + else if (cc == ',') // read "(a,b,c,d,e,f," + { + is >> g; // read "(a,b,c,d,e,f,g" // read "(a,b,c,d,e,f" + + if (!is.good()) goto finish; + + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "(a,b,c,d,e,f,g)" + { + o = octonion<T>(a,b,c,d,e,f,g); + } + else if (cc == ',') // read "(a,b,c,d,e,f,g," + { + is >> h; // read "(a,b,c,d,e,f,g,h" // read "(a,b,c,d,e,f,g" // read "(a,b,c,d,e,f" + + if (!is.good()) goto finish; + + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // read "(a,b,c,d,e,f,g,h)" + { + o = octonion<T>(a,b,c,d,e,f,g,h); + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + } + else // format: a + { + is.putback(ch); + + is >> a; // we extract the first component + + if (!is.good()) goto finish; + + o = octonion<T>(a); + } + + finish: + return(is); + } + + +#if BOOST_WORKAROUND(__GNUC__, < 3) + template<typename T> + ::std::ostream & operator << ( ::std::ostream & os, + octonion<T> const & o) +#else + template<typename T, typename charT, class traits> + ::std::basic_ostream<charT,traits> & operator << ( ::std::basic_ostream<charT,traits> & os, + octonion<T> const & o) +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + ::std::ostringstream s; +#else + ::std::basic_ostringstream<charT,traits> s; +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + + s.flags(os.flags()); +#ifdef BOOST_NO_STD_LOCALE +#else + s.imbue(os.getloc()); +#endif /* BOOST_NO_STD_LOCALE */ + s.precision(os.precision()); + + s << '(' << o.R_component_1() << ',' + << o.R_component_2() << ',' + << o.R_component_3() << ',' + << o.R_component_4() << ',' + << o.R_component_5() << ',' + << o.R_component_6() << ',' + << o.R_component_7() << ',' + << o.R_component_8() << ')'; + + return os << s.str(); + } + + + // values + + template<typename T> + inline T real(octonion<T> const & o) + { + return(o.real()); + } + + + template<typename T> + inline octonion<T> unreal(octonion<T> const & o) + { + return(o.unreal()); + } + + +#define BOOST_OCTONION_VALARRAY_LOADER \ + using ::std::valarray; \ + \ + valarray<T> temp(8); \ + \ + temp[0] = o.R_component_1(); \ + temp[1] = o.R_component_2(); \ + temp[2] = o.R_component_3(); \ + temp[3] = o.R_component_4(); \ + temp[4] = o.R_component_5(); \ + temp[5] = o.R_component_6(); \ + temp[6] = o.R_component_7(); \ + temp[7] = o.R_component_8(); + + + template<typename T> + inline T sup(octonion<T> const & o) + { +#ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP + using ::std::abs; +#endif /* BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP */ + + BOOST_OCTONION_VALARRAY_LOADER + +#if BOOST_WORKAROUND(__GNUC__, < 3) + return((BOOST_GET_VALARRAY(T, abs(temp)).max)()); +#else + return((abs(temp).max)()); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + + + template<typename T> + inline T l1(octonion<T> const & o) + { +#ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP + using ::std::abs; +#endif /* BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP */ + + BOOST_OCTONION_VALARRAY_LOADER + +#if BOOST_WORKAROUND(__GNUC__, < 3) + return(BOOST_GET_VALARRAY(T, abs(temp)).sum()); +#else + return(abs(temp).sum()); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + + + template<typename T> + inline T abs(const octonion<T> & o) + { +#ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP + using ::std::abs; +#endif /* BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP */ + + using ::std::sqrt; + + BOOST_OCTONION_VALARRAY_LOADER + +#if BOOST_WORKAROUND(__GNUC__, < 3) + T maxim = (BOOST_GET_VALARRAY(T,abs(temp)).max)(); // overflow protection +#else + T maxim = (abs(temp).max)(); // overflow protection +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + + if (maxim == static_cast<T>(0)) + { + return(maxim); + } + else + { + T mixam = static_cast<T>(1)/maxim; // prefer multiplications over divisions + + temp *= mixam; + + temp *= temp; + + return(maxim*sqrt(temp.sum())); + } + + //return(::std::sqrt(norm(o))); + } + + +#undef BOOST_OCTONION_VALARRAY_LOADER + + + // Note: This is the Cayley norm, not the Euclidian norm... + + template<typename T> + inline T norm(octonion<T> const & o) + { + return(real(o*conj(o))); + } + + + template<typename T> + inline octonion<T> conj(octonion<T> const & o) + { + return(octonion<T>( +o.R_component_1(), + -o.R_component_2(), + -o.R_component_3(), + -o.R_component_4(), + -o.R_component_5(), + -o.R_component_6(), + -o.R_component_7(), + -o.R_component_8())); + } + + + // Note: There is little point, for the octonions, to introduce the equivalents + // to the complex "arg" and the quaternionic "cylindropolar". + + + template<typename T> + inline octonion<T> spherical(T const & rho, + T const & theta, + T const & phi1, + T const & phi2, + T const & phi3, + T const & phi4, + T const & phi5, + T const & phi6) + { + using ::std::cos; + using ::std::sin; + + //T a = cos(theta)*cos(phi1)*cos(phi2)*cos(phi3)*cos(phi4)*cos(phi5)*cos(phi6); + //T b = sin(theta)*cos(phi1)*cos(phi2)*cos(phi3)*cos(phi4)*cos(phi5)*cos(phi6); + //T c = sin(phi1)*cos(phi2)*cos(phi3)*cos(phi4)*cos(phi5)*cos(phi6); + //T d = sin(phi2)*cos(phi3)*cos(phi4)*cos(phi5)*cos(phi6); + //T e = sin(phi3)*cos(phi4)*cos(phi5)*cos(phi6); + //T f = sin(phi4)*cos(phi5)*cos(phi6); + //T g = sin(phi5)*cos(phi6); + //T h = sin(phi6); + + T courrant = static_cast<T>(1); + + T h = sin(phi6); + + courrant *= cos(phi6); + + T g = sin(phi5)*courrant; + + courrant *= cos(phi5); + + T f = sin(phi4)*courrant; + + courrant *= cos(phi4); + + T e = sin(phi3)*courrant; + + courrant *= cos(phi3); + + T d = sin(phi2)*courrant; + + courrant *= cos(phi2); + + T c = sin(phi1)*courrant; + + courrant *= cos(phi1); + + T b = sin(theta)*courrant; + T a = cos(theta)*courrant; + + return(rho*octonion<T>(a,b,c,d,e,f,g,h)); + } + + + template<typename T> + inline octonion<T> multipolar(T const & rho1, + T const & theta1, + T const & rho2, + T const & theta2, + T const & rho3, + T const & theta3, + T const & rho4, + T const & theta4) + { + using ::std::cos; + using ::std::sin; + + T a = rho1*cos(theta1); + T b = rho1*sin(theta1); + T c = rho2*cos(theta2); + T d = rho2*sin(theta2); + T e = rho3*cos(theta3); + T f = rho3*sin(theta3); + T g = rho4*cos(theta4); + T h = rho4*sin(theta4); + + return(octonion<T>(a,b,c,d,e,f,g,h)); + } + + + template<typename T> + inline octonion<T> cylindrical(T const & r, + T const & angle, + T const & h1, + T const & h2, + T const & h3, + T const & h4, + T const & h5, + T const & h6) + { + using ::std::cos; + using ::std::sin; + + T a = r*cos(angle); + T b = r*sin(angle); + + return(octonion<T>(a,b,h1,h2,h3,h4,h5,h6)); + } + + + template<typename T> + inline octonion<T> exp(octonion<T> const & o) + { + using ::std::exp; + using ::std::cos; + + using ::boost::math::sinc_pi; + + T u = exp(real(o)); + + T z = abs(unreal(o)); + + T w = sinc_pi(z); + + return(u*octonion<T>(cos(z), + w*o.R_component_2(), w*o.R_component_3(), + w*o.R_component_4(), w*o.R_component_5(), + w*o.R_component_6(), w*o.R_component_7(), + w*o.R_component_8())); + } + + + template<typename T> + inline octonion<T> cos(octonion<T> const & o) + { + using ::std::sin; + using ::std::cos; + using ::std::cosh; + + using ::boost::math::sinhc_pi; + + T z = abs(unreal(o)); + + T w = -sin(o.real())*sinhc_pi(z); + + return(octonion<T>(cos(o.real())*cosh(z), + w*o.R_component_2(), w*o.R_component_3(), + w*o.R_component_4(), w*o.R_component_5(), + w*o.R_component_6(), w*o.R_component_7(), + w*o.R_component_8())); + } + + + template<typename T> + inline octonion<T> sin(octonion<T> const & o) + { + using ::std::sin; + using ::std::cos; + using ::std::cosh; + + using ::boost::math::sinhc_pi; + + T z = abs(unreal(o)); + + T w = +cos(o.real())*sinhc_pi(z); + + return(octonion<T>(sin(o.real())*cosh(z), + w*o.R_component_2(), w*o.R_component_3(), + w*o.R_component_4(), w*o.R_component_5(), + w*o.R_component_6(), w*o.R_component_7(), + w*o.R_component_8())); + } + + + template<typename T> + inline octonion<T> tan(octonion<T> const & o) + { + return(sin(o)/cos(o)); + } + + + template<typename T> + inline octonion<T> cosh(octonion<T> const & o) + { + return((exp(+o)+exp(-o))/static_cast<T>(2)); + } + + + template<typename T> + inline octonion<T> sinh(octonion<T> const & o) + { + return((exp(+o)-exp(-o))/static_cast<T>(2)); + } + + + template<typename T> + inline octonion<T> tanh(octonion<T> const & o) + { + return(sinh(o)/cosh(o)); + } + + + template<typename T> + octonion<T> pow(octonion<T> const & o, + int n) + { + if (n > 1) + { + int m = n>>1; + + octonion<T> result = pow(o, m); + + result *= result; + + if (n != (m<<1)) + { + result *= o; // n odd + } + + return(result); + } + else if (n == 1) + { + return(o); + } + else if (n == 0) + { + return(octonion<T>(1)); + } + else /* n < 0 */ + { + return(pow(octonion<T>(1)/o,-n)); + } + } + + + // helper templates for converting copy constructors (definition) + + namespace detail + { + + template< typename T, + typename U + > + octonion<T> octonion_type_converter(octonion<U> const & rhs) + { + return(octonion<T>( static_cast<T>(rhs.R_component_1()), + static_cast<T>(rhs.R_component_2()), + static_cast<T>(rhs.R_component_3()), + static_cast<T>(rhs.R_component_4()), + static_cast<T>(rhs.R_component_5()), + static_cast<T>(rhs.R_component_6()), + static_cast<T>(rhs.R_component_7()), + static_cast<T>(rhs.R_component_8()))); + } + } + } +} + + +#if BOOST_WORKAROUND(__GNUC__, < 3) + #undef BOOST_GET_VALARRAY +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + + +#endif /* BOOST_OCTONION_HPP */ diff --git a/Utilities/BGL/boost/math/policies/error_handling.hpp b/Utilities/BGL/boost/math/policies/error_handling.hpp new file mode 100644 index 0000000000000000000000000000000000000000..8f41a3914438870b8873162a9e480a64c15dd52b --- /dev/null +++ b/Utilities/BGL/boost/math/policies/error_handling.hpp @@ -0,0 +1,653 @@ +// Copyright John Maddock 2007. +// Copyright Paul A. Bristow 2007. + +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_POLICY_ERROR_HANDLING_HPP +#define BOOST_MATH_POLICY_ERROR_HANDLING_HPP + +#include <stdexcept> +#include <iomanip> +#include <string> +#include <cerrno> +#include <boost/config/no_tr1/cmath.hpp> +#include <stdexcept> +#include <boost/math/tools/config.hpp> +#include <boost/math/policies/policy.hpp> +#include <boost/math/tools/precision.hpp> +#include <boost/cstdint.hpp> +#ifdef BOOST_MSVC +# pragma warning(push) // Quiet warnings in boost/format.hpp +# pragma warning(disable: 4996) // _SCL_SECURE_NO_DEPRECATE +# pragma warning(disable: 4512) // assignment operator could not be generated. +// And warnings in error handling: +# pragma warning(disable: 4702) // unreachable code +// Note that this only occurs when the compiler can deduce code is unreachable, +// for example when policy macros are used to ignore errors rather than throw. +#endif +#include <boost/format.hpp> + +namespace boost{ namespace math{ + +class evaluation_error : public std::runtime_error +{ +public: + evaluation_error(const std::string& s) : std::runtime_error(s){} +}; + +class rounding_error : public std::runtime_error +{ +public: + rounding_error(const std::string& s) : std::runtime_error(s){} +}; + +namespace policies{ +// +// Forward declarations of user error handlers, +// it's up to the user to provide the definition of these: +// +template <class T> +T user_domain_error(const char* function, const char* message, const T& val); +template <class T> +T user_pole_error(const char* function, const char* message, const T& val); +template <class T> +T user_overflow_error(const char* function, const char* message, const T& val); +template <class T> +T user_underflow_error(const char* function, const char* message, const T& val); +template <class T> +T user_denorm_error(const char* function, const char* message, const T& val); +template <class T> +T user_evaluation_error(const char* function, const char* message, const T& val); +template <class T> +T user_rounding_error(const char* function, const char* message, const T& val); +template <class T> +T user_indeterminate_result_error(const char* function, const char* message, const T& val); + +namespace detail +{ +// +// Helper function to avoid binding rvalue to non-const-reference, +// in other words a warning suppression mechansim: +// +template <class Formatter, class Group> +inline std::string do_format(Formatter f, const Group& g) +{ + return (f % g).str(); +} + +template <class E, class T> +void raise_error(const char* function, const char* message) +{ + if(function == 0) + function = "Unknown function operating on type %1%"; + if(message == 0) + message = "Cause unknown"; + + std::string msg("Error in function "); + msg += (boost::format(function) % typeid(T).name()).str(); + msg += ": "; + msg += message; + + E e(msg); + boost::throw_exception(e); +} + +template <class E, class T> +void raise_error(const char* function, const char* message, const T& val) +{ + if(function == 0) + function = "Unknown function operating on type %1%"; + if(message == 0) + message = "Cause unknown: error caused by bad argument with value %1%"; + + std::string msg("Error in function "); + msg += (boost::format(function) % typeid(T).name()).str(); + msg += ": "; + msg += message; + + int prec = 2 + (boost::math::policies::digits<T, boost::math::policies::policy<> >() * 30103UL) / 100000UL; + msg = do_format(boost::format(msg), boost::io::group(std::setprecision(prec), val)); + + E e(msg); + boost::throw_exception(e); +} + +template <class T> +inline T raise_domain_error( + const char* function, + const char* message, + const T& val, + const ::boost::math::policies::domain_error< ::boost::math::policies::throw_on_error>&) +{ + raise_error<std::domain_error, T>(function, message, val); + // we never get here: + return std::numeric_limits<T>::quiet_NaN(); +} + +template <class T> +inline T raise_domain_error( + const char* , + const char* , + const T& , + const ::boost::math::policies::domain_error< ::boost::math::policies::ignore_error>&) +{ + // This may or may not do the right thing, but the user asked for the error + // to be ignored so here we go anyway: + return std::numeric_limits<T>::quiet_NaN(); +} + +template <class T> +inline T raise_domain_error( + const char* , + const char* , + const T& , + const ::boost::math::policies::domain_error< ::boost::math::policies::errno_on_error>&) +{ + errno = EDOM; + // This may or may not do the right thing, but the user asked for the error + // to be silent so here we go anyway: + return std::numeric_limits<T>::quiet_NaN(); +} + +template <class T> +inline T raise_domain_error( + const char* function, + const char* message, + const T& val, + const ::boost::math::policies::domain_error< ::boost::math::policies::user_error>&) +{ + return user_domain_error(function, message, val); +} + +template <class T> +inline T raise_pole_error( + const char* function, + const char* message, + const T& val, + const ::boost::math::policies::pole_error< ::boost::math::policies::throw_on_error>&) +{ + return boost::math::policies::detail::raise_domain_error(function, message, val, ::boost::math::policies::domain_error< ::boost::math::policies::throw_on_error>()); +} + +template <class T> +inline T raise_pole_error( + const char* function, + const char* message, + const T& val, + const ::boost::math::policies::pole_error< ::boost::math::policies::ignore_error>&) +{ + return ::boost::math::policies::detail::raise_domain_error(function, message, val, ::boost::math::policies::domain_error< ::boost::math::policies::ignore_error>()); +} + +template <class T> +inline T raise_pole_error( + const char* function, + const char* message, + const T& val, + const ::boost::math::policies::pole_error< ::boost::math::policies::errno_on_error>&) +{ + return ::boost::math::policies::detail::raise_domain_error(function, message, val, ::boost::math::policies::domain_error< ::boost::math::policies::errno_on_error>()); +} + +template <class T> +inline T raise_pole_error( + const char* function, + const char* message, + const T& val, + const ::boost::math::policies::pole_error< ::boost::math::policies::user_error>&) +{ + return user_pole_error(function, message, val); +} + +template <class T> +inline T raise_overflow_error( + const char* function, + const char* message, + const ::boost::math::policies::overflow_error< ::boost::math::policies::throw_on_error>&) +{ + raise_error<std::overflow_error, T>(function, message ? message : "numeric overflow"); + // we never get here: + return std::numeric_limits<T>::has_infinity ? std::numeric_limits<T>::infinity() : boost::math::tools::max_value<T>(); +} + +template <class T> +inline T raise_overflow_error( + const char* , + const char* , + const ::boost::math::policies::overflow_error< ::boost::math::policies::ignore_error>&) +{ + // This may or may not do the right thing, but the user asked for the error + // to be ignored so here we go anyway: + return std::numeric_limits<T>::has_infinity ? std::numeric_limits<T>::infinity() : boost::math::tools::max_value<T>(); +} + +template <class T> +inline T raise_overflow_error( + const char* , + const char* , + const ::boost::math::policies::overflow_error< ::boost::math::policies::errno_on_error>&) +{ + errno = ERANGE; + // This may or may not do the right thing, but the user asked for the error + // to be silent so here we go anyway: + return std::numeric_limits<T>::has_infinity ? std::numeric_limits<T>::infinity() : boost::math::tools::max_value<T>(); +} + +template <class T> +inline T raise_overflow_error( + const char* function, + const char* message, + const ::boost::math::policies::overflow_error< ::boost::math::policies::user_error>&) +{ + return user_overflow_error(function, message, std::numeric_limits<T>::infinity()); +} + +template <class T> +inline T raise_underflow_error( + const char* function, + const char* message, + const ::boost::math::policies::underflow_error< ::boost::math::policies::throw_on_error>&) +{ + raise_error<std::underflow_error, T>(function, message ? message : "numeric underflow"); + // we never get here: + return 0; +} + +template <class T> +inline T raise_underflow_error( + const char* , + const char* , + const ::boost::math::policies::underflow_error< ::boost::math::policies::ignore_error>&) +{ + // This may or may not do the right thing, but the user asked for the error + // to be ignored so here we go anyway: + return T(0); +} + +template <class T> +inline T raise_underflow_error( + const char* /* function */, + const char* /* message */, + const ::boost::math::policies::underflow_error< ::boost::math::policies::errno_on_error>&) +{ + errno = ERANGE; + // This may or may not do the right thing, but the user asked for the error + // to be silent so here we go anyway: + return T(0); +} + +template <class T> +inline T raise_underflow_error( + const char* function, + const char* message, + const ::boost::math::policies::underflow_error< ::boost::math::policies::user_error>&) +{ + return user_underflow_error(function, message, T(0)); +} + +template <class T> +inline T raise_denorm_error( + const char* function, + const char* message, + const T& /* val */, + const ::boost::math::policies::denorm_error< ::boost::math::policies::throw_on_error>&) +{ + raise_error<std::underflow_error, T>(function, message ? message : "denormalised result"); + // we never get here: + return T(0); +} + +template <class T> +inline T raise_denorm_error( + const char* , + const char* , + const T& val, + const ::boost::math::policies::denorm_error< ::boost::math::policies::ignore_error>&) +{ + // This may or may not do the right thing, but the user asked for the error + // to be ignored so here we go anyway: + return val; +} + +template <class T> +inline T raise_denorm_error( + const char* , + const char* , + const T& val, + const ::boost::math::policies::denorm_error< ::boost::math::policies::errno_on_error>&) +{ + errno = ERANGE; + // This may or may not do the right thing, but the user asked for the error + // to be silent so here we go anyway: + return val; +} + +template <class T> +inline T raise_denorm_error( + const char* function, + const char* message, + const T& val, + const ::boost::math::policies::denorm_error< ::boost::math::policies::user_error>&) +{ + return user_denorm_error(function, message, val); +} + +template <class T> +inline T raise_evaluation_error( + const char* function, + const char* message, + const T& val, + const ::boost::math::policies::evaluation_error< ::boost::math::policies::throw_on_error>&) +{ + raise_error<boost::math::evaluation_error, T>(function, message, val); + // we never get here: + return T(0); +} + +template <class T> +inline T raise_evaluation_error( + const char* , + const char* , + const T& val, + const ::boost::math::policies::evaluation_error< ::boost::math::policies::ignore_error>&) +{ + // This may or may not do the right thing, but the user asked for the error + // to be ignored so here we go anyway: + return val; +} + +template <class T> +inline T raise_evaluation_error( + const char* , + const char* , + const T& val, + const ::boost::math::policies::evaluation_error< ::boost::math::policies::errno_on_error>&) +{ + errno = EDOM; + // This may or may not do the right thing, but the user asked for the error + // to be silent so here we go anyway: + return val; +} + +template <class T> +inline T raise_evaluation_error( + const char* function, + const char* message, + const T& val, + const ::boost::math::policies::evaluation_error< ::boost::math::policies::user_error>&) +{ + return user_evaluation_error(function, message, val); +} + +template <class T> +inline T raise_rounding_error( + const char* function, + const char* message, + const T& val, + const ::boost::math::policies::rounding_error< ::boost::math::policies::throw_on_error>&) +{ + raise_error<boost::math::rounding_error, T>(function, message, val); + // we never get here: + return T(0); +} + +template <class T> +inline T raise_rounding_error( + const char* , + const char* , + const T& val, + const ::boost::math::policies::rounding_error< ::boost::math::policies::ignore_error>&) +{ + // This may or may not do the right thing, but the user asked for the error + // to be ignored so here we go anyway: + return val; +} + +template <class T> +inline T raise_rounding_error( + const char* , + const char* , + const T& val, + const ::boost::math::policies::rounding_error< ::boost::math::policies::errno_on_error>&) +{ + errno = ERANGE; + // This may or may not do the right thing, but the user asked for the error + // to be silent so here we go anyway: + return val; +} + +template <class T> +inline T raise_rounding_error( + const char* function, + const char* message, + const T& val, + const ::boost::math::policies::rounding_error< ::boost::math::policies::user_error>&) +{ + return user_rounding_error(function, message, val); +} + +template <class T, class R> +inline T raise_indeterminate_result_error( + const char* function, + const char* message, + const T& val, + const R& , + const ::boost::math::policies::indeterminate_result_error< ::boost::math::policies::throw_on_error>&) +{ + raise_error<std::domain_error, T>(function, message, val); + // we never get here: + return std::numeric_limits<T>::quiet_NaN(); +} + +template <class T, class R> +inline T raise_indeterminate_result_error( + const char* , + const char* , + const T& , + const R& result, + const ::boost::math::policies::indeterminate_result_error< ::boost::math::policies::ignore_error>&) +{ + // This may or may not do the right thing, but the user asked for the error + // to be ignored so here we go anyway: + return result; +} + +template <class T, class R> +inline T raise_indeterminate_result_error( + const char* , + const char* , + const T& , + const R& result, + const ::boost::math::policies::indeterminate_result_error< ::boost::math::policies::errno_on_error>&) +{ + errno = EDOM; + // This may or may not do the right thing, but the user asked for the error + // to be silent so here we go anyway: + return result; +} + +template <class T, class R> +inline T raise_indeterminate_result_error( + const char* function, + const char* message, + const T& val, + const R& , + const ::boost::math::policies::indeterminate_result_error< ::boost::math::policies::user_error>&) +{ + return user_indeterminate_result_error(function, message, val); +} + +} // namespace detail + +template <class T, class Policy> +inline T raise_domain_error(const char* function, const char* message, const T& val, const Policy&) +{ + typedef typename Policy::domain_error_type policy_type; + return detail::raise_domain_error( + function, message ? message : "Domain Error evaluating function at %1%", + val, policy_type()); +} + +template <class T, class Policy> +inline T raise_pole_error(const char* function, const char* message, const T& val, const Policy&) +{ + typedef typename Policy::pole_error_type policy_type; + return detail::raise_pole_error( + function, message ? message : "Evaluation of function at pole %1%", + val, policy_type()); +} + +template <class T, class Policy> +inline T raise_overflow_error(const char* function, const char* message, const Policy&) +{ + typedef typename Policy::overflow_error_type policy_type; + return detail::raise_overflow_error<T>( + function, message ? message : "Overflow Error", + policy_type()); +} + +template <class T, class Policy> +inline T raise_underflow_error(const char* function, const char* message, const Policy&) +{ + typedef typename Policy::underflow_error_type policy_type; + return detail::raise_underflow_error<T>( + function, message ? message : "Underflow Error", + policy_type()); +} + +template <class T, class Policy> +inline T raise_denorm_error(const char* function, const char* message, const T& val, const Policy&) +{ + typedef typename Policy::denorm_error_type policy_type; + return detail::raise_denorm_error<T>( + function, message ? message : "Denorm Error", + val, + policy_type()); +} + +template <class T, class Policy> +inline T raise_evaluation_error(const char* function, const char* message, const T& val, const Policy&) +{ + typedef typename Policy::evaluation_error_type policy_type; + return detail::raise_evaluation_error( + function, message ? message : "Internal Evaluation Error, best value so far was %1%", + val, policy_type()); +} + +template <class T, class Policy> +inline T raise_rounding_error(const char* function, const char* message, const T& val, const Policy&) +{ + typedef typename Policy::rounding_error_type policy_type; + return detail::raise_rounding_error( + function, message ? message : "Value %1% can not be represented in the target integer type.", + val, policy_type()); +} + +template <class T, class R, class Policy> +inline T raise_indeterminate_result_error(const char* function, const char* message, const T& val, const R& result, const Policy&) +{ + typedef typename Policy::indeterminate_result_error_type policy_type; + return detail::raise_indeterminate_result_error( + function, message ? message : "Indeterminate result with value %1%", + val, result, policy_type()); +} + +// +// checked_narrowing_cast: +// +namespace detail +{ + +template <class R, class T, class Policy> +inline bool check_overflow(T val, R* result, const char* function, const Policy& pol) +{ + BOOST_MATH_STD_USING + if(fabs(val) > tools::max_value<R>()) + { + *result = static_cast<R>(boost::math::policies::detail::raise_overflow_error<R>(function, 0, pol)); + return true; + } + return false; +} +template <class R, class T, class Policy> +inline bool check_underflow(T val, R* result, const char* function, const Policy& pol) +{ + if((val != 0) && (static_cast<R>(val) == 0)) + { + *result = static_cast<R>(boost::math::policies::detail::raise_underflow_error<R>(function, 0, pol)); + return true; + } + return false; +} +template <class R, class T, class Policy> +inline bool check_denorm(T val, R* result, const char* function, const Policy& pol) +{ + BOOST_MATH_STD_USING + if((fabs(val) < static_cast<T>(tools::min_value<R>())) && (static_cast<R>(val) != 0)) + { + *result = static_cast<R>(boost::math::policies::detail::raise_denorm_error<R>(function, 0, static_cast<R>(val), pol)); + return true; + } + return false; +} + +// Default instantiations with ignore_error policy. +template <class R, class T> +inline bool check_overflow(T /* val */, R* /* result */, const char* /* function */, const overflow_error<ignore_error>&){ return false; } +template <class R, class T> +inline bool check_underflow(T /* val */, R* /* result */, const char* /* function */, const underflow_error<ignore_error>&){ return false; } +template <class R, class T> +inline bool check_denorm(T /* val */, R* /* result*/, const char* /* function */, const denorm_error<ignore_error>&){ return false; } + +} // namespace detail + +template <class R, class Policy, class T> +inline R checked_narrowing_cast(T val, const char* function) +{ + typedef typename Policy::overflow_error_type overflow_type; + typedef typename Policy::underflow_error_type underflow_type; + typedef typename Policy::denorm_error_type denorm_type; + // + // Most of what follows will evaluate to a no-op: + // + R result; + if(detail::check_overflow<R>(val, &result, function, overflow_type())) + return result; + if(detail::check_underflow<R>(val, &result, function, underflow_type())) + return result; + if(detail::check_denorm<R>(val, &result, function, denorm_type())) + return result; + + return static_cast<R>(val); +} + +template <class Policy> +inline void check_series_iterations(const char* function, boost::uintmax_t max_iter, const Policy& pol) +{ + if(max_iter >= policies::get_max_series_iterations<Policy>()) + raise_evaluation_error<boost::uintmax_t>( + function, + "Series evaluation exceeded %1% iterations, giving up now.", max_iter, pol); +} + +template <class Policy> +inline void check_root_iterations(const char* function, boost::uintmax_t max_iter, const Policy& pol) +{ + if(max_iter >= policies::get_max_root_iterations<Policy>()) + raise_evaluation_error<boost::uintmax_t>( + function, + "Root finding evaluation exceeded %1% iterations, giving up now.", max_iter, pol); +} + +} //namespace policies + +#ifdef BOOST_MSVC +# pragma warning(pop) +#endif + +}} // namespaces boost/math + +#endif // BOOST_MATH_POLICY_ERROR_HANDLING_HPP + diff --git a/Utilities/BGL/boost/math/policies/policy.hpp b/Utilities/BGL/boost/math/policies/policy.hpp new file mode 100644 index 0000000000000000000000000000000000000000..229bf8afbb144788a817ff91978be87315c83e45 --- /dev/null +++ b/Utilities/BGL/boost/math/policies/policy.hpp @@ -0,0 +1,955 @@ +// Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_POLICY_HPP +#define BOOST_MATH_POLICY_HPP + +#include <boost/mpl/list.hpp> +#include <boost/mpl/contains.hpp> +#include <boost/mpl/if.hpp> +#include <boost/mpl/find_if.hpp> +#include <boost/mpl/remove_if.hpp> +#include <boost/mpl/vector.hpp> +#include <boost/mpl/push_back.hpp> +#include <boost/mpl/at.hpp> +#include <boost/mpl/size.hpp> +#include <boost/mpl/comparison.hpp> +#include <boost/type_traits/is_same.hpp> +#include <boost/static_assert.hpp> +#include <boost/assert.hpp> +#include <boost/math/tools/config.hpp> +#include <limits> +// Sadly we do need the .h versions of these to be sure of getting +// FLT_MANT_DIG etc. +#include <limits.h> +#include <stdlib.h> +#include <stddef.h> +#include <math.h> + +namespace boost{ namespace math{ + +namespace tools{ + +template <class T> +int digits(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(T)); +template <class T> +T epsilon(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(T)); + +} + +namespace policies{ + +// +// Define macros for our default policies, if they're not defined already: +// +#ifndef BOOST_MATH_DOMAIN_ERROR_POLICY +#define BOOST_MATH_DOMAIN_ERROR_POLICY throw_on_error +#endif +#ifndef BOOST_MATH_POLE_ERROR_POLICY +#define BOOST_MATH_POLE_ERROR_POLICY throw_on_error +#endif +#ifndef BOOST_MATH_OVERFLOW_ERROR_POLICY +#define BOOST_MATH_OVERFLOW_ERROR_POLICY throw_on_error +#endif +#ifndef BOOST_MATH_EVALUATION_ERROR_POLICY +#define BOOST_MATH_EVALUATION_ERROR_POLICY throw_on_error +#endif +#ifndef BOOST_MATH_ROUNDING_ERROR_POLICY +#define BOOST_MATH_ROUNDING_ERROR_POLICY throw_on_error +#endif +#ifndef BOOST_MATH_UNDERFLOW_ERROR_POLICY +#define BOOST_MATH_UNDERFLOW_ERROR_POLICY ignore_error +#endif +#ifndef BOOST_MATH_DENORM_ERROR_POLICY +#define BOOST_MATH_DENORM_ERROR_POLICY ignore_error +#endif +#ifndef BOOST_MATH_INDETERMINATE_RESULT_ERROR_POLICY +#define BOOST_MATH_INDETERMINATE_RESULT_ERROR_POLICY ignore_error +#endif +#ifndef BOOST_MATH_DIGITS10_POLICY +#define BOOST_MATH_DIGITS10_POLICY 0 +#endif +#ifndef BOOST_MATH_PROMOTE_FLOAT_POLICY +#define BOOST_MATH_PROMOTE_FLOAT_POLICY true +#endif +#ifndef BOOST_MATH_PROMOTE_DOUBLE_POLICY +#ifdef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS +#define BOOST_MATH_PROMOTE_DOUBLE_POLICY false +#else +#define BOOST_MATH_PROMOTE_DOUBLE_POLICY true +#endif +#endif +#ifndef BOOST_MATH_DISCRETE_QUANTILE_POLICY +#define BOOST_MATH_DISCRETE_QUANTILE_POLICY integer_round_outwards +#endif +#ifndef BOOST_MATH_ASSERT_UNDEFINED_POLICY +#define BOOST_MATH_ASSERT_UNDEFINED_POLICY true +#endif +#ifndef BOOST_MATH_MAX_SERIES_ITERATION_POLICY +#define BOOST_MATH_MAX_SERIES_ITERATION_POLICY 1000000 +#endif +#ifndef BOOST_MATH_MAX_ROOT_ITERATION_POLICY +#define BOOST_MATH_MAX_ROOT_ITERATION_POLICY 200 +#endif + +#if !defined(__BORLANDC__) \ + && !(defined(__GNUC__) && (__GNUC__ == 3) && (__GNUC_MINOR__ <= 2)) +#define BOOST_MATH_META_INT(type, name, Default)\ + template <type N = Default> struct name : public boost::mpl::int_<N>{};\ + namespace detail{\ + template <type N>\ + char test_is_valid_arg(const name<N>*);\ + char test_is_default_arg(const name<Default>*);\ + template <class T> struct is_##name##_imp\ + {\ + template <type N> static char test(const name<N>*);\ + static double test(...);\ + BOOST_STATIC_CONSTANT(bool, value = sizeof(test(static_cast<T*>(0))) == 1);\ + };\ + }\ + template <class T> struct is_##name : public boost::mpl::bool_< ::boost::math::policies::detail::is_##name##_imp<T>::value>{}; + +#define BOOST_MATH_META_BOOL(name, Default)\ + template <bool N = Default> struct name : public boost::mpl::bool_<N>{};\ + namespace detail{\ + template <bool N>\ + char test_is_valid_arg(const name<N>*);\ + char test_is_default_arg(const name<Default>*);\ + template <class T> struct is_##name##_imp\ + {\ + template <bool N> static char test(const name<N>*);\ + static double test(...);\ + BOOST_STATIC_CONSTANT(bool, value = sizeof(test(static_cast<T*>(0))) == 1);\ + };\ + }\ + template <class T> struct is_##name : public boost::mpl::bool_< ::boost::math::policies::detail::is_##name##_imp<T>::value>{}; +#else +#define BOOST_MATH_META_INT(Type, name, Default)\ + template <Type N = Default> struct name : public boost::mpl::int_<N>{};\ + namespace detail{\ + template <Type N>\ + char test_is_valid_arg(const name<N>*);\ + char test_is_default_arg(const name<Default>*);\ + template <class T> struct is_##name##_tester\ + {\ + template <Type N> static char test(const name<N>&);\ + static double test(...);\ + };\ + template <class T> struct is_##name##_imp\ + {\ + static T inst;\ + BOOST_STATIC_CONSTANT(bool, value = sizeof( ::boost::math::policies::detail::is_##name##_tester<T>::test(inst)) == 1);\ + };\ + }\ + template <class T> struct is_##name : public boost::mpl::bool_< ::boost::math::policies::detail::is_##name##_imp<T>::value>\ + {\ + template <class U> struct apply{ typedef is_##name<U> type; };\ + }; + +#define BOOST_MATH_META_BOOL(name, Default)\ + template <bool N = Default> struct name : public boost::mpl::bool_<N>{};\ + namespace detail{\ + template <bool N>\ + char test_is_valid_arg(const name<N>*);\ + char test_is_default_arg(const name<Default>*);\ + template <class T> struct is_##name##_tester\ + {\ + template <bool N> static char test(const name<N>&);\ + static double test(...);\ + };\ + template <class T> struct is_##name##_imp\ + {\ + static T inst;\ + BOOST_STATIC_CONSTANT(bool, value = sizeof( ::boost::math::policies::detail::is_##name##_tester<T>::test(inst)) == 1);\ + };\ + }\ + template <class T> struct is_##name : public boost::mpl::bool_< ::boost::math::policies::detail::is_##name##_imp<T>::value>\ + {\ + template <class U> struct apply{ typedef is_##name<U> type; };\ + }; +#endif +// +// Begin by defining policy types for error handling: +// +enum error_policy_type +{ + throw_on_error = 0, + errno_on_error = 1, + ignore_error = 2, + user_error = 3 +}; + +BOOST_MATH_META_INT(error_policy_type, domain_error, BOOST_MATH_DOMAIN_ERROR_POLICY) +BOOST_MATH_META_INT(error_policy_type, pole_error, BOOST_MATH_POLE_ERROR_POLICY) +BOOST_MATH_META_INT(error_policy_type, overflow_error, BOOST_MATH_OVERFLOW_ERROR_POLICY) +BOOST_MATH_META_INT(error_policy_type, underflow_error, BOOST_MATH_UNDERFLOW_ERROR_POLICY) +BOOST_MATH_META_INT(error_policy_type, denorm_error, BOOST_MATH_DENORM_ERROR_POLICY) +BOOST_MATH_META_INT(error_policy_type, evaluation_error, BOOST_MATH_EVALUATION_ERROR_POLICY) +BOOST_MATH_META_INT(error_policy_type, rounding_error, BOOST_MATH_ROUNDING_ERROR_POLICY) +BOOST_MATH_META_INT(error_policy_type, indeterminate_result_error, BOOST_MATH_INDETERMINATE_RESULT_ERROR_POLICY) + +// +// Policy types for internal promotion: +// +BOOST_MATH_META_BOOL(promote_float, BOOST_MATH_PROMOTE_FLOAT_POLICY) +BOOST_MATH_META_BOOL(promote_double, BOOST_MATH_PROMOTE_DOUBLE_POLICY) +BOOST_MATH_META_BOOL(assert_undefined, BOOST_MATH_ASSERT_UNDEFINED_POLICY) +// +// Policy types for discrete quantiles: +// +enum discrete_quantile_policy_type +{ + real, + integer_round_outwards, + integer_round_inwards, + integer_round_down, + integer_round_up, + integer_round_nearest +}; + +BOOST_MATH_META_INT(discrete_quantile_policy_type, discrete_quantile, BOOST_MATH_DISCRETE_QUANTILE_POLICY) +// +// Precision: +// +BOOST_MATH_META_INT(int, digits10, BOOST_MATH_DIGITS10_POLICY) +BOOST_MATH_META_INT(int, digits2, 0) +// +// Iterations: +// +BOOST_MATH_META_INT(unsigned long, max_series_iterations, BOOST_MATH_MAX_SERIES_ITERATION_POLICY) +BOOST_MATH_META_INT(unsigned long, max_root_iterations, BOOST_MATH_MAX_ROOT_ITERATION_POLICY) +// +// Define the names for each possible policy: +// +#define BOOST_MATH_PARAMETER(name)\ + BOOST_PARAMETER_TEMPLATE_KEYWORD(name##_name)\ + BOOST_PARAMETER_NAME(name##_name) + +struct default_policy{}; + +namespace detail{ +// +// Trait to work out bits precision from digits10 and digits2: +// +template <class Digits10, class Digits2> +struct precision +{ + // + // Now work out the precision: + // + typedef typename mpl::if_c< + (Digits10::value == 0), + digits2<0>, + digits2<((Digits10::value + 1) * 1000L) / 301L> + >::type digits2_type; +public: +#ifdef __BORLANDC__ + typedef typename mpl::if_c< + (Digits2::value > ::boost::math::policies::detail::precision<Digits10,Digits2>::digits2_type::value), + Digits2, digits2_type>::type type; +#else + typedef typename mpl::if_c< + (Digits2::value > digits2_type::value), + Digits2, digits2_type>::type type; +#endif +}; + +template <class A, class B, bool b> +struct select_result +{ + typedef A type; +}; +template <class A, class B> +struct select_result<A, B, false> +{ + typedef typename mpl::deref<B>::type type; +}; + +template <class Seq, class Pred, class DefaultType> +struct find_arg +{ +private: + typedef typename mpl::find_if<Seq, Pred>::type iter; + typedef typename mpl::end<Seq>::type end_type; +public: + typedef typename select_result< + DefaultType, iter, + ::boost::is_same<iter, end_type>::value>::type type; +}; + +double test_is_valid_arg(...); +double test_is_default_arg(...); +char test_is_valid_arg(const default_policy*); +char test_is_default_arg(const default_policy*); + +template <class T> +struct is_valid_policy_imp +{ + BOOST_STATIC_CONSTANT(bool, value = sizeof(::boost::math::policies::detail::test_is_valid_arg(static_cast<T*>(0))) == 1); +}; + +template <class T> +struct is_default_policy_imp +{ + BOOST_STATIC_CONSTANT(bool, value = sizeof(::boost::math::policies::detail::test_is_default_arg(static_cast<T*>(0))) == 1); +}; + +template <class T> struct is_valid_policy +: public mpl::bool_< + ::boost::math::policies::detail::is_valid_policy_imp<T>::value> +{}; + +template <class T> struct is_default_policy +: public mpl::bool_< + ::boost::math::policies::detail::is_default_policy_imp<T>::value> +{ + template <class U> + struct apply + { + typedef is_default_policy<U> type; + }; +}; + +template <class Seq, class T, int N> +struct append_N +{ + typedef typename mpl::push_back<Seq, T>::type new_seq; + typedef typename append_N<new_seq, T, N-1>::type type; +}; + +template <class Seq, class T> +struct append_N<Seq, T, 0> +{ + typedef Seq type; +}; + +// +// Traits class to work out what template parameters our default +// policy<> class will have when modified for forwarding: +// +template <bool f, bool d> +struct default_args +{ + typedef promote_float<false> arg1; + typedef promote_double<false> arg2; +}; + +template <> +struct default_args<false, false> +{ + typedef default_policy arg1; + typedef default_policy arg2; +}; + +template <> +struct default_args<true, false> +{ + typedef promote_float<false> arg1; + typedef default_policy arg2; +}; + +template <> +struct default_args<false, true> +{ + typedef promote_double<false> arg1; + typedef default_policy arg2; +}; + +typedef default_args<BOOST_MATH_PROMOTE_FLOAT_POLICY, BOOST_MATH_PROMOTE_DOUBLE_POLICY>::arg1 forwarding_arg1; +typedef default_args<BOOST_MATH_PROMOTE_FLOAT_POLICY, BOOST_MATH_PROMOTE_DOUBLE_POLICY>::arg2 forwarding_arg2; + +} // detail +// +// Now define the policy type with enough arguments to handle all +// the policies: +// +template <class A1 = default_policy, + class A2 = default_policy, + class A3 = default_policy, + class A4 = default_policy, + class A5 = default_policy, + class A6 = default_policy, + class A7 = default_policy, + class A8 = default_policy, + class A9 = default_policy, + class A10 = default_policy, + class A11 = default_policy, + class A12 = default_policy, + class A13 = default_policy> +struct policy +{ +private: + // + // Validate all our arguments: + // + BOOST_STATIC_ASSERT(::boost::math::policies::detail::is_valid_policy<A1>::value); + BOOST_STATIC_ASSERT(::boost::math::policies::detail::is_valid_policy<A2>::value); + BOOST_STATIC_ASSERT(::boost::math::policies::detail::is_valid_policy<A3>::value); + BOOST_STATIC_ASSERT(::boost::math::policies::detail::is_valid_policy<A4>::value); + BOOST_STATIC_ASSERT(::boost::math::policies::detail::is_valid_policy<A5>::value); + BOOST_STATIC_ASSERT(::boost::math::policies::detail::is_valid_policy<A6>::value); + BOOST_STATIC_ASSERT(::boost::math::policies::detail::is_valid_policy<A7>::value); + BOOST_STATIC_ASSERT(::boost::math::policies::detail::is_valid_policy<A8>::value); + BOOST_STATIC_ASSERT(::boost::math::policies::detail::is_valid_policy<A9>::value); + BOOST_STATIC_ASSERT(::boost::math::policies::detail::is_valid_policy<A10>::value); + BOOST_STATIC_ASSERT(::boost::math::policies::detail::is_valid_policy<A11>::value); + BOOST_STATIC_ASSERT(::boost::math::policies::detail::is_valid_policy<A12>::value); + BOOST_STATIC_ASSERT(::boost::math::policies::detail::is_valid_policy<A13>::value); + // + // Typelist of the arguments: + // + typedef mpl::list<A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13> arg_list; + +public: + typedef typename detail::find_arg<arg_list, is_domain_error<mpl::_1>, domain_error<> >::type domain_error_type; + typedef typename detail::find_arg<arg_list, is_pole_error<mpl::_1>, pole_error<> >::type pole_error_type; + typedef typename detail::find_arg<arg_list, is_overflow_error<mpl::_1>, overflow_error<> >::type overflow_error_type; + typedef typename detail::find_arg<arg_list, is_underflow_error<mpl::_1>, underflow_error<> >::type underflow_error_type; + typedef typename detail::find_arg<arg_list, is_denorm_error<mpl::_1>, denorm_error<> >::type denorm_error_type; + typedef typename detail::find_arg<arg_list, is_evaluation_error<mpl::_1>, evaluation_error<> >::type evaluation_error_type; + typedef typename detail::find_arg<arg_list, is_rounding_error<mpl::_1>, rounding_error<> >::type rounding_error_type; + typedef typename detail::find_arg<arg_list, is_indeterminate_result_error<mpl::_1>, indeterminate_result_error<> >::type indeterminate_result_error_type; +private: + // + // Now work out the precision: + // + typedef typename detail::find_arg<arg_list, is_digits10<mpl::_1>, digits10<> >::type digits10_type; + typedef typename detail::find_arg<arg_list, is_digits2<mpl::_1>, digits2<> >::type bits_precision_type; +public: + typedef typename detail::precision<digits10_type, bits_precision_type>::type precision_type; + // + // Internal promotion: + // + typedef typename detail::find_arg<arg_list, is_promote_float<mpl::_1>, promote_float<> >::type promote_float_type; + typedef typename detail::find_arg<arg_list, is_promote_double<mpl::_1>, promote_double<> >::type promote_double_type; + // + // Discrete quantiles: + // + typedef typename detail::find_arg<arg_list, is_discrete_quantile<mpl::_1>, discrete_quantile<> >::type discrete_quantile_type; + // + // Mathematically undefined properties: + // + typedef typename detail::find_arg<arg_list, is_assert_undefined<mpl::_1>, discrete_quantile<> >::type assert_undefined_type; + // + // Max iterations: + // + typedef typename detail::find_arg<arg_list, is_max_series_iterations<mpl::_1>, max_series_iterations<> >::type max_series_iterations_type; + typedef typename detail::find_arg<arg_list, is_max_root_iterations<mpl::_1>, max_root_iterations<> >::type max_root_iterations_type; +}; +// +// These full specializations are defined to reduce the amount of +// template instantiations that have to take place when using the default +// policies, they have quite a large impact on compile times: +// +template <> +struct policy<default_policy, default_policy, default_policy, default_policy, default_policy, default_policy, default_policy, default_policy, default_policy, default_policy, default_policy> +{ +public: + typedef domain_error<> domain_error_type; + typedef pole_error<> pole_error_type; + typedef overflow_error<> overflow_error_type; + typedef underflow_error<> underflow_error_type; + typedef denorm_error<> denorm_error_type; + typedef evaluation_error<> evaluation_error_type; + typedef rounding_error<> rounding_error_type; + typedef indeterminate_result_error<> indeterminate_result_error_type; +#if BOOST_MATH_DIGITS10_POLICY == 0 + typedef digits2<> precision_type; +#else + typedef detail::precision<digits10<>, digits2<> >::type precision_type; +#endif + typedef promote_float<> promote_float_type; + typedef promote_double<> promote_double_type; + typedef discrete_quantile<> discrete_quantile_type; + typedef assert_undefined<> assert_undefined_type; + typedef max_series_iterations<> max_series_iterations_type; + typedef max_root_iterations<> max_root_iterations_type; +}; + +template <> +struct policy<detail::forwarding_arg1, detail::forwarding_arg2, default_policy, default_policy, default_policy, default_policy, default_policy, default_policy, default_policy, default_policy, default_policy> +{ +public: + typedef domain_error<> domain_error_type; + typedef pole_error<> pole_error_type; + typedef overflow_error<> overflow_error_type; + typedef underflow_error<> underflow_error_type; + typedef denorm_error<> denorm_error_type; + typedef evaluation_error<> evaluation_error_type; + typedef rounding_error<> rounding_error_type; + typedef indeterminate_result_error<> indeterminate_result_error_type; +#if BOOST_MATH_DIGITS10_POLICY == 0 + typedef digits2<> precision_type; +#else + typedef detail::precision<digits10<>, digits2<> >::type precision_type; +#endif + typedef promote_float<false> promote_float_type; + typedef promote_double<false> promote_double_type; + typedef discrete_quantile<> discrete_quantile_type; + typedef assert_undefined<> assert_undefined_type; + typedef max_series_iterations<> max_series_iterations_type; + typedef max_root_iterations<> max_root_iterations_type; +}; + +template <class Policy, + class A1 = default_policy, + class A2 = default_policy, + class A3 = default_policy, + class A4 = default_policy, + class A5 = default_policy, + class A6 = default_policy, + class A7 = default_policy, + class A8 = default_policy, + class A9 = default_policy, + class A10 = default_policy, + class A11 = default_policy, + class A12 = default_policy, + class A13 = default_policy> +struct normalise +{ +private: + typedef mpl::list<A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13> arg_list; + typedef typename detail::find_arg<arg_list, is_domain_error<mpl::_1>, typename Policy::domain_error_type >::type domain_error_type; + typedef typename detail::find_arg<arg_list, is_pole_error<mpl::_1>, typename Policy::pole_error_type >::type pole_error_type; + typedef typename detail::find_arg<arg_list, is_overflow_error<mpl::_1>, typename Policy::overflow_error_type >::type overflow_error_type; + typedef typename detail::find_arg<arg_list, is_underflow_error<mpl::_1>, typename Policy::underflow_error_type >::type underflow_error_type; + typedef typename detail::find_arg<arg_list, is_denorm_error<mpl::_1>, typename Policy::denorm_error_type >::type denorm_error_type; + typedef typename detail::find_arg<arg_list, is_evaluation_error<mpl::_1>, typename Policy::evaluation_error_type >::type evaluation_error_type; + typedef typename detail::find_arg<arg_list, is_rounding_error<mpl::_1>, typename Policy::rounding_error_type >::type rounding_error_type; + typedef typename detail::find_arg<arg_list, is_indeterminate_result_error<mpl::_1>, typename Policy::indeterminate_result_error_type >::type indeterminate_result_error_type; + // + // Now work out the precision: + // + typedef typename detail::find_arg<arg_list, is_digits10<mpl::_1>, digits10<> >::type digits10_type; + typedef typename detail::find_arg<arg_list, is_digits2<mpl::_1>, typename Policy::precision_type >::type bits_precision_type; + typedef typename detail::precision<digits10_type, bits_precision_type>::type precision_type; + // + // Internal promotion: + // + typedef typename detail::find_arg<arg_list, is_promote_float<mpl::_1>, typename Policy::promote_float_type >::type promote_float_type; + typedef typename detail::find_arg<arg_list, is_promote_double<mpl::_1>, typename Policy::promote_double_type >::type promote_double_type; + // + // Discrete quantiles: + // + typedef typename detail::find_arg<arg_list, is_discrete_quantile<mpl::_1>, typename Policy::discrete_quantile_type >::type discrete_quantile_type; + // + // Mathematically undefined properties: + // + typedef typename detail::find_arg<arg_list, is_assert_undefined<mpl::_1>, discrete_quantile<> >::type assert_undefined_type; + // + // Max iterations: + // + typedef typename detail::find_arg<arg_list, is_max_series_iterations<mpl::_1>, max_series_iterations<> >::type max_series_iterations_type; + typedef typename detail::find_arg<arg_list, is_max_root_iterations<mpl::_1>, max_root_iterations<> >::type max_root_iterations_type; + // + // Define a typelist of the policies: + // + typedef mpl::vector< + domain_error_type, + pole_error_type, + overflow_error_type, + underflow_error_type, + denorm_error_type, + evaluation_error_type, + rounding_error_type, + indeterminate_result_error_type, + precision_type, + promote_float_type, + promote_double_type, + discrete_quantile_type, + assert_undefined_type, + max_series_iterations_type, + max_root_iterations_type> result_list; + // + // Remove all the policies that are the same as the default: + // + typedef typename mpl::remove_if<result_list, detail::is_default_policy<mpl::_> >::type reduced_list; + // + // Pad out the list with defaults: + // + typedef typename detail::append_N<reduced_list, default_policy, (14 - ::boost::mpl::size<reduced_list>::value)>::type result_type; +public: + typedef policy< + typename mpl::at<result_type, mpl::int_<0> >::type, + typename mpl::at<result_type, mpl::int_<1> >::type, + typename mpl::at<result_type, mpl::int_<2> >::type, + typename mpl::at<result_type, mpl::int_<3> >::type, + typename mpl::at<result_type, mpl::int_<4> >::type, + typename mpl::at<result_type, mpl::int_<5> >::type, + typename mpl::at<result_type, mpl::int_<6> >::type, + typename mpl::at<result_type, mpl::int_<7> >::type, + typename mpl::at<result_type, mpl::int_<8> >::type, + typename mpl::at<result_type, mpl::int_<9> >::type, + typename mpl::at<result_type, mpl::int_<10> >::type, + typename mpl::at<result_type, mpl::int_<11> >::type, + typename mpl::at<result_type, mpl::int_<12> >::type > type; +}; +// +// Full specialisation to speed up compilation of the common case: +// +template <> +struct normalise<policy<>, + promote_float<false>, + promote_double<false>, + discrete_quantile<>, + assert_undefined<>, + default_policy, + default_policy, + default_policy, + default_policy, + default_policy, + default_policy, + default_policy> +{ + typedef policy<detail::forwarding_arg1, detail::forwarding_arg2> type; +}; + +template <> +struct normalise<policy<detail::forwarding_arg1, detail::forwarding_arg2>, + promote_float<false>, + promote_double<false>, + discrete_quantile<>, + assert_undefined<>, + default_policy, + default_policy, + default_policy, + default_policy, + default_policy, + default_policy, + default_policy> +{ + typedef policy<detail::forwarding_arg1, detail::forwarding_arg2> type; +}; + +inline policy<> make_policy() +{ return policy<>(); } + +template <class A1> +inline typename normalise<policy<>, A1>::type make_policy(const A1&) +{ + typedef typename normalise<policy<>, A1>::type result_type; + return result_type(); +} + +template <class A1, class A2> +inline typename normalise<policy<>, A1, A2>::type make_policy(const A1&, const A2&) +{ + typedef typename normalise<policy<>, A1, A2>::type result_type; + return result_type(); +} + +template <class A1, class A2, class A3> +inline typename normalise<policy<>, A1, A2, A3>::type make_policy(const A1&, const A2&, const A3&) +{ + typedef typename normalise<policy<>, A1, A2, A3>::type result_type; + return result_type(); +} + +template <class A1, class A2, class A3, class A4> +inline typename normalise<policy<>, A1, A2, A3, A4>::type make_policy(const A1&, const A2&, const A3&, const A4&) +{ + typedef typename normalise<policy<>, A1, A2, A3, A4>::type result_type; + return result_type(); +} + +template <class A1, class A2, class A3, class A4, class A5> +inline typename normalise<policy<>, A1, A2, A3, A4, A5>::type make_policy(const A1&, const A2&, const A3&, const A4&, const A5&) +{ + typedef typename normalise<policy<>, A1, A2, A3, A4, A5>::type result_type; + return result_type(); +} + +template <class A1, class A2, class A3, class A4, class A5, class A6> +inline typename normalise<policy<>, A1, A2, A3, A4, A5, A6>::type make_policy(const A1&, const A2&, const A3&, const A4&, const A5&, const A6&) +{ + typedef typename normalise<policy<>, A1, A2, A3, A4, A5, A6>::type result_type; + return result_type(); +} + +template <class A1, class A2, class A3, class A4, class A5, class A6, class A7> +inline typename normalise<policy<>, A1, A2, A3, A4, A5, A6, A7>::type make_policy(const A1&, const A2&, const A3&, const A4&, const A5&, const A6&, const A7&) +{ + typedef typename normalise<policy<>, A1, A2, A3, A4, A5, A6, A7>::type result_type; + return result_type(); +} + +template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8> +inline typename normalise<policy<>, A1, A2, A3, A4, A5, A6, A7, A8>::type make_policy(const A1&, const A2&, const A3&, const A4&, const A5&, const A6&, const A7&, const A8&) +{ + typedef typename normalise<policy<>, A1, A2, A3, A4, A5, A6, A7, A8>::type result_type; + return result_type(); +} + +template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9> +inline typename normalise<policy<>, A1, A2, A3, A4, A5, A6, A7, A8, A9>::type make_policy(const A1&, const A2&, const A3&, const A4&, const A5&, const A6&, const A7&, const A8&, const A9&) +{ + typedef typename normalise<policy<>, A1, A2, A3, A4, A5, A6, A7, A8, A9>::type result_type; + return result_type(); +} + +template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10> +inline typename normalise<policy<>, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10>::type make_policy(const A1&, const A2&, const A3&, const A4&, const A5&, const A6&, const A7&, const A8&, const A9&, const A10&) +{ + typedef typename normalise<policy<>, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10>::type result_type; + return result_type(); +} + +template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10, class A11> +inline typename normalise<policy<>, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11>::type make_policy(const A1&, const A2&, const A3&, const A4&, const A5&, const A6&, const A7&, const A8&, const A9&, const A10&, const A11&) +{ + typedef typename normalise<policy<>, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11>::type result_type; + return result_type(); +} + +// +// Traits class to handle internal promotion: +// +template <class Real, class Policy> +struct evaluation +{ + typedef Real type; +}; + +template <class Policy> +struct evaluation<float, Policy> +{ + typedef typename mpl::if_<typename Policy::promote_float_type, double, float>::type type; +}; + +template <class Policy> +struct evaluation<double, Policy> +{ + typedef typename mpl::if_<typename Policy::promote_double_type, long double, double>::type type; +}; + +#ifdef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS + +template <class Real> +struct basic_digits : public mpl::int_<0>{ }; +template <> +struct basic_digits<float> : public mpl::int_<FLT_MANT_DIG>{ }; +template <> +struct basic_digits<double> : public mpl::int_<DBL_MANT_DIG>{ }; +template <> +struct basic_digits<long double> : public mpl::int_<LDBL_MANT_DIG>{ }; + +template <class Real, class Policy> +struct precision +{ + typedef typename Policy::precision_type precision_type; + typedef basic_digits<Real> digits_t; + typedef typename mpl::if_< + mpl::equal_to<digits_t, mpl::int_<0> >, + // Possibly unknown precision: + precision_type, + typename mpl::if_< + mpl::or_<mpl::less_equal<digits_t, precision_type>, mpl::less_equal<precision_type, mpl::int_<0> > >, + // Default case, full precision for RealType: + digits2< ::std::numeric_limits<Real>::digits>, + // User customised precision: + precision_type + >::type + >::type type; +}; + +template <class Policy> +struct precision<float, Policy> +{ + typedef digits2<FLT_MANT_DIG> type; +}; +template <class Policy> +struct precision<double, Policy> +{ + typedef digits2<DBL_MANT_DIG> type; +}; +template <class Policy> +struct precision<long double, Policy> +{ + typedef digits2<LDBL_MANT_DIG> type; +}; + +#else + +template <class Real, class Policy> +struct precision +{ +#ifndef __BORLANDC__ + typedef typename Policy::precision_type precision_type; + typedef typename mpl::if_c< + ((::std::numeric_limits<Real>::is_specialized == 0) || (::std::numeric_limits<Real>::digits == 0)), + // Possibly unknown precision: + precision_type, + typename mpl::if_c< + ((::std::numeric_limits<Real>::digits <= precision_type::value) + || (Policy::precision_type::value <= 0)), + // Default case, full precision for RealType: + digits2< ::std::numeric_limits<Real>::digits>, + // User customised precision: + precision_type + >::type + >::type type; +#else + typedef typename Policy::precision_type precision_type; + typedef mpl::int_< ::std::numeric_limits<Real>::digits> digits_t; + typedef mpl::bool_< ::std::numeric_limits<Real>::is_specialized> spec_t; + typedef typename mpl::if_< + mpl::or_<mpl::equal_to<spec_t, mpl::false_>, mpl::equal_to<digits_t, mpl::int_<0> > >, + // Possibly unknown precision: + precision_type, + typename mpl::if_< + mpl::or_<mpl::less_equal<digits_t, precision_type>, mpl::less_equal<precision_type, mpl::int_<0> > >, + // Default case, full precision for RealType: + digits2< ::std::numeric_limits<Real>::digits>, + // User customised precision: + precision_type + >::type + >::type type; +#endif +}; + +#endif + +namespace detail{ + +template <class T, class Policy> +inline int digits_imp(mpl::true_ const&) +{ +#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS + BOOST_STATIC_ASSERT( ::std::numeric_limits<T>::is_specialized); +#else + BOOST_ASSERT(::std::numeric_limits<T>::is_specialized); +#endif + typedef typename boost::math::policies::precision<T, Policy>::type p_t; + return p_t::value; +} + +template <class T, class Policy> +inline int digits_imp(mpl::false_ const&) +{ + return tools::digits<T>(); +} + +} // namespace detail + +template <class T, class Policy> +inline int digits(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(T)) +{ + typedef mpl::bool_< std::numeric_limits<T>::is_specialized > tag_type; + return detail::digits_imp<T, Policy>(tag_type()); +} + +template <class Policy> +inline unsigned long get_max_series_iterations() +{ + typedef typename Policy::max_series_iterations_type iter_type; + return iter_type::value; +} + +template <class Policy> +inline unsigned long get_max_root_iterations() +{ + typedef typename Policy::max_root_iterations_type iter_type; + return iter_type::value; +} + +namespace detail{ + +template <class T, class Digits, class Small, class Default> +struct series_factor_calc +{ + static T get() + { + return ldexp(T(1.0), 1 - Digits::value); + } +}; + +template <class T, class Digits> +struct series_factor_calc<T, Digits, mpl::true_, mpl::true_> +{ + static T get() + { + return boost::math::tools::epsilon<T>(); + } +}; +template <class T, class Digits> +struct series_factor_calc<T, Digits, mpl::true_, mpl::false_> +{ + static T get() + { + static const boost::uintmax_t v = static_cast<boost::uintmax_t>(1u) << (Digits::value - 1); + return 1 / static_cast<T>(v); + } +}; +template <class T, class Digits> +struct series_factor_calc<T, Digits, mpl::false_, mpl::true_> +{ + static T get() + { + return boost::math::tools::epsilon<T>(); + } +}; + +template <class T, class Policy> +inline T get_epsilon_imp(mpl::true_ const&) +{ +#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS + BOOST_STATIC_ASSERT( ::std::numeric_limits<T>::is_specialized); +#else + BOOST_ASSERT(::std::numeric_limits<T>::is_specialized); +#endif + typedef typename boost::math::policies::precision<T, Policy>::type p_t; + typedef mpl::bool_<p_t::value <= std::numeric_limits<boost::uintmax_t>::digits> is_small_int; + typedef mpl::bool_<p_t::value >= std::numeric_limits<T>::digits> is_default_value; + return series_factor_calc<T, p_t, is_small_int, is_default_value>::get(); +} + +template <class T, class Policy> +inline T get_epsilon_imp(mpl::false_ const&) +{ + return tools::epsilon<T>(); +} + +} // namespace detail + +template <class T, class Policy> +inline T get_epsilon(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(T)) +{ + typedef mpl::bool_< std::numeric_limits<T>::is_specialized > tag_type; + return detail::get_epsilon_imp<T, Policy>(tag_type()); +} + +namespace detail{ + +template <class A1, + class A2, + class A3, + class A4, + class A5, + class A6, + class A7, + class A8, + class A9, + class A10, + class A11> +char test_is_policy(const policy<A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11>*); +double test_is_policy(...); + +template <class P> +struct is_policy_imp +{ + BOOST_STATIC_CONSTANT(bool, value = (sizeof(::boost::math::policies::detail::test_is_policy(static_cast<P*>(0))) == 1)); +}; + +} + +template <class P> +struct is_policy : public mpl::bool_< ::boost::math::policies::detail::is_policy_imp<P>::value> {}; + +}}} // namespaces + +#endif // BOOST_MATH_POLICY_HPP + + + diff --git a/Utilities/BGL/boost/math/quaternion.hpp b/Utilities/BGL/boost/math/quaternion.hpp new file mode 100644 index 0000000000000000000000000000000000000000..e4640d7c8c2af80cc52437e1ad7749d57744be44 --- /dev/null +++ b/Utilities/BGL/boost/math/quaternion.hpp @@ -0,0 +1,1924 @@ +// boost quaternion.hpp header file + +// (C) Copyright Hubert Holin 2001. +// 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) + +// See http://www.boost.org for updates, documentation, and revision history. + +#ifndef BOOST_QUATERNION_HPP +#define BOOST_QUATERNION_HPP + + +#include <complex> +#include <iosfwd> // for the "<<" and ">>" operators +#include <sstream> // for the "<<" operator + +#include <boost/config.hpp> // for BOOST_NO_STD_LOCALE +#include <boost/detail/workaround.hpp> +#ifndef BOOST_NO_STD_LOCALE + #include <locale> // for the "<<" operator +#endif /* BOOST_NO_STD_LOCALE */ + +#include <valarray> + + + +#include <boost/math/special_functions/sinc.hpp> // for the Sinus cardinal +#include <boost/math/special_functions/sinhc.hpp> // for the Hyperbolic Sinus cardinal + + +namespace boost +{ + namespace math + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + // gcc 2.95.x uses expression templates for valarray calculations, but + // the result is not conforming. We need BOOST_GET_VALARRAY to get an + // actual valarray result when we need to call a member function + #define BOOST_GET_VALARRAY(T,x) ::std::valarray<T>(x) + // gcc 2.95.x has an "std::ios" class that is similar to + // "std::ios_base", so we just use a #define + #define BOOST_IOS_BASE ::std::ios + // gcc 2.x ignores function scope using declarations, + // put them in the scope of the enclosing namespace instead: + using ::std::valarray; + using ::std::sqrt; + using ::std::cos; + using ::std::sin; + using ::std::exp; + using ::std::cosh; +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + +#define BOOST_QUATERNION_ACCESSOR_GENERATOR(type) \ + type real() const \ + { \ + return(a); \ + } \ + \ + quaternion<type> unreal() const \ + { \ + return(quaternion<type>(static_cast<type>(0),b,c,d)); \ + } \ + \ + type R_component_1() const \ + { \ + return(a); \ + } \ + \ + type R_component_2() const \ + { \ + return(b); \ + } \ + \ + type R_component_3() const \ + { \ + return(c); \ + } \ + \ + type R_component_4() const \ + { \ + return(d); \ + } \ + \ + ::std::complex<type> C_component_1() const \ + { \ + return(::std::complex<type>(a,b)); \ + } \ + \ + ::std::complex<type> C_component_2() const \ + { \ + return(::std::complex<type>(c,d)); \ + } + + +#define BOOST_QUATERNION_MEMBER_ASSIGNMENT_GENERATOR(type) \ + template<typename X> \ + quaternion<type> & operator = (quaternion<X> const & a_affecter) \ + { \ + a = static_cast<type>(a_affecter.R_component_1()); \ + b = static_cast<type>(a_affecter.R_component_2()); \ + c = static_cast<type>(a_affecter.R_component_3()); \ + d = static_cast<type>(a_affecter.R_component_4()); \ + \ + return(*this); \ + } \ + \ + quaternion<type> & operator = (quaternion<type> const & a_affecter) \ + { \ + a = a_affecter.a; \ + b = a_affecter.b; \ + c = a_affecter.c; \ + d = a_affecter.d; \ + \ + return(*this); \ + } \ + \ + quaternion<type> & operator = (type const & a_affecter) \ + { \ + a = a_affecter; \ + \ + b = c = d = static_cast<type>(0); \ + \ + return(*this); \ + } \ + \ + quaternion<type> & operator = (::std::complex<type> const & a_affecter) \ + { \ + a = a_affecter.real(); \ + b = a_affecter.imag(); \ + \ + c = d = static_cast<type>(0); \ + \ + return(*this); \ + } + + +#define BOOST_QUATERNION_MEMBER_DATA_GENERATOR(type) \ + type a; \ + type b; \ + type c; \ + type d; + + + template<typename T> + class quaternion + { + public: + + typedef T value_type; + + + // constructor for H seen as R^4 + // (also default constructor) + + explicit quaternion( T const & requested_a = T(), + T const & requested_b = T(), + T const & requested_c = T(), + T const & requested_d = T()) + : a(requested_a), + b(requested_b), + c(requested_c), + d(requested_d) + { + // nothing to do! + } + + + // constructor for H seen as C^2 + + explicit quaternion( ::std::complex<T> const & z0, + ::std::complex<T> const & z1 = ::std::complex<T>()) + : a(z0.real()), + b(z0.imag()), + c(z1.real()), + d(z1.imag()) + { + // nothing to do! + } + + + // UNtemplated copy constructor + // (this is taken care of by the compiler itself) + + + // templated copy constructor + + template<typename X> + explicit quaternion(quaternion<X> const & a_recopier) + : a(static_cast<T>(a_recopier.R_component_1())), + b(static_cast<T>(a_recopier.R_component_2())), + c(static_cast<T>(a_recopier.R_component_3())), + d(static_cast<T>(a_recopier.R_component_4())) + { + // nothing to do! + } + + + // destructor + // (this is taken care of by the compiler itself) + + + // accessors + // + // Note: Like complex number, quaternions do have a meaningful notion of "real part", + // but unlike them there is no meaningful notion of "imaginary part". + // Instead there is an "unreal part" which itself is a quaternion, and usually + // nothing simpler (as opposed to the complex number case). + // However, for practicallity, there are accessors for the other components + // (these are necessary for the templated copy constructor, for instance). + + BOOST_QUATERNION_ACCESSOR_GENERATOR(T) + + // assignment operators + + BOOST_QUATERNION_MEMBER_ASSIGNMENT_GENERATOR(T) + + // other assignment-related operators + // + // NOTE: Quaternion multiplication is *NOT* commutative; + // symbolically, "q *= rhs;" means "q = q * rhs;" + // and "q /= rhs;" means "q = q * inverse_of(rhs);" + + quaternion<T> & operator += (T const & rhs) + { + T at = a + rhs; // exception guard + + a = at; + + return(*this); + } + + + quaternion<T> & operator += (::std::complex<T> const & rhs) + { + T at = a + rhs.real(); // exception guard + T bt = b + rhs.imag(); // exception guard + + a = at; + b = bt; + + return(*this); + } + + + template<typename X> + quaternion<T> & operator += (quaternion<X> const & rhs) + { + T at = a + static_cast<T>(rhs.R_component_1()); // exception guard + T bt = b + static_cast<T>(rhs.R_component_2()); // exception guard + T ct = c + static_cast<T>(rhs.R_component_3()); // exception guard + T dt = d + static_cast<T>(rhs.R_component_4()); // exception guard + + a = at; + b = bt; + c = ct; + d = dt; + + return(*this); + } + + + + quaternion<T> & operator -= (T const & rhs) + { + T at = a - rhs; // exception guard + + a = at; + + return(*this); + } + + + quaternion<T> & operator -= (::std::complex<T> const & rhs) + { + T at = a - rhs.real(); // exception guard + T bt = b - rhs.imag(); // exception guard + + a = at; + b = bt; + + return(*this); + } + + + template<typename X> + quaternion<T> & operator -= (quaternion<X> const & rhs) + { + T at = a - static_cast<T>(rhs.R_component_1()); // exception guard + T bt = b - static_cast<T>(rhs.R_component_2()); // exception guard + T ct = c - static_cast<T>(rhs.R_component_3()); // exception guard + T dt = d - static_cast<T>(rhs.R_component_4()); // exception guard + + a = at; + b = bt; + c = ct; + d = dt; + + return(*this); + } + + + quaternion<T> & operator *= (T const & rhs) + { + T at = a * rhs; // exception guard + T bt = b * rhs; // exception guard + T ct = c * rhs; // exception guard + T dt = d * rhs; // exception guard + + a = at; + b = bt; + c = ct; + d = dt; + + return(*this); + } + + + quaternion<T> & operator *= (::std::complex<T> const & rhs) + { + T ar = rhs.real(); + T br = rhs.imag(); + + T at = +a*ar-b*br; + T bt = +a*br+b*ar; + T ct = +c*ar+d*br; + T dt = -c*br+d*ar; + + a = at; + b = bt; + c = ct; + d = dt; + + return(*this); + } + + + template<typename X> + quaternion<T> & operator *= (quaternion<X> const & rhs) + { + T ar = static_cast<T>(rhs.R_component_1()); + T br = static_cast<T>(rhs.R_component_2()); + T cr = static_cast<T>(rhs.R_component_3()); + T dr = static_cast<T>(rhs.R_component_4()); + + T at = +a*ar-b*br-c*cr-d*dr; + T bt = +a*br+b*ar+c*dr-d*cr; //(a*br+ar*b)+(c*dr-cr*d); + T ct = +a*cr-b*dr+c*ar+d*br; //(a*cr+ar*c)+(d*br-dr*b); + T dt = +a*dr+b*cr-c*br+d*ar; //(a*dr+ar*d)+(b*cr-br*c); + + a = at; + b = bt; + c = ct; + d = dt; + + return(*this); + } + + + + quaternion<T> & operator /= (T const & rhs) + { + T at = a / rhs; // exception guard + T bt = b / rhs; // exception guard + T ct = c / rhs; // exception guard + T dt = d / rhs; // exception guard + + a = at; + b = bt; + c = ct; + d = dt; + + return(*this); + } + + + quaternion<T> & operator /= (::std::complex<T> const & rhs) + { + T ar = rhs.real(); + T br = rhs.imag(); + + T denominator = ar*ar+br*br; + + T at = (+a*ar+b*br)/denominator; //(a*ar+b*br)/denominator; + T bt = (-a*br+b*ar)/denominator; //(ar*b-a*br)/denominator; + T ct = (+c*ar-d*br)/denominator; //(ar*c-d*br)/denominator; + T dt = (+c*br+d*ar)/denominator; //(ar*d+br*c)/denominator; + + a = at; + b = bt; + c = ct; + d = dt; + + return(*this); + } + + + template<typename X> + quaternion<T> & operator /= (quaternion<X> const & rhs) + { + T ar = static_cast<T>(rhs.R_component_1()); + T br = static_cast<T>(rhs.R_component_2()); + T cr = static_cast<T>(rhs.R_component_3()); + T dr = static_cast<T>(rhs.R_component_4()); + + T denominator = ar*ar+br*br+cr*cr+dr*dr; + + T at = (+a*ar+b*br+c*cr+d*dr)/denominator; //(a*ar+b*br+c*cr+d*dr)/denominator; + T bt = (-a*br+b*ar-c*dr+d*cr)/denominator; //((ar*b-a*br)+(cr*d-c*dr))/denominator; + T ct = (-a*cr+b*dr+c*ar-d*br)/denominator; //((ar*c-a*cr)+(dr*b-d*br))/denominator; + T dt = (-a*dr-b*cr+c*br+d*ar)/denominator; //((ar*d-a*dr)+(br*c-b*cr))/denominator; + + a = at; + b = bt; + c = ct; + d = dt; + + return(*this); + } + + + protected: + + BOOST_QUATERNION_MEMBER_DATA_GENERATOR(T) + + + private: + + }; + + + // declaration of quaternion specialization + + template<> class quaternion<float>; + template<> class quaternion<double>; + template<> class quaternion<long double>; + + + // helper templates for converting copy constructors (declaration) + + namespace detail + { + + template< typename T, + typename U + > + quaternion<T> quaternion_type_converter(quaternion<U> const & rhs); + } + + + // implementation of quaternion specialization + + +#define BOOST_QUATERNION_CONSTRUCTOR_GENERATOR(type) \ + explicit quaternion( type const & requested_a = static_cast<type>(0), \ + type const & requested_b = static_cast<type>(0), \ + type const & requested_c = static_cast<type>(0), \ + type const & requested_d = static_cast<type>(0)) \ + : a(requested_a), \ + b(requested_b), \ + c(requested_c), \ + d(requested_d) \ + { \ + } \ + \ + explicit quaternion( ::std::complex<type> const & z0, \ + ::std::complex<type> const & z1 = ::std::complex<type>()) \ + : a(z0.real()), \ + b(z0.imag()), \ + c(z1.real()), \ + d(z1.imag()) \ + { \ + } + + +#define BOOST_QUATERNION_MEMBER_ADD_GENERATOR_1(type) \ + quaternion<type> & operator += (type const & rhs) \ + { \ + a += rhs; \ + \ + return(*this); \ + } + +#define BOOST_QUATERNION_MEMBER_ADD_GENERATOR_2(type) \ + quaternion<type> & operator += (::std::complex<type> const & rhs) \ + { \ + a += rhs.real(); \ + b += rhs.imag(); \ + \ + return(*this); \ + } + +#define BOOST_QUATERNION_MEMBER_ADD_GENERATOR_3(type) \ + template<typename X> \ + quaternion<type> & operator += (quaternion<X> const & rhs) \ + { \ + a += static_cast<type>(rhs.R_component_1()); \ + b += static_cast<type>(rhs.R_component_2()); \ + c += static_cast<type>(rhs.R_component_3()); \ + d += static_cast<type>(rhs.R_component_4()); \ + \ + return(*this); \ + } + +#define BOOST_QUATERNION_MEMBER_SUB_GENERATOR_1(type) \ + quaternion<type> & operator -= (type const & rhs) \ + { \ + a -= rhs; \ + \ + return(*this); \ + } + +#define BOOST_QUATERNION_MEMBER_SUB_GENERATOR_2(type) \ + quaternion<type> & operator -= (::std::complex<type> const & rhs) \ + { \ + a -= rhs.real(); \ + b -= rhs.imag(); \ + \ + return(*this); \ + } + +#define BOOST_QUATERNION_MEMBER_SUB_GENERATOR_3(type) \ + template<typename X> \ + quaternion<type> & operator -= (quaternion<X> const & rhs) \ + { \ + a -= static_cast<type>(rhs.R_component_1()); \ + b -= static_cast<type>(rhs.R_component_2()); \ + c -= static_cast<type>(rhs.R_component_3()); \ + d -= static_cast<type>(rhs.R_component_4()); \ + \ + return(*this); \ + } + +#define BOOST_QUATERNION_MEMBER_MUL_GENERATOR_1(type) \ + quaternion<type> & operator *= (type const & rhs) \ + { \ + a *= rhs; \ + b *= rhs; \ + c *= rhs; \ + d *= rhs; \ + \ + return(*this); \ + } + +#define BOOST_QUATERNION_MEMBER_MUL_GENERATOR_2(type) \ + quaternion<type> & operator *= (::std::complex<type> const & rhs) \ + { \ + type ar = rhs.real(); \ + type br = rhs.imag(); \ + \ + type at = +a*ar-b*br; \ + type bt = +a*br+b*ar; \ + type ct = +c*ar+d*br; \ + type dt = -c*br+d*ar; \ + \ + a = at; \ + b = bt; \ + c = ct; \ + d = dt; \ + \ + return(*this); \ + } + +#define BOOST_QUATERNION_MEMBER_MUL_GENERATOR_3(type) \ + template<typename X> \ + quaternion<type> & operator *= (quaternion<X> const & rhs) \ + { \ + type ar = static_cast<type>(rhs.R_component_1()); \ + type br = static_cast<type>(rhs.R_component_2()); \ + type cr = static_cast<type>(rhs.R_component_3()); \ + type dr = static_cast<type>(rhs.R_component_4()); \ + \ + type at = +a*ar-b*br-c*cr-d*dr; \ + type bt = +a*br+b*ar+c*dr-d*cr; \ + type ct = +a*cr-b*dr+c*ar+d*br; \ + type dt = +a*dr+b*cr-c*br+d*ar; \ + \ + a = at; \ + b = bt; \ + c = ct; \ + d = dt; \ + \ + return(*this); \ + } + +// There is quite a lot of repetition in the code below. This is intentional. +// The last conditional block is the normal form, and the others merely +// consist of workarounds for various compiler deficiencies. Hopefuly, when +// more compilers are conformant and we can retire support for those that are +// not, we will be able to remove the clutter. This is makes the situation +// (painfully) explicit. + +#define BOOST_QUATERNION_MEMBER_DIV_GENERATOR_1(type) \ + quaternion<type> & operator /= (type const & rhs) \ + { \ + a /= rhs; \ + b /= rhs; \ + c /= rhs; \ + d /= rhs; \ + \ + return(*this); \ + } + +#if defined(__GNUC__) && (__GNUC__ < 3) + #define BOOST_QUATERNION_MEMBER_DIV_GENERATOR_2(type) \ + quaternion<type> & operator /= (::std::complex<type> const & rhs) \ + { \ + using ::std::valarray; \ + \ + valarray<type> tr(2); \ + \ + tr[0] = rhs.real(); \ + tr[1] = rhs.imag(); \ + \ + type mixam = (BOOST_GET_VALARRAY(type,static_cast<type>(1)/abs(tr)).max)(); \ + \ + tr *= mixam; \ + \ + valarray<type> tt(4); \ + \ + tt[0] = +a*tr[0]+b*tr[1]; \ + tt[1] = -a*tr[1]+b*tr[0]; \ + tt[2] = +c*tr[0]-d*tr[1]; \ + tt[3] = +c*tr[1]+d*tr[0]; \ + \ + tr *= tr; \ + \ + tt *= (mixam/tr.sum()); \ + \ + a = tt[0]; \ + b = tt[1]; \ + c = tt[2]; \ + d = tt[3]; \ + \ + return(*this); \ + } +#elif defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP) + #define BOOST_QUATERNION_MEMBER_DIV_GENERATOR_2(type) \ + quaternion<type> & operator /= (::std::complex<type> const & rhs) \ + { \ + using ::std::valarray; \ + using ::std::abs; \ + \ + valarray<type> tr(2); \ + \ + tr[0] = rhs.real(); \ + tr[1] = rhs.imag(); \ + \ + type mixam = static_cast<type>(1)/(abs(tr).max)(); \ + \ + tr *= mixam; \ + \ + valarray<type> tt(4); \ + \ + tt[0] = +a*tr[0]+b*tr[1]; \ + tt[1] = -a*tr[1]+b*tr[0]; \ + tt[2] = +c*tr[0]-d*tr[1]; \ + tt[3] = +c*tr[1]+d*tr[0]; \ + \ + tr *= tr; \ + \ + tt *= (mixam/tr.sum()); \ + \ + a = tt[0]; \ + b = tt[1]; \ + c = tt[2]; \ + d = tt[3]; \ + \ + return(*this); \ + } +#else + #define BOOST_QUATERNION_MEMBER_DIV_GENERATOR_2(type) \ + quaternion<type> & operator /= (::std::complex<type> const & rhs) \ + { \ + using ::std::valarray; \ + \ + valarray<type> tr(2); \ + \ + tr[0] = rhs.real(); \ + tr[1] = rhs.imag(); \ + \ + type mixam = static_cast<type>(1)/(abs(tr).max)(); \ + \ + tr *= mixam; \ + \ + valarray<type> tt(4); \ + \ + tt[0] = +a*tr[0]+b*tr[1]; \ + tt[1] = -a*tr[1]+b*tr[0]; \ + tt[2] = +c*tr[0]-d*tr[1]; \ + tt[3] = +c*tr[1]+d*tr[0]; \ + \ + tr *= tr; \ + \ + tt *= (mixam/tr.sum()); \ + \ + a = tt[0]; \ + b = tt[1]; \ + c = tt[2]; \ + d = tt[3]; \ + \ + return(*this); \ + } +#endif /* defined(__GNUC__) && (__GNUC__ < 3) */ /* BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP */ + +#if defined(__GNUC__) && (__GNUC__ < 3) + #define BOOST_QUATERNION_MEMBER_DIV_GENERATOR_3(type) \ + template<typename X> \ + quaternion<type> & operator /= (quaternion<X> const & rhs) \ + { \ + using ::std::valarray; \ + \ + valarray<type> tr(4); \ + \ + tr[0] = static_cast<type>(rhs.R_component_1()); \ + tr[1] = static_cast<type>(rhs.R_component_2()); \ + tr[2] = static_cast<type>(rhs.R_component_3()); \ + tr[3] = static_cast<type>(rhs.R_component_4()); \ + \ + type mixam = (BOOST_GET_VALARRAY(type,static_cast<type>(1)/abs(tr)).max)(); \ + \ + tr *= mixam; \ + \ + valarray<type> tt(4); \ + \ + tt[0] = +a*tr[0]+b*tr[1]+c*tr[2]+d*tr[3]; \ + tt[1] = -a*tr[1]+b*tr[0]-c*tr[3]+d*tr[2]; \ + tt[2] = -a*tr[2]+b*tr[3]+c*tr[0]-d*tr[1]; \ + tt[3] = -a*tr[3]-b*tr[2]+c*tr[1]+d*tr[0]; \ + \ + tr *= tr; \ + \ + tt *= (mixam/tr.sum()); \ + \ + a = tt[0]; \ + b = tt[1]; \ + c = tt[2]; \ + d = tt[3]; \ + \ + return(*this); \ + } +#elif defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP) + #define BOOST_QUATERNION_MEMBER_DIV_GENERATOR_3(type) \ + template<typename X> \ + quaternion<type> & operator /= (quaternion<X> const & rhs) \ + { \ + using ::std::valarray; \ + using ::std::abs; \ + \ + valarray<type> tr(4); \ + \ + tr[0] = static_cast<type>(rhs.R_component_1()); \ + tr[1] = static_cast<type>(rhs.R_component_2()); \ + tr[2] = static_cast<type>(rhs.R_component_3()); \ + tr[3] = static_cast<type>(rhs.R_component_4()); \ + \ + type mixam = static_cast<type>(1)/(abs(tr).max)(); \ + \ + tr *= mixam; \ + \ + valarray<type> tt(4); \ + \ + tt[0] = +a*tr[0]+b*tr[1]+c*tr[2]+d*tr[3]; \ + tt[1] = -a*tr[1]+b*tr[0]-c*tr[3]+d*tr[2]; \ + tt[2] = -a*tr[2]+b*tr[3]+c*tr[0]-d*tr[1]; \ + tt[3] = -a*tr[3]-b*tr[2]+c*tr[1]+d*tr[0]; \ + \ + tr *= tr; \ + \ + tt *= (mixam/tr.sum()); \ + \ + a = tt[0]; \ + b = tt[1]; \ + c = tt[2]; \ + d = tt[3]; \ + \ + return(*this); \ + } +#else + #define BOOST_QUATERNION_MEMBER_DIV_GENERATOR_3(type) \ + template<typename X> \ + quaternion<type> & operator /= (quaternion<X> const & rhs) \ + { \ + using ::std::valarray; \ + \ + valarray<type> tr(4); \ + \ + tr[0] = static_cast<type>(rhs.R_component_1()); \ + tr[1] = static_cast<type>(rhs.R_component_2()); \ + tr[2] = static_cast<type>(rhs.R_component_3()); \ + tr[3] = static_cast<type>(rhs.R_component_4()); \ + \ + type mixam = static_cast<type>(1)/(abs(tr).max)(); \ + \ + tr *= mixam; \ + \ + valarray<type> tt(4); \ + \ + tt[0] = +a*tr[0]+b*tr[1]+c*tr[2]+d*tr[3]; \ + tt[1] = -a*tr[1]+b*tr[0]-c*tr[3]+d*tr[2]; \ + tt[2] = -a*tr[2]+b*tr[3]+c*tr[0]-d*tr[1]; \ + tt[3] = -a*tr[3]-b*tr[2]+c*tr[1]+d*tr[0]; \ + \ + tr *= tr; \ + \ + tt *= (mixam/tr.sum()); \ + \ + a = tt[0]; \ + b = tt[1]; \ + c = tt[2]; \ + d = tt[3]; \ + \ + return(*this); \ + } +#endif /* defined(__GNUC__) && (__GNUC__ < 3) */ /* BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP */ + +#define BOOST_QUATERNION_MEMBER_ADD_GENERATOR(type) \ + BOOST_QUATERNION_MEMBER_ADD_GENERATOR_1(type) \ + BOOST_QUATERNION_MEMBER_ADD_GENERATOR_2(type) \ + BOOST_QUATERNION_MEMBER_ADD_GENERATOR_3(type) + +#define BOOST_QUATERNION_MEMBER_SUB_GENERATOR(type) \ + BOOST_QUATERNION_MEMBER_SUB_GENERATOR_1(type) \ + BOOST_QUATERNION_MEMBER_SUB_GENERATOR_2(type) \ + BOOST_QUATERNION_MEMBER_SUB_GENERATOR_3(type) + +#define BOOST_QUATERNION_MEMBER_MUL_GENERATOR(type) \ + BOOST_QUATERNION_MEMBER_MUL_GENERATOR_1(type) \ + BOOST_QUATERNION_MEMBER_MUL_GENERATOR_2(type) \ + BOOST_QUATERNION_MEMBER_MUL_GENERATOR_3(type) + +#define BOOST_QUATERNION_MEMBER_DIV_GENERATOR(type) \ + BOOST_QUATERNION_MEMBER_DIV_GENERATOR_1(type) \ + BOOST_QUATERNION_MEMBER_DIV_GENERATOR_2(type) \ + BOOST_QUATERNION_MEMBER_DIV_GENERATOR_3(type) + +#define BOOST_QUATERNION_MEMBER_ALGEBRAIC_GENERATOR(type) \ + BOOST_QUATERNION_MEMBER_ADD_GENERATOR(type) \ + BOOST_QUATERNION_MEMBER_SUB_GENERATOR(type) \ + BOOST_QUATERNION_MEMBER_MUL_GENERATOR(type) \ + BOOST_QUATERNION_MEMBER_DIV_GENERATOR(type) + + + template<> + class quaternion<float> + { + public: + + typedef float value_type; + + BOOST_QUATERNION_CONSTRUCTOR_GENERATOR(float) + + // UNtemplated copy constructor + // (this is taken care of by the compiler itself) + + // explicit copy constructors (precision-loosing converters) + + explicit quaternion(quaternion<double> const & a_recopier) + { + *this = detail::quaternion_type_converter<float, double>(a_recopier); + } + + explicit quaternion(quaternion<long double> const & a_recopier) + { + *this = detail::quaternion_type_converter<float, long double>(a_recopier); + } + + // destructor + // (this is taken care of by the compiler itself) + + // accessors + // + // Note: Like complex number, quaternions do have a meaningful notion of "real part", + // but unlike them there is no meaningful notion of "imaginary part". + // Instead there is an "unreal part" which itself is a quaternion, and usually + // nothing simpler (as opposed to the complex number case). + // However, for practicallity, there are accessors for the other components + // (these are necessary for the templated copy constructor, for instance). + + BOOST_QUATERNION_ACCESSOR_GENERATOR(float) + + // assignment operators + + BOOST_QUATERNION_MEMBER_ASSIGNMENT_GENERATOR(float) + + // other assignment-related operators + // + // NOTE: Quaternion multiplication is *NOT* commutative; + // symbolically, "q *= rhs;" means "q = q * rhs;" + // and "q /= rhs;" means "q = q * inverse_of(rhs);" + + BOOST_QUATERNION_MEMBER_ALGEBRAIC_GENERATOR(float) + + + protected: + + BOOST_QUATERNION_MEMBER_DATA_GENERATOR(float) + + + private: + + }; + + + template<> + class quaternion<double> + { + public: + + typedef double value_type; + + BOOST_QUATERNION_CONSTRUCTOR_GENERATOR(double) + + // UNtemplated copy constructor + // (this is taken care of by the compiler itself) + + // converting copy constructor + + explicit quaternion(quaternion<float> const & a_recopier) + { + *this = detail::quaternion_type_converter<double, float>(a_recopier); + } + + // explicit copy constructors (precision-loosing converters) + + explicit quaternion(quaternion<long double> const & a_recopier) + { + *this = detail::quaternion_type_converter<double, long double>(a_recopier); + } + + // destructor + // (this is taken care of by the compiler itself) + + // accessors + // + // Note: Like complex number, quaternions do have a meaningful notion of "real part", + // but unlike them there is no meaningful notion of "imaginary part". + // Instead there is an "unreal part" which itself is a quaternion, and usually + // nothing simpler (as opposed to the complex number case). + // However, for practicallity, there are accessors for the other components + // (these are necessary for the templated copy constructor, for instance). + + BOOST_QUATERNION_ACCESSOR_GENERATOR(double) + + // assignment operators + + BOOST_QUATERNION_MEMBER_ASSIGNMENT_GENERATOR(double) + + // other assignment-related operators + // + // NOTE: Quaternion multiplication is *NOT* commutative; + // symbolically, "q *= rhs;" means "q = q * rhs;" + // and "q /= rhs;" means "q = q * inverse_of(rhs);" + + BOOST_QUATERNION_MEMBER_ALGEBRAIC_GENERATOR(double) + + + protected: + + BOOST_QUATERNION_MEMBER_DATA_GENERATOR(double) + + + private: + + }; + + + template<> + class quaternion<long double> + { + public: + + typedef long double value_type; + + BOOST_QUATERNION_CONSTRUCTOR_GENERATOR(long double) + + // UNtemplated copy constructor + // (this is taken care of by the compiler itself) + + // converting copy constructors + + explicit quaternion(quaternion<float> const & a_recopier) + { + *this = detail::quaternion_type_converter<long double, float>(a_recopier); + } + + explicit quaternion(quaternion<double> const & a_recopier) + { + *this = detail::quaternion_type_converter<long double, double>(a_recopier); + } + + // destructor + // (this is taken care of by the compiler itself) + + // accessors + // + // Note: Like complex number, quaternions do have a meaningful notion of "real part", + // but unlike them there is no meaningful notion of "imaginary part". + // Instead there is an "unreal part" which itself is a quaternion, and usually + // nothing simpler (as opposed to the complex number case). + // However, for practicallity, there are accessors for the other components + // (these are necessary for the templated copy constructor, for instance). + + BOOST_QUATERNION_ACCESSOR_GENERATOR(long double) + + // assignment operators + + BOOST_QUATERNION_MEMBER_ASSIGNMENT_GENERATOR(long double) + + // other assignment-related operators + // + // NOTE: Quaternion multiplication is *NOT* commutative; + // symbolically, "q *= rhs;" means "q = q * rhs;" + // and "q /= rhs;" means "q = q * inverse_of(rhs);" + + BOOST_QUATERNION_MEMBER_ALGEBRAIC_GENERATOR(long double) + + + protected: + + BOOST_QUATERNION_MEMBER_DATA_GENERATOR(long double) + + + private: + + }; + + +#undef BOOST_QUATERNION_MEMBER_ALGEBRAIC_GENERATOR +#undef BOOST_QUATERNION_MEMBER_ADD_GENERATOR +#undef BOOST_QUATERNION_MEMBER_SUB_GENERATOR +#undef BOOST_QUATERNION_MEMBER_MUL_GENERATOR +#undef BOOST_QUATERNION_MEMBER_DIV_GENERATOR +#undef BOOST_QUATERNION_MEMBER_ADD_GENERATOR_1 +#undef BOOST_QUATERNION_MEMBER_ADD_GENERATOR_2 +#undef BOOST_QUATERNION_MEMBER_ADD_GENERATOR_3 +#undef BOOST_QUATERNION_MEMBER_SUB_GENERATOR_1 +#undef BOOST_QUATERNION_MEMBER_SUB_GENERATOR_2 +#undef BOOST_QUATERNION_MEMBER_SUB_GENERATOR_3 +#undef BOOST_QUATERNION_MEMBER_MUL_GENERATOR_1 +#undef BOOST_QUATERNION_MEMBER_MUL_GENERATOR_2 +#undef BOOST_QUATERNION_MEMBER_MUL_GENERATOR_3 +#undef BOOST_QUATERNION_MEMBER_DIV_GENERATOR_1 +#undef BOOST_QUATERNION_MEMBER_DIV_GENERATOR_2 +#undef BOOST_QUATERNION_MEMBER_DIV_GENERATOR_3 + +#undef BOOST_QUATERNION_CONSTRUCTOR_GENERATOR + + +#undef BOOST_QUATERNION_MEMBER_ASSIGNMENT_GENERATOR + +#undef BOOST_QUATERNION_MEMBER_DATA_GENERATOR + +#undef BOOST_QUATERNION_ACCESSOR_GENERATOR + + + // operators + +#define BOOST_QUATERNION_OPERATOR_GENERATOR_BODY(op) \ + { \ + quaternion<T> res(lhs); \ + res op##= rhs; \ + return(res); \ + } + +#define BOOST_QUATERNION_OPERATOR_GENERATOR_1_L(op) \ + template<typename T> \ + inline quaternion<T> operator op (T const & lhs, quaternion<T> const & rhs) \ + BOOST_QUATERNION_OPERATOR_GENERATOR_BODY(op) + +#define BOOST_QUATERNION_OPERATOR_GENERATOR_1_R(op) \ + template<typename T> \ + inline quaternion<T> operator op (quaternion<T> const & lhs, T const & rhs) \ + BOOST_QUATERNION_OPERATOR_GENERATOR_BODY(op) + +#define BOOST_QUATERNION_OPERATOR_GENERATOR_2_L(op) \ + template<typename T> \ + inline quaternion<T> operator op (::std::complex<T> const & lhs, quaternion<T> const & rhs) \ + BOOST_QUATERNION_OPERATOR_GENERATOR_BODY(op) + +#define BOOST_QUATERNION_OPERATOR_GENERATOR_2_R(op) \ + template<typename T> \ + inline quaternion<T> operator op (quaternion<T> const & lhs, ::std::complex<T> const & rhs) \ + BOOST_QUATERNION_OPERATOR_GENERATOR_BODY(op) + +#define BOOST_QUATERNION_OPERATOR_GENERATOR_3(op) \ + template<typename T> \ + inline quaternion<T> operator op (quaternion<T> const & lhs, quaternion<T> const & rhs) \ + BOOST_QUATERNION_OPERATOR_GENERATOR_BODY(op) + +#define BOOST_QUATERNION_OPERATOR_GENERATOR(op) \ + BOOST_QUATERNION_OPERATOR_GENERATOR_1_L(op) \ + BOOST_QUATERNION_OPERATOR_GENERATOR_1_R(op) \ + BOOST_QUATERNION_OPERATOR_GENERATOR_2_L(op) \ + BOOST_QUATERNION_OPERATOR_GENERATOR_2_R(op) \ + BOOST_QUATERNION_OPERATOR_GENERATOR_3(op) + + + BOOST_QUATERNION_OPERATOR_GENERATOR(+) + BOOST_QUATERNION_OPERATOR_GENERATOR(-) + BOOST_QUATERNION_OPERATOR_GENERATOR(*) + BOOST_QUATERNION_OPERATOR_GENERATOR(/) + + +#undef BOOST_QUATERNION_OPERATOR_GENERATOR + +#undef BOOST_QUATERNION_OPERATOR_GENERATOR_1_L +#undef BOOST_QUATERNION_OPERATOR_GENERATOR_1_R +#undef BOOST_QUATERNION_OPERATOR_GENERATOR_2_L +#undef BOOST_QUATERNION_OPERATOR_GENERATOR_2_R +#undef BOOST_QUATERNION_OPERATOR_GENERATOR_3 + +#undef BOOST_QUATERNION_OPERATOR_GENERATOR_BODY + + + template<typename T> + inline quaternion<T> operator + (quaternion<T> const & q) + { + return(q); + } + + + template<typename T> + inline quaternion<T> operator - (quaternion<T> const & q) + { + return(quaternion<T>(-q.R_component_1(),-q.R_component_2(),-q.R_component_3(),-q.R_component_4())); + } + + + template<typename T> + inline bool operator == (T const & lhs, quaternion<T> const & rhs) + { + return ( + (rhs.R_component_1() == lhs)&& + (rhs.R_component_2() == static_cast<T>(0))&& + (rhs.R_component_3() == static_cast<T>(0))&& + (rhs.R_component_4() == static_cast<T>(0)) + ); + } + + + template<typename T> + inline bool operator == (quaternion<T> const & lhs, T const & rhs) + { + return ( + (lhs.R_component_1() == rhs)&& + (lhs.R_component_2() == static_cast<T>(0))&& + (lhs.R_component_3() == static_cast<T>(0))&& + (lhs.R_component_4() == static_cast<T>(0)) + ); + } + + + template<typename T> + inline bool operator == (::std::complex<T> const & lhs, quaternion<T> const & rhs) + { + return ( + (rhs.R_component_1() == lhs.real())&& + (rhs.R_component_2() == lhs.imag())&& + (rhs.R_component_3() == static_cast<T>(0))&& + (rhs.R_component_4() == static_cast<T>(0)) + ); + } + + + template<typename T> + inline bool operator == (quaternion<T> const & lhs, ::std::complex<T> const & rhs) + { + return ( + (lhs.R_component_1() == rhs.real())&& + (lhs.R_component_2() == rhs.imag())&& + (lhs.R_component_3() == static_cast<T>(0))&& + (lhs.R_component_4() == static_cast<T>(0)) + ); + } + + + template<typename T> + inline bool operator == (quaternion<T> const & lhs, quaternion<T> const & rhs) + { + return ( + (rhs.R_component_1() == lhs.R_component_1())&& + (rhs.R_component_2() == lhs.R_component_2())&& + (rhs.R_component_3() == lhs.R_component_3())&& + (rhs.R_component_4() == lhs.R_component_4()) + ); + } + + +#define BOOST_QUATERNION_NOT_EQUAL_GENERATOR \ + { \ + return(!(lhs == rhs)); \ + } + + template<typename T> + inline bool operator != (T const & lhs, quaternion<T> const & rhs) + BOOST_QUATERNION_NOT_EQUAL_GENERATOR + + template<typename T> + inline bool operator != (quaternion<T> const & lhs, T const & rhs) + BOOST_QUATERNION_NOT_EQUAL_GENERATOR + + template<typename T> + inline bool operator != (::std::complex<T> const & lhs, quaternion<T> const & rhs) + BOOST_QUATERNION_NOT_EQUAL_GENERATOR + + template<typename T> + inline bool operator != (quaternion<T> const & lhs, ::std::complex<T> const & rhs) + BOOST_QUATERNION_NOT_EQUAL_GENERATOR + + template<typename T> + inline bool operator != (quaternion<T> const & lhs, quaternion<T> const & rhs) + BOOST_QUATERNION_NOT_EQUAL_GENERATOR + +#undef BOOST_QUATERNION_NOT_EQUAL_GENERATOR + + + // Note: we allow the following formats, whith a, b, c, and d reals + // a + // (a), (a,b), (a,b,c), (a,b,c,d) + // (a,(c)), (a,(c,d)), ((a)), ((a),c), ((a),(c)), ((a),(c,d)), ((a,b)), ((a,b),c), ((a,b),(c)), ((a,b),(c,d)) +#if BOOST_WORKAROUND(__GNUC__, < 3) + template<typename T> + std::istream & operator >> ( ::std::istream & is, + quaternion<T> & q) +#else + template<typename T, typename charT, class traits> + ::std::basic_istream<charT,traits> & operator >> ( ::std::basic_istream<charT,traits> & is, + quaternion<T> & q) +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + typedef char charT; +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + +#ifdef BOOST_NO_STD_LOCALE +#else + const ::std::ctype<charT> & ct = ::std::use_facet< ::std::ctype<charT> >(is.getloc()); +#endif /* BOOST_NO_STD_LOCALE */ + + T a = T(); + T b = T(); + T c = T(); + T d = T(); + + ::std::complex<T> u = ::std::complex<T>(); + ::std::complex<T> v = ::std::complex<T>(); + + charT ch = charT(); + char cc; + + is >> ch; // get the first lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == '(') // read "(", possible: (a), (a,b), (a,b,c), (a,b,c,d), (a,(c)), (a,(c,d)), ((a)), ((a),c), ((a),(c)), ((a),(c,d)), ((a,b)), ((a,b),c), ((a,b),(c)), ((a,b,),(c,d,)) + { + is >> ch; // get the second lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == '(') // read "((", possible: ((a)), ((a),c), ((a),(c)), ((a),(c,d)), ((a,b)), ((a,b),c), ((a,b),(c)), ((a,b,),(c,d,)) + { + is.putback(ch); + + is >> u; // we extract the first and second components + a = u.real(); + b = u.imag(); + + if (!is.good()) goto finish; + + is >> ch; // get the next lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // format: ((a)) or ((a,b)) + { + q = quaternion<T>(a,b); + } + else if (cc == ',') // read "((a)," or "((a,b),", possible: ((a),c), ((a),(c)), ((a),(c,d)), ((a,b),c), ((a,b),(c)), ((a,b,),(c,d,)) + { + is >> v; // we extract the third and fourth components + c = v.real(); + d = v.imag(); + + if (!is.good()) goto finish; + + is >> ch; // get the last lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // format: ((a),c), ((a),(c)), ((a),(c,d)), ((a,b),c), ((a,b),(c)) or ((a,b,),(c,d,)) + { + q = quaternion<T>(a,b,c,d); + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else // read "(a", possible: (a), (a,b), (a,b,c), (a,b,c,d), (a,(c)), (a,(c,d)) + { + is.putback(ch); + + is >> a; // we extract the first component + + if (!is.good()) goto finish; + + is >> ch; // get the third lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // format: (a) + { + q = quaternion<T>(a); + } + else if (cc == ',') // read "(a,", possible: (a,b), (a,b,c), (a,b,c,d), (a,(c)), (a,(c,d)) + { + is >> ch; // get the fourth lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == '(') // read "(a,(", possible: (a,(c)), (a,(c,d)) + { + is.putback(ch); + + is >> v; // we extract the third and fourth component + + c = v.real(); + d = v.imag(); + + if (!is.good()) goto finish; + + is >> ch; // get the ninth lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // format: (a,(c)) or (a,(c,d)) + { + q = quaternion<T>(a,b,c,d); + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else // read "(a,b", possible: (a,b), (a,b,c), (a,b,c,d) + { + is.putback(ch); + + is >> b; // we extract the second component + + if (!is.good()) goto finish; + + is >> ch; // get the fifth lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // format: (a,b) + { + q = quaternion<T>(a,b); + } + else if (cc == ',') // read "(a,b,", possible: (a,b,c), (a,b,c,d) + { + is >> c; // we extract the third component + + if (!is.good()) goto finish; + + is >> ch; // get the seventh lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // format: (a,b,c) + { + q = quaternion<T>(a,b,c); + } + else if (cc == ',') // read "(a,b,c,", possible: (a,b,c,d) + { + is >> d; // we extract the fourth component + + if (!is.good()) goto finish; + + is >> ch; // get the ninth lexeme + + if (!is.good()) goto finish; + +#ifdef BOOST_NO_STD_LOCALE + cc = ch; +#else + cc = ct.narrow(ch, char()); +#endif /* BOOST_NO_STD_LOCALE */ + + if (cc == ')') // format: (a,b,c,d) + { + q = quaternion<T>(a,b,c,d); + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + } + else // error + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + is.setstate(::std::ios::failbit); +#else + is.setstate(::std::ios_base::failbit); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + } + } + else // format: a + { + is.putback(ch); + + is >> a; // we extract the first component + + if (!is.good()) goto finish; + + q = quaternion<T>(a); + } + + finish: + return(is); + } + + +#if BOOST_WORKAROUND(__GNUC__, < 3) + template<typename T> + ::std::ostream & operator << ( ::std::ostream & os, + quaternion<T> const & q) +#else + template<typename T, typename charT, class traits> + ::std::basic_ostream<charT,traits> & operator << ( ::std::basic_ostream<charT,traits> & os, + quaternion<T> const & q) +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + { +#if BOOST_WORKAROUND(__GNUC__, < 3) + ::std::ostringstream s; +#else + ::std::basic_ostringstream<charT,traits> s; +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + + s.flags(os.flags()); +#ifdef BOOST_NO_STD_LOCALE +#else + s.imbue(os.getloc()); +#endif /* BOOST_NO_STD_LOCALE */ + s.precision(os.precision()); + + s << '(' << q.R_component_1() << ',' + << q.R_component_2() << ',' + << q.R_component_3() << ',' + << q.R_component_4() << ')'; + + return os << s.str(); + } + + + // values + + template<typename T> + inline T real(quaternion<T> const & q) + { + return(q.real()); + } + + + template<typename T> + inline quaternion<T> unreal(quaternion<T> const & q) + { + return(q.unreal()); + } + + +#define BOOST_QUATERNION_VALARRAY_LOADER \ + using ::std::valarray; \ + \ + valarray<T> temp(4); \ + \ + temp[0] = q.R_component_1(); \ + temp[1] = q.R_component_2(); \ + temp[2] = q.R_component_3(); \ + temp[3] = q.R_component_4(); + + + template<typename T> + inline T sup(quaternion<T> const & q) + { +#ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP + using ::std::abs; +#endif /* BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP */ + + BOOST_QUATERNION_VALARRAY_LOADER + +#if BOOST_WORKAROUND(__GNUC__, < 3) + return((BOOST_GET_VALARRAY(T, abs(temp)).max)()); +#else + return((abs(temp).max)()); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + + + template<typename T> + inline T l1(quaternion<T> const & q) + { +#ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP + using ::std::abs; +#endif /* BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP */ + + BOOST_QUATERNION_VALARRAY_LOADER + +#if BOOST_WORKAROUND(__GNUC__, < 3) + return(BOOST_GET_VALARRAY(T, abs(temp)).sum()); +#else + return(abs(temp).sum()); +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + } + + + template<typename T> + inline T abs(quaternion<T> const & q) + { +#ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP + using ::std::abs; +#endif /* BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP */ + + using ::std::sqrt; + + BOOST_QUATERNION_VALARRAY_LOADER + +#if BOOST_WORKAROUND(__GNUC__, < 3) + T maxim = (BOOST_GET_VALARRAY(T, abs(temp)).max)(); // overflow protection +#else + T maxim = (abs(temp).max)(); // overflow protection +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + + if (maxim == static_cast<T>(0)) + { + return(maxim); + } + else + { + T mixam = static_cast<T>(1)/maxim; // prefer multiplications over divisions + + temp *= mixam; + + temp *= temp; + + return(maxim*sqrt(temp.sum())); + } + + //return(sqrt(norm(q))); + } + + +#undef BOOST_QUATERNION_VALARRAY_LOADER + + + // Note: This is the Cayley norm, not the Euclidian norm... + + template<typename T> + inline T norm(quaternion<T>const & q) + { + return(real(q*conj(q))); + } + + + template<typename T> + inline quaternion<T> conj(quaternion<T> const & q) + { + return(quaternion<T>( +q.R_component_1(), + -q.R_component_2(), + -q.R_component_3(), + -q.R_component_4())); + } + + + template<typename T> + inline quaternion<T> spherical( T const & rho, + T const & theta, + T const & phi1, + T const & phi2) + { + using ::std::cos; + using ::std::sin; + + //T a = cos(theta)*cos(phi1)*cos(phi2); + //T b = sin(theta)*cos(phi1)*cos(phi2); + //T c = sin(phi1)*cos(phi2); + //T d = sin(phi2); + + T courrant = static_cast<T>(1); + + T d = sin(phi2); + + courrant *= cos(phi2); + + T c = sin(phi1)*courrant; + + courrant *= cos(phi1); + + T b = sin(theta)*courrant; + T a = cos(theta)*courrant; + + return(rho*quaternion<T>(a,b,c,d)); + } + + + template<typename T> + inline quaternion<T> semipolar( T const & rho, + T const & alpha, + T const & theta1, + T const & theta2) + { + using ::std::cos; + using ::std::sin; + + T a = cos(alpha)*cos(theta1); + T b = cos(alpha)*sin(theta1); + T c = sin(alpha)*cos(theta2); + T d = sin(alpha)*sin(theta2); + + return(rho*quaternion<T>(a,b,c,d)); + } + + + template<typename T> + inline quaternion<T> multipolar( T const & rho1, + T const & theta1, + T const & rho2, + T const & theta2) + { + using ::std::cos; + using ::std::sin; + + T a = rho1*cos(theta1); + T b = rho1*sin(theta1); + T c = rho2*cos(theta2); + T d = rho2*sin(theta2); + + return(quaternion<T>(a,b,c,d)); + } + + + template<typename T> + inline quaternion<T> cylindrospherical( T const & t, + T const & radius, + T const & longitude, + T const & latitude) + { + using ::std::cos; + using ::std::sin; + + + + T b = radius*cos(longitude)*cos(latitude); + T c = radius*sin(longitude)*cos(latitude); + T d = radius*sin(latitude); + + return(quaternion<T>(t,b,c,d)); + } + + + template<typename T> + inline quaternion<T> cylindrical(T const & r, + T const & angle, + T const & h1, + T const & h2) + { + using ::std::cos; + using ::std::sin; + + T a = r*cos(angle); + T b = r*sin(angle); + + return(quaternion<T>(a,b,h1,h2)); + } + + + // transcendentals + // (please see the documentation) + + + template<typename T> + inline quaternion<T> exp(quaternion<T> const & q) + { + using ::std::exp; + using ::std::cos; + + using ::boost::math::sinc_pi; + + T u = exp(real(q)); + + T z = abs(unreal(q)); + + T w = sinc_pi(z); + + return(u*quaternion<T>(cos(z), + w*q.R_component_2(), w*q.R_component_3(), + w*q.R_component_4())); + } + + + template<typename T> + inline quaternion<T> cos(quaternion<T> const & q) + { + using ::std::sin; + using ::std::cos; + using ::std::cosh; + + using ::boost::math::sinhc_pi; + + T z = abs(unreal(q)); + + T w = -sin(q.real())*sinhc_pi(z); + + return(quaternion<T>(cos(q.real())*cosh(z), + w*q.R_component_2(), w*q.R_component_3(), + w*q.R_component_4())); + } + + + template<typename T> + inline quaternion<T> sin(quaternion<T> const & q) + { + using ::std::sin; + using ::std::cos; + using ::std::cosh; + + using ::boost::math::sinhc_pi; + + T z = abs(unreal(q)); + + T w = +cos(q.real())*sinhc_pi(z); + + return(quaternion<T>(sin(q.real())*cosh(z), + w*q.R_component_2(), w*q.R_component_3(), + w*q.R_component_4())); + } + + + template<typename T> + inline quaternion<T> tan(quaternion<T> const & q) + { + return(sin(q)/cos(q)); + } + + + template<typename T> + inline quaternion<T> cosh(quaternion<T> const & q) + { + return((exp(+q)+exp(-q))/static_cast<T>(2)); + } + + + template<typename T> + inline quaternion<T> sinh(quaternion<T> const & q) + { + return((exp(+q)-exp(-q))/static_cast<T>(2)); + } + + + template<typename T> + inline quaternion<T> tanh(quaternion<T> const & q) + { + return(sinh(q)/cosh(q)); + } + + + template<typename T> + quaternion<T> pow(quaternion<T> const & q, + int n) + { + if (n > 1) + { + int m = n>>1; + + quaternion<T> result = pow(q, m); + + result *= result; + + if (n != (m<<1)) + { + result *= q; // n odd + } + + return(result); + } + else if (n == 1) + { + return(q); + } + else if (n == 0) + { + return(quaternion<T>(1)); + } + else /* n < 0 */ + { + return(pow(quaternion<T>(1)/q,-n)); + } + } + + + // helper templates for converting copy constructors (definition) + + namespace detail + { + + template< typename T, + typename U + > + quaternion<T> quaternion_type_converter(quaternion<U> const & rhs) + { + return(quaternion<T>( static_cast<T>(rhs.R_component_1()), + static_cast<T>(rhs.R_component_2()), + static_cast<T>(rhs.R_component_3()), + static_cast<T>(rhs.R_component_4()))); + } + } + } +} + + +#if BOOST_WORKAROUND(__GNUC__, < 3) + #undef BOOST_GET_VALARRAY +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + + +#endif /* BOOST_QUATERNION_HPP */ diff --git a/Utilities/BGL/boost/math/special_functions.hpp b/Utilities/BGL/boost/math/special_functions.hpp new file mode 100644 index 0000000000000000000000000000000000000000..26c886f84981bde0ba233b86b00ee900435acd40 --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions.hpp @@ -0,0 +1,59 @@ +// Copyright John Maddock 2006, 2007. +// Copyright Paul A. Bristow 2006, 2007. + +// Use, modification and distribution are subject to 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) + +// This file includes *all* the special functions. +// this may be useful if many are used +// - to avoid including each function individually. + +#ifndef BOOST_MATH_SPECIAL_FUNCTIONS_HPP +#define BOOST_MATH_SPECIAL_FUNCTIONS_HPP + +#include <boost/math/special_functions/acosh.hpp> +#include <boost/math/special_functions/asinh.hpp> +#include <boost/math/special_functions/atanh.hpp> +#include <boost/math/special_functions/bessel.hpp> +#include <boost/math/special_functions/beta.hpp> +#include <boost/math/special_functions/binomial.hpp> +#include <boost/math/special_functions/cbrt.hpp> +#include <boost/math/special_functions/cos_pi.hpp> +#include <boost/math/special_functions/digamma.hpp> +#include <boost/math/special_functions/ellint_1.hpp> +#include <boost/math/special_functions/ellint_2.hpp> +#include <boost/math/special_functions/ellint_3.hpp> +#include <boost/math/special_functions/ellint_rc.hpp> +#include <boost/math/special_functions/ellint_rd.hpp> +#include <boost/math/special_functions/ellint_rf.hpp> +#include <boost/math/special_functions/ellint_rj.hpp> +#include <boost/math/special_functions/erf.hpp> +#include <boost/math/special_functions/expint.hpp> +#include <boost/math/special_functions/expm1.hpp> +#include <boost/math/special_functions/factorials.hpp> +#include <boost/math/special_functions/fpclassify.hpp> +#include <boost/math/special_functions/gamma.hpp> +#include <boost/math/special_functions/hermite.hpp> +#include <boost/math/special_functions/hypot.hpp> +#include <boost/math/special_functions/laguerre.hpp> +#include <boost/math/special_functions/lanczos.hpp> +#include <boost/math/special_functions/legendre.hpp> +#include <boost/math/special_functions/log1p.hpp> +#include <boost/math/special_functions/math_fwd.hpp> +#include <boost/math/special_functions/next.hpp> +#include <boost/math/special_functions/powm1.hpp> +#include <boost/math/special_functions/sign.hpp> +#include <boost/math/special_functions/sin_pi.hpp> +#include <boost/math/special_functions/sinc.hpp> +#include <boost/math/special_functions/sinhc.hpp> +#include <boost/math/special_functions/spherical_harmonic.hpp> +#include <boost/math/special_functions/sqrt1pm1.hpp> +#include <boost/math/special_functions/zeta.hpp> +#include <boost/math/special_functions/modf.hpp> +#include <boost/math/special_functions/round.hpp> +#include <boost/math/special_functions/trunc.hpp> +#include <boost/math/special_functions/pow.hpp> +#include <boost/math/special_functions/next.hpp> + +#endif // BOOST_MATH_SPECIAL_FUNCTIONS_HPP diff --git a/Utilities/BGL/boost/math/special_functions/acosh.hpp b/Utilities/BGL/boost/math/special_functions/acosh.hpp new file mode 100644 index 0000000000000000000000000000000000000000..ffb73f24e2493fe62291635ebbd8b0b45e8080c1 --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/acosh.hpp @@ -0,0 +1,114 @@ +// boost asinh.hpp header file + +// (C) Copyright Eric Ford 2001 & Hubert Holin. +// (C) Copyright John Maddock 2008. +// 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) + +// See http://www.boost.org for updates, documentation, and revision history. + +#ifndef BOOST_ACOSH_HPP +#define BOOST_ACOSH_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/config/no_tr1/cmath.hpp> +#include <boost/config.hpp> +#include <boost/math/tools/precision.hpp> +#include <boost/math/policies/error_handling.hpp> +#include <boost/math/special_functions/math_fwd.hpp> +#include <boost/math/special_functions/log1p.hpp> + +// This is the inverse of the hyperbolic cosine function. + +namespace boost +{ + namespace math + { + namespace detail + { +#if defined(__GNUC__) && (__GNUC__ < 3) + // gcc 2.x ignores function scope using declarations, + // put them in the scope of the enclosing namespace instead: + + using ::std::abs; + using ::std::sqrt; + using ::std::log; + + using ::std::numeric_limits; +#endif + + template<typename T, typename Policy> + inline T acosh_imp(const T x, const Policy& pol) + { + BOOST_MATH_STD_USING + + if(x < 1) + { + return policies::raise_domain_error<T>( + "boost::math::acosh<%1%>(%1%)", + "acosh requires x >= 1, but got x = %1%.", x, pol); + } + else if ((x - 1) >= tools::root_epsilon<T>()) + { + if (x > 1 / tools::root_epsilon<T>()) + { + // http://functions.wolfram.com/ElementaryFunctions/ArcCosh/06/01/06/01/0001/ + // approximation by laurent series in 1/x at 0+ order from -1 to 0 + return( log( x * 2) ); + } + else if(x < 1.5f) + { + // This is just a rearrangement of the standard form below + // devised to minimse loss of precision when x ~ 1: + T y = x - 1; + return boost::math::log1p(y + sqrt(y * y + 2 * y), pol); + } + else + { + // http://functions.wolfram.com/ElementaryFunctions/ArcCosh/02/ + return( log( x + sqrt(x * x - 1) ) ); + } + } + else + { + // see http://functions.wolfram.com/ElementaryFunctions/ArcCosh/06/01/04/01/0001/ + T y = x - 1; + + // approximation by taylor series in y at 0 up to order 2 + T result = sqrt(2 * y) * (1 + y /12 + 3 * y * y / 160); + return result; + } + } + } + + template<typename T, typename Policy> + inline typename tools::promote_args<T>::type acosh(T x, const Policy&) + { + typedef typename tools::promote_args<T>::type result_type; + typedef typename policies::evaluation<result_type, Policy>::type value_type; + typedef typename policies::normalise< + Policy, + policies::promote_float<false>, + policies::promote_double<false>, + policies::discrete_quantile<>, + policies::assert_undefined<> >::type forwarding_policy; + return policies::checked_narrowing_cast<result_type, forwarding_policy>( + detail::acosh_imp(static_cast<value_type>(x), forwarding_policy()), + "boost::math::acosh<%1%>(%1%)"); + } + template<typename T> + inline typename tools::promote_args<T>::type acosh(T x) + { + return boost::math::acosh(x, policies::policy<>()); + } + + } +} + +#endif /* BOOST_ACOSH_HPP */ + + diff --git a/Utilities/BGL/boost/math/special_functions/asinh.hpp b/Utilities/BGL/boost/math/special_functions/asinh.hpp new file mode 100644 index 0000000000000000000000000000000000000000..5b76807718f0bad9dba7e7286e3a34a5d07f2e1d --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/asinh.hpp @@ -0,0 +1,116 @@ +// boost asinh.hpp header file + +// (C) Copyright Eric Ford & Hubert Holin 2001. +// (C) Copyright John Maddock 2008. +// 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) + +// See http://www.boost.org for updates, documentation, and revision history. + +#ifndef BOOST_ASINH_HPP +#define BOOST_ASINH_HPP + +#ifdef _MSC_VER +#pragma once +#endif + + +#include <boost/config/no_tr1/cmath.hpp> +#include <boost/config.hpp> +#include <boost/math/tools/precision.hpp> +#include <boost/math/special_functions/math_fwd.hpp> +#include <boost/math/special_functions/sqrt1pm1.hpp> +#include <boost/math/special_functions/log1p.hpp> + +// This is the inverse of the hyperbolic sine function. + +namespace boost +{ + namespace math + { + namespace detail{ +#if defined(__GNUC__) && (__GNUC__ < 3) + // gcc 2.x ignores function scope using declarations, + // put them in the scope of the enclosing namespace instead: + + using ::std::abs; + using ::std::sqrt; + using ::std::log; + + using ::std::numeric_limits; +#endif + + template<typename T, class Policy> + inline T asinh_imp(const T x, const Policy& pol) + { + BOOST_MATH_STD_USING + + if (x >= tools::forth_root_epsilon<T>()) + { + if (x > 1 / tools::root_epsilon<T>()) + { + // http://functions.wolfram.com/ElementaryFunctions/ArcSinh/06/01/06/01/0001/ + // approximation by laurent series in 1/x at 0+ order from -1 to 1 + return log(x * 2) + 1/ (4 * x * x); + } + else if(x < 0.5f) + { + // As below, but rearranged to preserve digits: + return boost::math::log1p(x + boost::math::sqrt1pm1(x * x, pol), pol); + } + else + { + // http://functions.wolfram.com/ElementaryFunctions/ArcSinh/02/ + return( log( x + sqrt(x*x+1) ) ); + } + } + else if (x <= -tools::forth_root_epsilon<T>()) + { + return(-asinh(-x)); + } + else + { + // http://functions.wolfram.com/ElementaryFunctions/ArcSinh/06/01/03/01/0001/ + // approximation by taylor series in x at 0 up to order 2 + T result = x; + + if (abs(x) >= tools::root_epsilon<T>()) + { + T x3 = x*x*x; + + // approximation by taylor series in x at 0 up to order 4 + result -= x3/static_cast<T>(6); + } + + return(result); + } + } + } + + template<typename T> + inline typename tools::promote_args<T>::type asinh(T x) + { + return boost::math::asinh(x, policies::policy<>()); + } + template<typename T, typename Policy> + inline typename tools::promote_args<T>::type asinh(T x, const Policy&) + { + typedef typename tools::promote_args<T>::type result_type; + typedef typename policies::evaluation<result_type, Policy>::type value_type; + typedef typename policies::normalise< + Policy, + policies::promote_float<false>, + policies::promote_double<false>, + policies::discrete_quantile<>, + policies::assert_undefined<> >::type forwarding_policy; + return policies::checked_narrowing_cast<result_type, forwarding_policy>( + detail::asinh_imp(static_cast<value_type>(x), forwarding_policy()), + "boost::math::asinh<%1%>(%1%)"); + } + + } +} + +#endif /* BOOST_ASINH_HPP */ + diff --git a/Utilities/BGL/boost/math/special_functions/atanh.hpp b/Utilities/BGL/boost/math/special_functions/atanh.hpp new file mode 100644 index 0000000000000000000000000000000000000000..8500dc7c05247152c6988869c46a4d5f4d110b84 --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/atanh.hpp @@ -0,0 +1,128 @@ +// boost atanh.hpp header file + +// (C) Copyright Hubert Holin 2001. +// (C) Copyright John Maddock 2008. +// 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) + +// See http://www.boost.org for updates, documentation, and revision history. + +#ifndef BOOST_ATANH_HPP +#define BOOST_ATANH_HPP + +#ifdef _MSC_VER +#pragma once +#endif + + +#include <boost/config/no_tr1/cmath.hpp> +#include <boost/config.hpp> +#include <boost/math/tools/precision.hpp> +#include <boost/math/policies/error_handling.hpp> +#include <boost/math/special_functions/math_fwd.hpp> +#include <boost/math/special_functions/log1p.hpp> + +// This is the inverse of the hyperbolic tangent function. + +namespace boost +{ + namespace math + { + namespace detail + { +#if defined(__GNUC__) && (__GNUC__ < 3) + // gcc 2.x ignores function scope using declarations, + // put them in the scope of the enclosing namespace instead: + + using ::std::abs; + using ::std::sqrt; + using ::std::log; + + using ::std::numeric_limits; +#endif + + // This is the main fare + + template<typename T, typename Policy> + inline T atanh_imp(const T x, const Policy& pol) + { + BOOST_MATH_STD_USING + static const char* function = "boost::math::atanh<%1%>(%1%)"; + + if(x < -1) + { + return policies::raise_domain_error<T>( + function, + "atanh requires x >= -1, but got x = %1%.", x, pol); + } + else if(x < -1 + tools::epsilon<T>()) + { + // -Infinity: + return -policies::raise_overflow_error<T>(function, 0, pol); + } + else if(x > 1 - tools::epsilon<T>()) + { + // Infinity: + return -policies::raise_overflow_error<T>(function, 0, pol); + } + else if(x > 1) + { + return policies::raise_domain_error<T>( + function, + "atanh requires x <= 1, but got x = %1%.", x, pol); + } + else if(abs(x) >= tools::forth_root_epsilon<T>()) + { + // http://functions.wolfram.com/ElementaryFunctions/ArcTanh/02/ + if(abs(x) < 0.5f) + return (boost::math::log1p(x, pol) - boost::math::log1p(-x, pol)) / 2; + return(log( (1 + x) / (1 - x) ) / 2); + } + else + { + // http://functions.wolfram.com/ElementaryFunctions/ArcTanh/06/01/03/01/ + // approximation by taylor series in x at 0 up to order 2 + T result = x; + + if (abs(x) >= tools::root_epsilon<T>()) + { + T x3 = x*x*x; + + // approximation by taylor series in x at 0 up to order 4 + result += x3/static_cast<T>(3); + } + + return(result); + } + } + } + + template<typename T, typename Policy> + inline typename tools::promote_args<T>::type atanh(T x, const Policy&) + { + typedef typename tools::promote_args<T>::type result_type; + typedef typename policies::evaluation<result_type, Policy>::type value_type; + typedef typename policies::normalise< + Policy, + policies::promote_float<false>, + policies::promote_double<false>, + policies::discrete_quantile<>, + policies::assert_undefined<> >::type forwarding_policy; + return policies::checked_narrowing_cast<result_type, forwarding_policy>( + detail::atanh_imp(static_cast<value_type>(x), forwarding_policy()), + "boost::math::atanh<%1%>(%1%)"); + } + template<typename T> + inline typename tools::promote_args<T>::type atanh(T x) + { + return boost::math::atanh(x, policies::policy<>()); + } + + } +} + +#endif /* BOOST_ATANH_HPP */ + + + diff --git a/Utilities/BGL/boost/math/special_functions/bessel.hpp b/Utilities/BGL/boost/math/special_functions/bessel.hpp new file mode 100644 index 0000000000000000000000000000000000000000..6d2f62b427b7d572287c53df949b633c6c26b450 --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/bessel.hpp @@ -0,0 +1,514 @@ +// Copyright (c) 2007 John Maddock +// Use, modification and distribution are subject to 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) +// +// This header just defines the function entry points, and adds dispatch +// to the right implementation method. Most of the implementation details +// are in separate headers and copyright Xiaogang Zhang. +// +#ifndef BOOST_MATH_BESSEL_HPP +#define BOOST_MATH_BESSEL_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/math/special_functions/detail/bessel_jy.hpp> +#include <boost/math/special_functions/detail/bessel_jn.hpp> +#include <boost/math/special_functions/detail/bessel_yn.hpp> +#include <boost/math/special_functions/detail/bessel_ik.hpp> +#include <boost/math/special_functions/detail/bessel_i0.hpp> +#include <boost/math/special_functions/detail/bessel_i1.hpp> +#include <boost/math/special_functions/detail/bessel_kn.hpp> +#include <boost/math/special_functions/sin_pi.hpp> +#include <boost/math/special_functions/cos_pi.hpp> +#include <boost/math/special_functions/sinc.hpp> +#include <boost/math/special_functions/trunc.hpp> +#include <boost/math/special_functions/round.hpp> +#include <boost/math/tools/rational.hpp> +#include <boost/math/tools/promotion.hpp> + +namespace boost{ namespace math{ + +namespace detail{ + +template <class T, class Policy> +struct bessel_j_small_z_series_term +{ + typedef T result_type; + + bessel_j_small_z_series_term(T v_, T x) + : N(0), v(v_) + { + BOOST_MATH_STD_USING + mult = x / 2; + term = pow(mult, v) / boost::math::tgamma(v+1, Policy()); + mult *= -mult; + } + T operator()() + { + T r = term; + ++N; + term *= mult / (N * (N + v)); + return r; + } +private: + unsigned N; + T v; + T mult; + T term; +}; + +template <class T, class Policy> +struct sph_bessel_j_small_z_series_term +{ + typedef T result_type; + + sph_bessel_j_small_z_series_term(unsigned v_, T x) + : N(0), v(v_) + { + BOOST_MATH_STD_USING + mult = x / 2; + term = pow(mult, T(v)) / boost::math::tgamma(v+1+T(0.5f), Policy()); + mult *= -mult; + } + T operator()() + { + T r = term; + ++N; + term *= mult / (N * T(N + v + 0.5f)); + return r; + } +private: + unsigned N; + unsigned v; + T mult; + T term; +}; + +template <class T, class Policy> +inline T bessel_j_small_z_series(T v, T x, const Policy& pol) +{ + bessel_j_small_z_series_term<T, Policy> s(v, x); + boost::uintmax_t max_iter = policies::get_max_series_iterations<Policy>(); +#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582)) + T zero = 0; + T result = boost::math::tools::sum_series(s, boost::math::policies::get_epsilon<T, Policy>(), max_iter, zero); +#else + T result = boost::math::tools::sum_series(s, boost::math::policies::get_epsilon<T, Policy>(), max_iter); +#endif + policies::check_series_iterations("boost::math::bessel_j_small_z_series<%1%>(%1%,%1%)", max_iter, pol); + return result; +} + +template <class T, class Policy> +inline T sph_bessel_j_small_z_series(unsigned v, T x, const Policy& pol) +{ + BOOST_MATH_STD_USING // ADL of std names + sph_bessel_j_small_z_series_term<T, Policy> s(v, x); + boost::uintmax_t max_iter = policies::get_max_series_iterations<Policy>(); +#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582)) + T zero = 0; + T result = boost::math::tools::sum_series(s, boost::math::policies::get_epsilon<T, Policy>(), max_iter, zero); +#else + T result = boost::math::tools::sum_series(s, boost::math::policies::get_epsilon<T, Policy>(), max_iter); +#endif + policies::check_series_iterations("boost::math::sph_bessel_j_small_z_series<%1%>(%1%,%1%)", max_iter, pol); + return result * sqrt(constants::pi<T>() / 4); +} + +template <class T, class Policy> +T cyl_bessel_j_imp(T v, T x, const bessel_no_int_tag& t, const Policy& pol) +{ + BOOST_MATH_STD_USING + static const char* function = "boost::math::bessel_j<%1%>(%1%,%1%)"; + if(x < 0) + { + // better have integer v: + if(floor(v) == v) + { + T r = cyl_bessel_j_imp(v, T(-x), t, pol); + if(iround(v, pol) & 1) + r = -r; + return r; + } + else + return policies::raise_domain_error<T>( + function, + "Got x = %1%, but we need x >= 0", x, pol); + } + if(x == 0) + return (v == 0) ? 1 : (v > 0) ? 0 : + policies::raise_domain_error<T>( + function, + "Got v = %1%, but require v >= 0 or a negative integer: the result would be complex.", v, pol); + + + if((v >= 0) && ((x < 1) || (v > x * x / 4))) + { + return bessel_j_small_z_series(v, x, pol); + } + + T j, y; + bessel_jy(v, x, &j, &y, need_j, pol); + return j; +} + +template <class T, class Policy> +inline T cyl_bessel_j_imp(T v, T x, const bessel_maybe_int_tag&, const Policy& pol) +{ + BOOST_MATH_STD_USING // ADL of std names. + typedef typename bessel_asymptotic_tag<T, Policy>::type tag_type; + if((fabs(v) < 200) && (floor(v) == v)) + { + if(fabs(x) > asymptotic_bessel_j_limit<T>(v, tag_type())) + return asymptotic_bessel_j_large_x_2(v, x); + else + return bessel_jn(iround(v, pol), x, pol); + } + return cyl_bessel_j_imp(v, x, bessel_no_int_tag(), pol); +} + +template <class T, class Policy> +inline T cyl_bessel_j_imp(int v, T x, const bessel_int_tag&, const Policy& pol) +{ + BOOST_MATH_STD_USING + typedef typename bessel_asymptotic_tag<T, Policy>::type tag_type; + if(fabs(x) > asymptotic_bessel_j_limit<T>(abs(v), tag_type())) + { + T r = asymptotic_bessel_j_large_x_2(static_cast<T>(abs(v)), x); + if((v < 0) && (v & 1)) + r = -r; + return r; + } + else + return bessel_jn(v, x, pol); +} + +template <class T, class Policy> +inline T sph_bessel_j_imp(unsigned n, T x, const Policy& pol) +{ + BOOST_MATH_STD_USING // ADL of std names + if(x < 0) + return policies::raise_domain_error<T>( + "boost::math::sph_bessel_j<%1%>(%1%,%1%)", + "Got x = %1%, but function requires x > 0.", x, pol); + // + // Special case, n == 0 resolves down to the sinus cardinal of x: + // + if(n == 0) + return boost::math::sinc_pi(x, pol); + // + // When x is small we may end up with 0/0, use series evaluation + // instead, especially as it converges rapidly: + // + if(x < 1) + return sph_bessel_j_small_z_series(n, x, pol); + // + // Default case is just a naive evaluation of the definition: + // + return sqrt(constants::pi<T>() / (2 * x)) + * cyl_bessel_j_imp(T(T(n)+T(0.5f)), x, bessel_no_int_tag(), pol); +} + +template <class T, class Policy> +T cyl_bessel_i_imp(T v, T x, const Policy& pol) +{ + // + // This handles all the bessel I functions, note that we don't optimise + // for integer v, other than the v = 0 or 1 special cases, as Millers + // algorithm is at least as inefficient as the general case (the general + // case has better error handling too). + // + BOOST_MATH_STD_USING + if(x < 0) + { + // better have integer v: + if(floor(v) == v) + { + T r = cyl_bessel_i_imp(v, T(-x), pol); + if(iround(v, pol) & 1) + r = -r; + return r; + } + else + return policies::raise_domain_error<T>( + "boost::math::cyl_bessel_i<%1%>(%1%,%1%)", + "Got x = %1%, but we need x >= 0", x, pol); + } + if(x == 0) + { + return (v == 0) ? 1 : 0; + } + if(v == 0.5f) + { + // common special case, note try and avoid overflow in exp(x): + if(x >= tools::log_max_value<T>()) + { + T e = exp(x / 2); + return e * (e / sqrt(2 * x * constants::pi<T>())); + } + return sqrt(2 / (x * constants::pi<T>())) * sinh(x); + } + if(policies::digits<T, Policy>() <= 64) + { + if(v == 0) + { + return bessel_i0(x); + } + if(v == 1) + { + return bessel_i1(x); + } + } + T I, K; + bessel_ik(v, x, &I, &K, need_i, pol); + return I; +} + +template <class T, class Policy> +inline T cyl_bessel_k_imp(T v, T x, const bessel_no_int_tag& /* t */, const Policy& pol) +{ + static const char* function = "boost::math::cyl_bessel_k<%1%>(%1%,%1%)"; + BOOST_MATH_STD_USING + if(x < 0) + { + return policies::raise_domain_error<T>( + function, + "Got x = %1%, but we need x > 0", x, pol); + } + if(x == 0) + { + return (v == 0) ? policies::raise_overflow_error<T>(function, 0, pol) + : policies::raise_domain_error<T>( + function, + "Got x = %1%, but we need x > 0", x, pol); + } + T I, K; + bessel_ik(v, x, &I, &K, need_k, pol); + return K; +} + +template <class T, class Policy> +inline T cyl_bessel_k_imp(T v, T x, const bessel_maybe_int_tag&, const Policy& pol) +{ + BOOST_MATH_STD_USING + if((floor(v) == v)) + { + return bessel_kn(itrunc(v), x, pol); + } + return cyl_bessel_k_imp(v, x, bessel_no_int_tag(), pol); +} + +template <class T, class Policy> +inline T cyl_bessel_k_imp(int v, T x, const bessel_int_tag&, const Policy& pol) +{ + return bessel_kn(v, x, pol); +} + +template <class T, class Policy> +inline T cyl_neumann_imp(T v, T x, const bessel_no_int_tag&, const Policy& pol) +{ + static const char* function = "boost::math::cyl_neumann<%1%>(%1%,%1%)"; + + BOOST_MATH_INSTRUMENT_VARIABLE(v); + BOOST_MATH_INSTRUMENT_VARIABLE(x); + + if(x <= 0) + { + return (v == 0) && (x == 0) ? + policies::raise_overflow_error<T>(function, 0, pol) + : policies::raise_domain_error<T>( + function, + "Got x = %1%, but result is complex for x <= 0", x, pol); + } + T j, y; + bessel_jy(v, x, &j, &y, need_y, pol); + // + // Post evaluation check for internal overflow during evaluation, + // can occur when x is small and v is large, in which case the result + // is -INF: + // + if(!(boost::math::isfinite)(y)) + return -policies::raise_overflow_error<T>(function, 0, pol); + return y; +} + +template <class T, class Policy> +inline T cyl_neumann_imp(T v, T x, const bessel_maybe_int_tag&, const Policy& pol) +{ + BOOST_MATH_STD_USING + typedef typename bessel_asymptotic_tag<T, Policy>::type tag_type; + + BOOST_MATH_INSTRUMENT_VARIABLE(v); + BOOST_MATH_INSTRUMENT_VARIABLE(x); + + if(floor(v) == v) + { + if((fabs(x) > asymptotic_bessel_y_limit<T>(tag_type())) && (fabs(x) > 5 * abs(v))) + { + T r = asymptotic_bessel_y_large_x_2(static_cast<T>(abs(v)), x); + if((v < 0) && (itrunc(v, pol) & 1)) + r = -r; + BOOST_MATH_INSTRUMENT_VARIABLE(r); + return r; + } + else + { + T r = bessel_yn(itrunc(v, pol), x, pol); + BOOST_MATH_INSTRUMENT_VARIABLE(r); + return r; + } + } + T r = cyl_neumann_imp<T>(v, x, bessel_no_int_tag(), pol); + BOOST_MATH_INSTRUMENT_VARIABLE(r); + return r; +} + +template <class T, class Policy> +inline T cyl_neumann_imp(int v, T x, const bessel_int_tag&, const Policy& pol) +{ + BOOST_MATH_STD_USING + typedef typename bessel_asymptotic_tag<T, Policy>::type tag_type; + + BOOST_MATH_INSTRUMENT_VARIABLE(v); + BOOST_MATH_INSTRUMENT_VARIABLE(x); + + if((fabs(x) > asymptotic_bessel_y_limit<T>(tag_type())) && (fabs(x) > 5 * abs(v))) + { + T r = asymptotic_bessel_y_large_x_2(static_cast<T>(abs(v)), x); + if((v < 0) && (v & 1)) + r = -r; + return r; + } + else + return bessel_yn(v, x, pol); +} + +template <class T, class Policy> +inline T sph_neumann_imp(unsigned v, T x, const Policy& pol) +{ + BOOST_MATH_STD_USING // ADL of std names + static const char* function = "boost::math::sph_neumann<%1%>(%1%,%1%)"; + // + // Nothing much to do here but check for errors, and + // evaluate the function's definition directly: + // + if(x < 0) + return policies::raise_domain_error<T>( + function, + "Got x = %1%, but function requires x > 0.", x, pol); + + if(x < 2 * tools::min_value<T>()) + return -policies::raise_overflow_error<T>(function, 0, pol); + + T result = cyl_neumann_imp(T(T(v)+0.5f), x, bessel_no_int_tag(), pol); + T tx = sqrt(constants::pi<T>() / (2 * x)); + + if((tx > 1) && (tools::max_value<T>() / tx < result)) + return -policies::raise_overflow_error<T>(function, 0, pol); + + return result * tx; +} + +} // namespace detail + +template <class T1, class T2, class Policy> +inline typename detail::bessel_traits<T1, T2, Policy>::result_type cyl_bessel_j(T1 v, T2 x, const Policy& pol) +{ + BOOST_FPU_EXCEPTION_GUARD + typedef typename detail::bessel_traits<T1, T2, Policy>::result_type result_type; + typedef typename detail::bessel_traits<T1, T2, Policy>::optimisation_tag tag_type; + typedef typename policies::evaluation<result_type, Policy>::type value_type; + return policies::checked_narrowing_cast<result_type, Policy>(detail::cyl_bessel_j_imp<value_type>(v, static_cast<value_type>(x), tag_type(), pol), "boost::math::cyl_bessel_j<%1%>(%1%,%1%)"); +} + +template <class T1, class T2> +inline typename detail::bessel_traits<T1, T2, policies::policy<> >::result_type cyl_bessel_j(T1 v, T2 x) +{ + return cyl_bessel_j(v, x, policies::policy<>()); +} + +template <class T, class Policy> +inline typename detail::bessel_traits<T, T, Policy>::result_type sph_bessel(unsigned v, T x, const Policy& pol) +{ + BOOST_FPU_EXCEPTION_GUARD + typedef typename detail::bessel_traits<T, T, Policy>::result_type result_type; + typedef typename policies::evaluation<result_type, Policy>::type value_type; + return policies::checked_narrowing_cast<result_type, Policy>(detail::sph_bessel_j_imp<value_type>(v, static_cast<value_type>(x), pol), "boost::math::sph_bessel<%1%>(%1%,%1%)"); +} + +template <class T> +inline typename detail::bessel_traits<T, T, policies::policy<> >::result_type sph_bessel(unsigned v, T x) +{ + return sph_bessel(v, x, policies::policy<>()); +} + +template <class T1, class T2, class Policy> +inline typename detail::bessel_traits<T1, T2, Policy>::result_type cyl_bessel_i(T1 v, T2 x, const Policy& pol) +{ + BOOST_FPU_EXCEPTION_GUARD + typedef typename detail::bessel_traits<T1, T2, Policy>::result_type result_type; + typedef typename policies::evaluation<result_type, Policy>::type value_type; + return policies::checked_narrowing_cast<result_type, Policy>(detail::cyl_bessel_i_imp<value_type>(v, static_cast<value_type>(x), pol), "boost::math::cyl_bessel_i<%1%>(%1%,%1%)"); +} + +template <class T1, class T2> +inline typename detail::bessel_traits<T1, T2, policies::policy<> >::result_type cyl_bessel_i(T1 v, T2 x) +{ + return cyl_bessel_i(v, x, policies::policy<>()); +} + +template <class T1, class T2, class Policy> +inline typename detail::bessel_traits<T1, T2, Policy>::result_type cyl_bessel_k(T1 v, T2 x, const Policy& pol) +{ + BOOST_FPU_EXCEPTION_GUARD + typedef typename detail::bessel_traits<T1, T2, Policy>::result_type result_type; + typedef typename detail::bessel_traits<T1, T2, Policy>::optimisation_tag tag_type; + typedef typename policies::evaluation<result_type, Policy>::type value_type; + return policies::checked_narrowing_cast<result_type, Policy>(detail::cyl_bessel_k_imp<value_type>(v, static_cast<value_type>(x), tag_type(), pol), "boost::math::cyl_bessel_k<%1%>(%1%,%1%)"); +} + +template <class T1, class T2> +inline typename detail::bessel_traits<T1, T2, policies::policy<> >::result_type cyl_bessel_k(T1 v, T2 x) +{ + return cyl_bessel_k(v, x, policies::policy<>()); +} + +template <class T1, class T2, class Policy> +inline typename detail::bessel_traits<T1, T2, Policy>::result_type cyl_neumann(T1 v, T2 x, const Policy& pol) +{ + BOOST_FPU_EXCEPTION_GUARD + typedef typename detail::bessel_traits<T1, T2, Policy>::result_type result_type; + typedef typename detail::bessel_traits<T1, T2, Policy>::optimisation_tag tag_type; + typedef typename policies::evaluation<result_type, Policy>::type value_type; + return policies::checked_narrowing_cast<result_type, Policy>(detail::cyl_neumann_imp<value_type>(v, static_cast<value_type>(x), tag_type(), pol), "boost::math::cyl_neumann<%1%>(%1%,%1%)"); +} + +template <class T1, class T2> +inline typename detail::bessel_traits<T1, T2, policies::policy<> >::result_type cyl_neumann(T1 v, T2 x) +{ + return cyl_neumann(v, x, policies::policy<>()); +} + +template <class T, class Policy> +inline typename detail::bessel_traits<T, T, Policy>::result_type sph_neumann(unsigned v, T x, const Policy& pol) +{ + BOOST_FPU_EXCEPTION_GUARD + typedef typename detail::bessel_traits<T, T, Policy>::result_type result_type; + typedef typename policies::evaluation<result_type, Policy>::type value_type; + return policies::checked_narrowing_cast<result_type, Policy>(detail::sph_neumann_imp<value_type>(v, static_cast<value_type>(x), pol), "boost::math::sph_neumann<%1%>(%1%,%1%)"); +} + +template <class T> +inline typename detail::bessel_traits<T, T, policies::policy<> >::result_type sph_neumann(unsigned v, T x) +{ + return sph_neumann(v, x, policies::policy<>()); +} + +} // namespace math +} // namespace boost + +#endif // BOOST_MATH_BESSEL_HPP + diff --git a/Utilities/BGL/boost/math/special_functions/beta.hpp b/Utilities/BGL/boost/math/special_functions/beta.hpp new file mode 100644 index 0000000000000000000000000000000000000000..361fc47614100c4197b25241a837eececc654703 --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/beta.hpp @@ -0,0 +1,1430 @@ +// (C) Copyright John Maddock 2006. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_SPECIAL_BETA_HPP +#define BOOST_MATH_SPECIAL_BETA_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/math/special_functions/math_fwd.hpp> +#include <boost/math/tools/config.hpp> +#include <boost/math/special_functions/gamma.hpp> +#include <boost/math/special_functions/factorials.hpp> +#include <boost/math/special_functions/erf.hpp> +#include <boost/math/special_functions/log1p.hpp> +#include <boost/math/special_functions/expm1.hpp> +#include <boost/math/special_functions/trunc.hpp> +#include <boost/math/tools/roots.hpp> +#include <boost/static_assert.hpp> +#include <boost/config/no_tr1/cmath.hpp> + +namespace boost{ namespace math{ + +namespace detail{ + +// +// Implementation of Beta(a,b) using the Lanczos approximation: +// +template <class T, class L, class Policy> +T beta_imp(T a, T b, const L&, const Policy& pol) +{ + BOOST_MATH_STD_USING // for ADL of std names + + if(a <= 0) + policies::raise_domain_error<T>("boost::math::beta<%1%>(%1%,%1%)", "The arguments to the beta function must be greater than zero (got a=%1%).", a, pol); + if(b <= 0) + policies::raise_domain_error<T>("boost::math::beta<%1%>(%1%,%1%)", "The arguments to the beta function must be greater than zero (got b=%1%).", b, pol); + + T result; + + T prefix = 1; + T c = a + b; + + // Special cases: + if((c == a) && (b < tools::epsilon<T>())) + return boost::math::tgamma(b, pol); + else if((c == b) && (a < tools::epsilon<T>())) + return boost::math::tgamma(a, pol); + if(b == 1) + return 1/a; + else if(a == 1) + return 1/b; + + /* + // + // This code appears to be no longer necessary: it was + // used to offset errors introduced from the Lanczos + // approximation, but the current Lanczos approximations + // are sufficiently accurate for all z that we can ditch + // this. It remains in the file for future reference... + // + // If a or b are less than 1, shift to greater than 1: + if(a < 1) + { + prefix *= c / a; + c += 1; + a += 1; + } + if(b < 1) + { + prefix *= c / b; + c += 1; + b += 1; + } + */ + + if(a < b) + std::swap(a, b); + + // Lanczos calculation: + T agh = a + L::g() - T(0.5); + T bgh = b + L::g() - T(0.5); + T cgh = c + L::g() - T(0.5); + result = L::lanczos_sum_expG_scaled(a) * L::lanczos_sum_expG_scaled(b) / L::lanczos_sum_expG_scaled(c); + T ambh = a - T(0.5) - b; + if((fabs(b * ambh) < (cgh * 100)) && (a > 100)) + { + // Special case where the base of the power term is close to 1 + // compute (1+x)^y instead: + result *= exp(ambh * boost::math::log1p(-b / cgh, pol)); + } + else + { + result *= pow(agh / cgh, a - T(0.5) - b); + } + if(cgh > 1e10f) + // this avoids possible overflow, but appears to be marginally less accurate: + result *= pow((agh / cgh) * (bgh / cgh), b); + else + result *= pow((agh * bgh) / (cgh * cgh), b); + result *= sqrt(boost::math::constants::e<T>() / bgh); + + // If a and b were originally less than 1 we need to scale the result: + result *= prefix; + + return result; +} // template <class T, class L> beta_imp(T a, T b, const L&) + +// +// Generic implementation of Beta(a,b) without Lanczos approximation support +// (Caution this is slow!!!): +// +template <class T, class Policy> +T beta_imp(T a, T b, const lanczos::undefined_lanczos& /* l */, const Policy& pol) +{ + BOOST_MATH_STD_USING + + if(a <= 0) + policies::raise_domain_error<T>("boost::math::beta<%1%>(%1%,%1%)", "The arguments to the beta function must be greater than zero (got a=%1%).", a, pol); + if(b <= 0) + policies::raise_domain_error<T>("boost::math::beta<%1%>(%1%,%1%)", "The arguments to the beta function must be greater than zero (got b=%1%).", b, pol); + + T result; + + T prefix = 1; + T c = a + b; + + // special cases: + if((c == a) && (b < tools::epsilon<T>())) + return boost::math::tgamma(b, pol); + else if((c == b) && (a < tools::epsilon<T>())) + return boost::math::tgamma(a, pol); + if(b == 1) + return 1/a; + else if(a == 1) + return 1/b; + + // shift to a and b > 1 if required: + if(a < 1) + { + prefix *= c / a; + c += 1; + a += 1; + } + if(b < 1) + { + prefix *= c / b; + c += 1; + b += 1; + } + if(a < b) + std::swap(a, b); + + // set integration limits: + T la = (std::max)(T(10), a); + T lb = (std::max)(T(10), b); + T lc = (std::max)(T(10), a+b); + + // calculate the fraction parts: + T sa = detail::lower_gamma_series(a, la, pol) / a; + sa += detail::upper_gamma_fraction(a, la, ::boost::math::policies::get_epsilon<T, Policy>()); + T sb = detail::lower_gamma_series(b, lb, pol) / b; + sb += detail::upper_gamma_fraction(b, lb, ::boost::math::policies::get_epsilon<T, Policy>()); + T sc = detail::lower_gamma_series(c, lc, pol) / c; + sc += detail::upper_gamma_fraction(c, lc, ::boost::math::policies::get_epsilon<T, Policy>()); + + // and the exponent part: + result = exp(lc - la - lb) * pow(la/lc, a) * pow(lb/lc, b); + + // and combine: + result *= sa * sb / sc; + + // if a and b were originally less than 1 we need to scale the result: + result *= prefix; + + return result; +} // template <class T>T beta_imp(T a, T b, const lanczos::undefined_lanczos& l) + + +// +// Compute the leading power terms in the incomplete Beta: +// +// (x^a)(y^b)/Beta(a,b) when normalised, and +// (x^a)(y^b) otherwise. +// +// Almost all of the error in the incomplete beta comes from this +// function: particularly when a and b are large. Computing large +// powers are *hard* though, and using logarithms just leads to +// horrendous cancellation errors. +// +template <class T, class L, class Policy> +T ibeta_power_terms(T a, + T b, + T x, + T y, + const L&, + bool normalised, + const Policy& pol) +{ + BOOST_MATH_STD_USING + + if(!normalised) + { + // can we do better here? + return pow(x, a) * pow(y, b); + } + + T result; + + T prefix = 1; + T c = a + b; + + // combine power terms with Lanczos approximation: + T agh = a + L::g() - T(0.5); + T bgh = b + L::g() - T(0.5); + T cgh = c + L::g() - T(0.5); + result = L::lanczos_sum_expG_scaled(c) / (L::lanczos_sum_expG_scaled(a) * L::lanczos_sum_expG_scaled(b)); + + // l1 and l2 are the base of the exponents minus one: + T l1 = (x * b - y * agh) / agh; + T l2 = (y * a - x * bgh) / bgh; + if(((std::min)(fabs(l1), fabs(l2)) < 0.2)) + { + // when the base of the exponent is very near 1 we get really + // gross errors unless extra care is taken: + if((l1 * l2 > 0) || ((std::min)(a, b) < 1)) + { + // + // This first branch handles the simple cases where either: + // + // * The two power terms both go in the same direction + // (towards zero or towards infinity). In this case if either + // term overflows or underflows, then the product of the two must + // do so also. + // *Alternatively if one exponent is less than one, then we + // can't productively use it to eliminate overflow or underflow + // from the other term. Problems with spurious overflow/underflow + // can't be ruled out in this case, but it is *very* unlikely + // since one of the power terms will evaluate to a number close to 1. + // + if(fabs(l1) < 0.1) + { + result *= exp(a * boost::math::log1p(l1, pol)); + BOOST_MATH_INSTRUMENT_VARIABLE(result); + } + else + { + result *= pow((x * cgh) / agh, a); + BOOST_MATH_INSTRUMENT_VARIABLE(result); + } + if(fabs(l2) < 0.1) + { + result *= exp(b * boost::math::log1p(l2, pol)); + BOOST_MATH_INSTRUMENT_VARIABLE(result); + } + else + { + result *= pow((y * cgh) / bgh, b); + BOOST_MATH_INSTRUMENT_VARIABLE(result); + } + } + else if((std::max)(fabs(l1), fabs(l2)) < 0.5) + { + // + // Both exponents are near one and both the exponents are + // greater than one and further these two + // power terms tend in opposite directions (one towards zero, + // the other towards infinity), so we have to combine the terms + // to avoid any risk of overflow or underflow. + // + // We do this by moving one power term inside the other, we have: + // + // (1 + l1)^a * (1 + l2)^b + // = ((1 + l1)*(1 + l2)^(b/a))^a + // = (1 + l1 + l3 + l1*l3)^a ; l3 = (1 + l2)^(b/a) - 1 + // = exp((b/a) * log(1 + l2)) - 1 + // + // The tricky bit is deciding which term to move inside :-) + // By preference we move the larger term inside, so that the + // size of the largest exponent is reduced. However, that can + // only be done as long as l3 (see above) is also small. + // + bool small_a = a < b; + T ratio = b / a; + if((small_a && (ratio * l2 < 0.1)) || (!small_a && (l1 / ratio > 0.1))) + { + T l3 = boost::math::expm1(ratio * boost::math::log1p(l2, pol), pol); + l3 = l1 + l3 + l3 * l1; + l3 = a * boost::math::log1p(l3, pol); + result *= exp(l3); + BOOST_MATH_INSTRUMENT_VARIABLE(result); + } + else + { + T l3 = boost::math::expm1(boost::math::log1p(l1, pol) / ratio, pol); + l3 = l2 + l3 + l3 * l2; + l3 = b * boost::math::log1p(l3, pol); + result *= exp(l3); + BOOST_MATH_INSTRUMENT_VARIABLE(result); + } + } + else if(fabs(l1) < fabs(l2)) + { + // First base near 1 only: + T l = a * boost::math::log1p(l1, pol) + + b * log((y * cgh) / bgh); + result *= exp(l); + BOOST_MATH_INSTRUMENT_VARIABLE(result); + } + else + { + // Second base near 1 only: + T l = b * boost::math::log1p(l2, pol) + + a * log((x * cgh) / agh); + result *= exp(l); + BOOST_MATH_INSTRUMENT_VARIABLE(result); + } + } + else + { + // general case: + T b1 = (x * cgh) / agh; + T b2 = (y * cgh) / bgh; + l1 = a * log(b1); + l2 = b * log(b2); + if((l1 >= tools::log_max_value<T>()) + || (l1 <= tools::log_min_value<T>()) + || (l2 >= tools::log_max_value<T>()) + || (l2 <= tools::log_min_value<T>()) + ) + { + // Oops, overflow, sidestep: + if(a < b) + result *= pow(pow(b2, b/a) * b1, a); + else + result *= pow(pow(b1, a/b) * b2, b); + BOOST_MATH_INSTRUMENT_VARIABLE(result); + } + else + { + // finally the normal case: + result *= pow(b1, a) * pow(b2, b); + BOOST_MATH_INSTRUMENT_VARIABLE(result); + } + } + // combine with the leftover terms from the Lanczos approximation: + result *= sqrt(bgh / boost::math::constants::e<T>()); + result *= sqrt(agh / cgh); + result *= prefix; + + BOOST_MATH_INSTRUMENT_VARIABLE(result); + + return result; +} +// +// Compute the leading power terms in the incomplete Beta: +// +// (x^a)(y^b)/Beta(a,b) when normalised, and +// (x^a)(y^b) otherwise. +// +// Almost all of the error in the incomplete beta comes from this +// function: particularly when a and b are large. Computing large +// powers are *hard* though, and using logarithms just leads to +// horrendous cancellation errors. +// +// This version is generic, slow, and does not use the Lanczos approximation. +// +template <class T, class Policy> +T ibeta_power_terms(T a, + T b, + T x, + T y, + const boost::math::lanczos::undefined_lanczos&, + bool normalised, + const Policy& pol) +{ + BOOST_MATH_STD_USING + + if(!normalised) + { + return pow(x, a) * pow(y, b); + } + + T result; + + T prefix = 1; + T c = a + b; + + // integration limits for the gamma functions: + //T la = (std::max)(T(10), a); + //T lb = (std::max)(T(10), b); + //T lc = (std::max)(T(10), a+b); + T la = a + 5; + T lb = b + 5; + T lc = a + b + 5; + // gamma function partials: + T sa = detail::lower_gamma_series(a, la, pol) / a; + sa += detail::upper_gamma_fraction(a, la, ::boost::math::policies::get_epsilon<T, Policy>()); + T sb = detail::lower_gamma_series(b, lb, pol) / b; + sb += detail::upper_gamma_fraction(b, lb, ::boost::math::policies::get_epsilon<T, Policy>()); + T sc = detail::lower_gamma_series(c, lc, pol) / c; + sc += detail::upper_gamma_fraction(c, lc, ::boost::math::policies::get_epsilon<T, Policy>()); + // gamma function powers combined with incomplete beta powers: + + T b1 = (x * lc) / la; + T b2 = (y * lc) / lb; + T e1 = lc - la - lb; + T lb1 = a * log(b1); + T lb2 = b * log(b2); + + if((lb1 >= tools::log_max_value<T>()) + || (lb1 <= tools::log_min_value<T>()) + || (lb2 >= tools::log_max_value<T>()) + || (lb2 <= tools::log_min_value<T>()) + || (e1 >= tools::log_max_value<T>()) + || (e1 <= tools::log_min_value<T>()) + ) + { + result = exp(lb1 + lb2 - e1); + } + else + { + T p1, p2; + if((fabs(b1 - 1) * a < 10) && (a > 1)) + p1 = exp(a * boost::math::log1p((x * b - y * la) / la, pol)); + else + p1 = pow(b1, a); + if((fabs(b2 - 1) * b < 10) && (b > 1)) + p2 = exp(b * boost::math::log1p((y * a - x * lb) / lb, pol)); + else + p2 = pow(b2, b); + T p3 = exp(e1); + result = p1 * p2 / p3; + } + // and combine with the remaining gamma function components: + result /= sa * sb / sc; + + return result; +} +// +// Series approximation to the incomplete beta: +// +template <class T> +struct ibeta_series_t +{ + typedef T result_type; + ibeta_series_t(T a_, T b_, T x_, T mult) : result(mult), x(x_), apn(a_), poch(1-b_), n(1) {} + T operator()() + { + T r = result / apn; + apn += 1; + result *= poch * x / n; + ++n; + poch += 1; + return r; + } +private: + T result, x, apn, poch; + int n; +}; + +template <class T, class L, class Policy> +T ibeta_series(T a, T b, T x, T s0, const L&, bool normalised, T* p_derivative, T y, const Policy& pol) +{ + BOOST_MATH_STD_USING + + T result; + + BOOST_ASSERT((p_derivative == 0) || normalised); + + if(normalised) + { + T c = a + b; + + // incomplete beta power term, combined with the Lanczos approximation: + T agh = a + L::g() - T(0.5); + T bgh = b + L::g() - T(0.5); + T cgh = c + L::g() - T(0.5); + result = L::lanczos_sum_expG_scaled(c) / (L::lanczos_sum_expG_scaled(a) * L::lanczos_sum_expG_scaled(b)); + if(a * b < bgh * 10) + result *= exp((b - 0.5f) * boost::math::log1p(a / bgh, pol)); + else + result *= pow(cgh / bgh, b - 0.5f); + result *= pow(x * cgh / agh, a); + result *= sqrt(agh / boost::math::constants::e<T>()); + + if(p_derivative) + { + *p_derivative = result * pow(y, b); + BOOST_ASSERT(*p_derivative >= 0); + } + } + else + { + // Non-normalised, just compute the power: + result = pow(x, a); + } + if(result < tools::min_value<T>()) + return s0; // Safeguard: series can't cope with denorms. + ibeta_series_t<T> s(a, b, x, result); + boost::uintmax_t max_iter = policies::get_max_series_iterations<Policy>(); + result = boost::math::tools::sum_series(s, boost::math::policies::get_epsilon<T, Policy>(), max_iter, s0); + policies::check_series_iterations("boost::math::ibeta<%1%>(%1%, %1%, %1%) in ibeta_series (with lanczos)", max_iter, pol); + return result; +} +// +// Incomplete Beta series again, this time without Lanczos support: +// +template <class T, class Policy> +T ibeta_series(T a, T b, T x, T s0, const boost::math::lanczos::undefined_lanczos&, bool normalised, T* p_derivative, T y, const Policy& pol) +{ + BOOST_MATH_STD_USING + + T result; + BOOST_ASSERT((p_derivative == 0) || normalised); + + if(normalised) + { + T prefix = 1; + T c = a + b; + + // figure out integration limits for the gamma function: + //T la = (std::max)(T(10), a); + //T lb = (std::max)(T(10), b); + //T lc = (std::max)(T(10), a+b); + T la = a + 5; + T lb = b + 5; + T lc = a + b + 5; + + // calculate the gamma parts: + T sa = detail::lower_gamma_series(a, la, pol) / a; + sa += detail::upper_gamma_fraction(a, la, ::boost::math::policies::get_epsilon<T, Policy>()); + T sb = detail::lower_gamma_series(b, lb, pol) / b; + sb += detail::upper_gamma_fraction(b, lb, ::boost::math::policies::get_epsilon<T, Policy>()); + T sc = detail::lower_gamma_series(c, lc, pol) / c; + sc += detail::upper_gamma_fraction(c, lc, ::boost::math::policies::get_epsilon<T, Policy>()); + + // and their combined power-terms: + T b1 = (x * lc) / la; + T b2 = lc/lb; + T e1 = lc - la - lb; + T lb1 = a * log(b1); + T lb2 = b * log(b2); + + if((lb1 >= tools::log_max_value<T>()) + || (lb1 <= tools::log_min_value<T>()) + || (lb2 >= tools::log_max_value<T>()) + || (lb2 <= tools::log_min_value<T>()) + || (e1 >= tools::log_max_value<T>()) + || (e1 <= tools::log_min_value<T>()) ) + { + T p = lb1 + lb2 - e1; + result = exp(p); + } + else + { + result = pow(b1, a); + if(a * b < lb * 10) + result *= exp(b * boost::math::log1p(a / lb, pol)); + else + result *= pow(b2, b); + result /= exp(e1); + } + // and combine the results: + result /= sa * sb / sc; + + if(p_derivative) + { + *p_derivative = result * pow(y, b); + BOOST_ASSERT(*p_derivative >= 0); + } + } + else + { + // Non-normalised, just compute the power: + result = pow(x, a); + } + if(result < tools::min_value<T>()) + return s0; // Safeguard: series can't cope with denorms. + ibeta_series_t<T> s(a, b, x, result); + boost::uintmax_t max_iter = policies::get_max_series_iterations<Policy>(); + result = boost::math::tools::sum_series(s, boost::math::policies::get_epsilon<T, Policy>(), max_iter, s0); + policies::check_series_iterations("boost::math::ibeta<%1%>(%1%, %1%, %1%) in ibeta_series (without lanczos)", max_iter, pol); + return result; +} + +// +// Continued fraction for the incomplete beta: +// +template <class T> +struct ibeta_fraction2_t +{ + typedef std::pair<T, T> result_type; + + ibeta_fraction2_t(T a_, T b_, T x_) : a(a_), b(b_), x(x_), m(0) {} + + result_type operator()() + { + T aN = (a + m - 1) * (a + b + m - 1) * m * (b - m) * x * x; + T denom = (a + 2 * m - 1); + aN /= denom * denom; + + T bN = m; + bN += (m * (b - m) * x) / (a + 2*m - 1); + bN += ((a + m) * (a - (a + b) * x + 1 + m *(2 - x))) / (a + 2*m + 1); + + ++m; + + return std::make_pair(aN, bN); + } + +private: + T a, b, x; + int m; +}; +// +// Evaluate the incomplete beta via the continued fraction representation: +// +template <class T, class Policy> +inline T ibeta_fraction2(T a, T b, T x, T y, const Policy& pol, bool normalised, T* p_derivative) +{ + typedef typename lanczos::lanczos<T, Policy>::type lanczos_type; + BOOST_MATH_STD_USING + T result = ibeta_power_terms(a, b, x, y, lanczos_type(), normalised, pol); + if(p_derivative) + { + *p_derivative = result; + BOOST_ASSERT(*p_derivative >= 0); + } + if(result == 0) + return result; + + ibeta_fraction2_t<T> f(a, b, x); + T fract = boost::math::tools::continued_fraction_b(f, boost::math::policies::get_epsilon<T, Policy>()); + return result / fract; +} +// +// Computes the difference between ibeta(a,b,x) and ibeta(a+k,b,x): +// +template <class T, class Policy> +T ibeta_a_step(T a, T b, T x, T y, int k, const Policy& pol, bool normalised, T* p_derivative) +{ + typedef typename lanczos::lanczos<T, Policy>::type lanczos_type; + + BOOST_MATH_INSTRUMENT_VARIABLE(k); + + T prefix = ibeta_power_terms(a, b, x, y, lanczos_type(), normalised, pol); + if(p_derivative) + { + *p_derivative = prefix; + BOOST_ASSERT(*p_derivative >= 0); + } + prefix /= a; + if(prefix == 0) + return prefix; + T sum = 1; + T term = 1; + // series summation from 0 to k-1: + for(int i = 0; i < k-1; ++i) + { + term *= (a+b+i) * x / (a+i+1); + sum += term; + } + prefix *= sum; + + return prefix; +} +// +// This function is only needed for the non-regular incomplete beta, +// it computes the delta in: +// beta(a,b,x) = prefix + delta * beta(a+k,b,x) +// it is currently only called for small k. +// +template <class T> +inline T rising_factorial_ratio(T a, T b, int k) +{ + // calculate: + // (a)(a+1)(a+2)...(a+k-1) + // _______________________ + // (b)(b+1)(b+2)...(b+k-1) + + // This is only called with small k, for large k + // it is grossly inefficient, do not use outside it's + // intended purpose!!! + BOOST_MATH_INSTRUMENT_VARIABLE(k); + if(k == 0) + return 1; + T result = 1; + for(int i = 0; i < k; ++i) + result *= (a+i) / (b+i); + return result; +} +// +// Routine for a > 15, b < 1 +// +// Begin by figuring out how large our table of Pn's should be, +// quoted accuracies are "guestimates" based on empiracal observation. +// Note that the table size should never exceed the size of our +// tables of factorials. +// +template <class T> +struct Pn_size +{ + // This is likely to be enough for ~35-50 digit accuracy + // but it's hard to quantify exactly: + BOOST_STATIC_CONSTANT(unsigned, value = 50); + BOOST_STATIC_ASSERT(::boost::math::max_factorial<T>::value >= 100); +}; +template <> +struct Pn_size<float> +{ + BOOST_STATIC_CONSTANT(unsigned, value = 15); // ~8-15 digit accuracy + BOOST_STATIC_ASSERT(::boost::math::max_factorial<float>::value >= 30); +}; +template <> +struct Pn_size<double> +{ + BOOST_STATIC_CONSTANT(unsigned, value = 30); // 16-20 digit accuracy + BOOST_STATIC_ASSERT(::boost::math::max_factorial<double>::value >= 60); +}; +template <> +struct Pn_size<long double> +{ + BOOST_STATIC_CONSTANT(unsigned, value = 50); // ~35-50 digit accuracy + BOOST_STATIC_ASSERT(::boost::math::max_factorial<long double>::value >= 100); +}; + +template <class T, class Policy> +T beta_small_b_large_a_series(T a, T b, T x, T y, T s0, T mult, const Policy& pol, bool normalised) +{ + typedef typename lanczos::lanczos<T, Policy>::type lanczos_type; + BOOST_MATH_STD_USING + // + // This is DiDonato and Morris's BGRAT routine, see Eq's 9 through 9.6. + // + // Some values we'll need later, these are Eq 9.1: + // + T bm1 = b - 1; + T t = a + bm1 / 2; + T lx, u; + if(y < 0.35) + lx = boost::math::log1p(-y, pol); + else + lx = log(x); + u = -t * lx; + // and from from 9.2: + T prefix; + T h = regularised_gamma_prefix(b, u, pol, lanczos_type()); + if(h <= tools::min_value<T>()) + return s0; + if(normalised) + { + prefix = h / boost::math::tgamma_delta_ratio(a, b, pol); + prefix /= pow(t, b); + } + else + { + prefix = full_igamma_prefix(b, u, pol) / pow(t, b); + } + prefix *= mult; + // + // now we need the quantity Pn, unfortunatately this is computed + // recursively, and requires a full history of all the previous values + // so no choice but to declare a big table and hope it's big enough... + // + T p[ ::boost::math::detail::Pn_size<T>::value ] = { 1 }; // see 9.3. + // + // Now an initial value for J, see 9.6: + // + T j = boost::math::gamma_q(b, u, pol) / h; + // + // Now we can start to pull things together and evaluate the sum in Eq 9: + // + T sum = s0 + prefix * j; // Value at N = 0 + // some variables we'll need: + unsigned tnp1 = 1; // 2*N+1 + T lx2 = lx / 2; + lx2 *= lx2; + T lxp = 1; + T t4 = 4 * t * t; + T b2n = b; + + for(unsigned n = 1; n < sizeof(p)/sizeof(p[0]); ++n) + { + /* + // debugging code, enable this if you want to determine whether + // the table of Pn's is large enough... + // + static int max_count = 2; + if(n > max_count) + { + max_count = n; + std::cerr << "Max iterations in BGRAT was " << n << std::endl; + } + */ + // + // begin by evaluating the next Pn from Eq 9.4: + // + tnp1 += 2; + p[n] = 0; + T mbn = b - n; + unsigned tmp1 = 3; + for(unsigned m = 1; m < n; ++m) + { + mbn = m * b - n; + p[n] += mbn * p[n-m] / boost::math::unchecked_factorial<T>(tmp1); + tmp1 += 2; + } + p[n] /= n; + p[n] += bm1 / boost::math::unchecked_factorial<T>(tnp1); + // + // Now we want Jn from Jn-1 using Eq 9.6: + // + j = (b2n * (b2n + 1) * j + (u + b2n + 1) * lxp) / t4; + lxp *= lx2; + b2n += 2; + // + // pull it together with Eq 9: + // + T r = prefix * p[n] * j; + sum += r; + if(r > 1) + { + if(fabs(r) < fabs(tools::epsilon<T>() * sum)) + break; + } + else + { + if(fabs(r / tools::epsilon<T>()) < fabs(sum)) + break; + } + } + return sum; +} // template <class T, class L>T beta_small_b_large_a_series(T a, T b, T x, T y, T s0, T mult, const L& l, bool normalised) + +// +// For integer arguments we can relate the incomplete beta to the +// complement of the binomial distribution cdf and use this finite sum. +// +template <class T> +inline T binomial_ccdf(T n, T k, T x, T y) +{ + BOOST_MATH_STD_USING // ADL of std names + T result = pow(x, n); + T term = result; + for(unsigned i = itrunc(T(n - 1)); i > k; --i) + { + term *= ((i + 1) * y) / ((n - i) * x) ; + result += term; + } + + return result; +} + + +// +// The incomplete beta function implementation: +// This is just a big bunch of spagetti code to divide up the +// input range and select the right implementation method for +// each domain: +// +template <class T, class Policy> +T ibeta_imp(T a, T b, T x, const Policy& pol, bool inv, bool normalised, T* p_derivative) +{ + static const char* function = "boost::math::ibeta<%1%>(%1%, %1%, %1%)"; + typedef typename lanczos::lanczos<T, Policy>::type lanczos_type; + BOOST_MATH_STD_USING // for ADL of std math functions. + + BOOST_MATH_INSTRUMENT_VARIABLE(a); + BOOST_MATH_INSTRUMENT_VARIABLE(b); + BOOST_MATH_INSTRUMENT_VARIABLE(x); + BOOST_MATH_INSTRUMENT_VARIABLE(inv); + BOOST_MATH_INSTRUMENT_VARIABLE(normalised); + + bool invert = inv; + T fract; + T y = 1 - x; + + BOOST_ASSERT((p_derivative == 0) || normalised); + + if(p_derivative) + *p_derivative = -1; // value not set. + + if(normalised) + { + // extend to a few very special cases: + if((a == 0) && (b != 0)) + return inv ? 0 : 1; + else if(b == 0) + return inv ? 1 : 0; + } + + if(a <= 0) + policies::raise_domain_error<T>(function, "The argument a to the incomplete beta function must be greater than zero (got a=%1%).", a, pol); + if(b <= 0) + policies::raise_domain_error<T>(function, "The argument b to the incomplete beta function must be greater than zero (got b=%1%).", b, pol); + if((x < 0) || (x > 1)) + policies::raise_domain_error<T>(function, "Parameter x outside the range [0,1] in the incomplete beta function (got x=%1%).", x, pol); + + if(x == 0) + { + if(p_derivative) + { + *p_derivative = (a == 1) ? (T)1 : (a < 1) ? T(tools::max_value<T>() / 2) : T(tools::min_value<T>() * 2); + } + return (invert ? (normalised ? T(1) : boost::math::beta(a, b, pol)) : T(0)); + } + if(x == 1) + { + if(p_derivative) + { + *p_derivative = (b == 1) ? T(1) : (b < 1) ? T(tools::max_value<T>() / 2) : T(tools::min_value<T>() * 2); + } + return (invert == 0 ? (normalised ? 1 : boost::math::beta(a, b, pol)) : 0); + } + + if((std::min)(a, b) <= 1) + { + if(x > 0.5) + { + std::swap(a, b); + std::swap(x, y); + invert = !invert; + BOOST_MATH_INSTRUMENT_VARIABLE(invert); + } + if((std::max)(a, b) <= 1) + { + // Both a,b < 1: + if((a >= (std::min)(T(0.2), b)) || (pow(x, a) <= 0.9)) + { + if(!invert) + { + fract = ibeta_series(a, b, x, T(0), lanczos_type(), normalised, p_derivative, y, pol); + BOOST_MATH_INSTRUMENT_VARIABLE(fract); + } + else + { + fract = -(normalised ? 1 : boost::math::beta(a, b, pol)); + invert = false; + fract = -ibeta_series(a, b, x, fract, lanczos_type(), normalised, p_derivative, y, pol); + BOOST_MATH_INSTRUMENT_VARIABLE(fract); + } + } + else + { + std::swap(a, b); + std::swap(x, y); + invert = !invert; + if(y >= 0.3) + { + if(!invert) + { + fract = ibeta_series(a, b, x, T(0), lanczos_type(), normalised, p_derivative, y, pol); + BOOST_MATH_INSTRUMENT_VARIABLE(fract); + } + else + { + fract = -(normalised ? 1 : boost::math::beta(a, b, pol)); + invert = false; + fract = -ibeta_series(a, b, x, fract, lanczos_type(), normalised, p_derivative, y, pol); + BOOST_MATH_INSTRUMENT_VARIABLE(fract); + } + } + else + { + // Sidestep on a, and then use the series representation: + T prefix; + if(!normalised) + { + prefix = rising_factorial_ratio(T(a+b), a, 20); + } + else + { + prefix = 1; + } + fract = ibeta_a_step(a, b, x, y, 20, pol, normalised, p_derivative); + if(!invert) + { + fract = beta_small_b_large_a_series(T(a + 20), b, x, y, fract, prefix, pol, normalised); + BOOST_MATH_INSTRUMENT_VARIABLE(fract); + } + else + { + fract -= (normalised ? 1 : boost::math::beta(a, b, pol)); + invert = false; + fract = -beta_small_b_large_a_series(T(a + 20), b, x, y, fract, prefix, pol, normalised); + BOOST_MATH_INSTRUMENT_VARIABLE(fract); + } + } + } + } + else + { + // One of a, b < 1 only: + if((b <= 1) || ((x < 0.1) && (pow(b * x, a) <= 0.7))) + { + if(!invert) + { + fract = ibeta_series(a, b, x, T(0), lanczos_type(), normalised, p_derivative, y, pol); + BOOST_MATH_INSTRUMENT_VARIABLE(fract); + } + else + { + fract = -(normalised ? 1 : boost::math::beta(a, b, pol)); + invert = false; + fract = -ibeta_series(a, b, x, fract, lanczos_type(), normalised, p_derivative, y, pol); + BOOST_MATH_INSTRUMENT_VARIABLE(fract); + } + } + else + { + std::swap(a, b); + std::swap(x, y); + invert = !invert; + + if(y >= 0.3) + { + if(!invert) + { + fract = ibeta_series(a, b, x, T(0), lanczos_type(), normalised, p_derivative, y, pol); + BOOST_MATH_INSTRUMENT_VARIABLE(fract); + } + else + { + fract = -(normalised ? 1 : boost::math::beta(a, b, pol)); + invert = false; + fract = -ibeta_series(a, b, x, fract, lanczos_type(), normalised, p_derivative, y, pol); + BOOST_MATH_INSTRUMENT_VARIABLE(fract); + } + } + else if(a >= 15) + { + if(!invert) + { + fract = beta_small_b_large_a_series(a, b, x, y, T(0), T(1), pol, normalised); + BOOST_MATH_INSTRUMENT_VARIABLE(fract); + } + else + { + fract = -(normalised ? 1 : boost::math::beta(a, b, pol)); + invert = false; + fract = -beta_small_b_large_a_series(a, b, x, y, fract, T(1), pol, normalised); + BOOST_MATH_INSTRUMENT_VARIABLE(fract); + } + } + else + { + // Sidestep to improve errors: + T prefix; + if(!normalised) + { + prefix = rising_factorial_ratio(T(a+b), a, 20); + } + else + { + prefix = 1; + } + fract = ibeta_a_step(a, b, x, y, 20, pol, normalised, p_derivative); + BOOST_MATH_INSTRUMENT_VARIABLE(fract); + if(!invert) + { + fract = beta_small_b_large_a_series(T(a + 20), b, x, y, fract, prefix, pol, normalised); + BOOST_MATH_INSTRUMENT_VARIABLE(fract); + } + else + { + fract -= (normalised ? 1 : boost::math::beta(a, b, pol)); + invert = false; + fract = -beta_small_b_large_a_series(T(a + 20), b, x, y, fract, prefix, pol, normalised); + BOOST_MATH_INSTRUMENT_VARIABLE(fract); + } + } + } + } + } + else + { + // Both a,b >= 1: + T lambda; + if(a < b) + { + lambda = a - (a + b) * x; + } + else + { + lambda = (a + b) * y - b; + } + if(lambda < 0) + { + std::swap(a, b); + std::swap(x, y); + invert = !invert; + BOOST_MATH_INSTRUMENT_VARIABLE(invert); + } + + if(b < 40) + { + if((floor(a) == a) && (floor(b) == b)) + { + // relate to the binomial distribution and use a finite sum: + T k = a - 1; + T n = b + k; + fract = binomial_ccdf(n, k, x, y); + if(!normalised) + fract *= boost::math::beta(a, b, pol); + BOOST_MATH_INSTRUMENT_VARIABLE(fract); + } + else if(b * x <= 0.7) + { + if(!invert) + { + fract = ibeta_series(a, b, x, T(0), lanczos_type(), normalised, p_derivative, y, pol); + BOOST_MATH_INSTRUMENT_VARIABLE(fract); + } + else + { + fract = -(normalised ? 1 : boost::math::beta(a, b, pol)); + invert = false; + fract = -ibeta_series(a, b, x, fract, lanczos_type(), normalised, p_derivative, y, pol); + BOOST_MATH_INSTRUMENT_VARIABLE(fract); + } + } + else if(a > 15) + { + // sidestep so we can use the series representation: + int n = itrunc(T(floor(b)), pol); + if(n == b) + --n; + T bbar = b - n; + T prefix; + if(!normalised) + { + prefix = rising_factorial_ratio(T(a+bbar), bbar, n); + } + else + { + prefix = 1; + } + fract = ibeta_a_step(bbar, a, y, x, n, pol, normalised, static_cast<T*>(0)); + fract = beta_small_b_large_a_series(a, bbar, x, y, fract, T(1), pol, normalised); + fract /= prefix; + BOOST_MATH_INSTRUMENT_VARIABLE(fract); + } + else if(normalised) + { + // the formula here for the non-normalised case is tricky to figure + // out (for me!!), and requires two pochhammer calculations rather + // than one, so leave it for now.... + int n = itrunc(T(floor(b)), pol); + T bbar = b - n; + if(bbar <= 0) + { + --n; + bbar += 1; + } + fract = ibeta_a_step(bbar, a, y, x, n, pol, normalised, static_cast<T*>(0)); + fract += ibeta_a_step(a, bbar, x, y, 20, pol, normalised, static_cast<T*>(0)); + if(invert) + fract -= (normalised ? 1 : boost::math::beta(a, b, pol)); + //fract = ibeta_series(a+20, bbar, x, fract, l, normalised, p_derivative, y); + fract = beta_small_b_large_a_series(T(a+20), bbar, x, y, fract, T(1), pol, normalised); + if(invert) + { + fract = -fract; + invert = false; + } + BOOST_MATH_INSTRUMENT_VARIABLE(fract); + } + else + { + fract = ibeta_fraction2(a, b, x, y, pol, normalised, p_derivative); + BOOST_MATH_INSTRUMENT_VARIABLE(fract); + } + } + else + { + fract = ibeta_fraction2(a, b, x, y, pol, normalised, p_derivative); + BOOST_MATH_INSTRUMENT_VARIABLE(fract); + } + } + if(p_derivative) + { + if(*p_derivative < 0) + { + *p_derivative = ibeta_power_terms(a, b, x, y, lanczos_type(), true, pol); + } + T div = y * x; + + if(*p_derivative != 0) + { + if((tools::max_value<T>() * div < *p_derivative)) + { + // overflow, return an arbitarily large value: + *p_derivative = tools::max_value<T>() / 2; + } + else + { + *p_derivative /= div; + } + } + } + return invert ? (normalised ? 1 : boost::math::beta(a, b, pol)) - fract : fract; +} // template <class T, class L>T ibeta_imp(T a, T b, T x, const L& l, bool inv, bool normalised) + +template <class T, class Policy> +inline T ibeta_imp(T a, T b, T x, const Policy& pol, bool inv, bool normalised) +{ + return ibeta_imp(a, b, x, pol, inv, normalised, static_cast<T*>(0)); +} + +template <class T, class Policy> +T ibeta_derivative_imp(T a, T b, T x, const Policy& pol) +{ + static const char* function = "ibeta_derivative<%1%>(%1%,%1%,%1%)"; + // + // start with the usual error checks: + // + if(a <= 0) + policies::raise_domain_error<T>(function, "The argument a to the incomplete beta function must be greater than zero (got a=%1%).", a, pol); + if(b <= 0) + policies::raise_domain_error<T>(function, "The argument b to the incomplete beta function must be greater than zero (got b=%1%).", b, pol); + if((x < 0) || (x > 1)) + policies::raise_domain_error<T>(function, "Parameter x outside the range [0,1] in the incomplete beta function (got x=%1%).", x, pol); + // + // Now the corner cases: + // + if(x == 0) + { + return (a > 1) ? 0 : + (a == 1) ? 1 / boost::math::beta(a, b, pol) : policies::raise_overflow_error<T>(function, 0, pol); + } + else if(x == 1) + { + return (b > 1) ? 0 : + (b == 1) ? 1 / boost::math::beta(a, b, pol) : policies::raise_overflow_error<T>(function, 0, pol); + } + // + // Now the regular cases: + // + typedef typename lanczos::lanczos<T, Policy>::type lanczos_type; + T f1 = ibeta_power_terms<T>(a, b, x, 1 - x, lanczos_type(), true, pol); + T y = (1 - x) * x; + + if(f1 == 0) + return 0; + + if((tools::max_value<T>() * y < f1)) + { + // overflow: + return policies::raise_overflow_error<T>(function, 0, pol); + } + + f1 /= y; + + return f1; +} +// +// Some forwarding functions that dis-ambiguate the third argument type: +// +template <class RT1, class RT2, class Policy> +inline typename tools::promote_args<RT1, RT2>::type + beta(RT1 a, RT2 b, const Policy&, const mpl::true_*) +{ + BOOST_FPU_EXCEPTION_GUARD + typedef typename tools::promote_args<RT1, RT2>::type result_type; + typedef typename policies::evaluation<result_type, Policy>::type value_type; + typedef typename lanczos::lanczos<value_type, Policy>::type evaluation_type; + typedef typename policies::normalise< + Policy, + policies::promote_float<false>, + policies::promote_double<false>, + policies::discrete_quantile<>, + policies::assert_undefined<> >::type forwarding_policy; + + return policies::checked_narrowing_cast<result_type, forwarding_policy>(detail::beta_imp(static_cast<value_type>(a), static_cast<value_type>(b), evaluation_type(), forwarding_policy()), "boost::math::beta<%1%>(%1%,%1%)"); +} +template <class RT1, class RT2, class RT3> +inline typename tools::promote_args<RT1, RT2, RT3>::type + beta(RT1 a, RT2 b, RT3 x, const mpl::false_*) +{ + return boost::math::beta(a, b, x, policies::policy<>()); +} +} // namespace detail + +// +// The actual function entry-points now follow, these just figure out +// which Lanczos approximation to use +// and forward to the implementation functions: +// +template <class RT1, class RT2, class A> +inline typename tools::promote_args<RT1, RT2, A>::type + beta(RT1 a, RT2 b, A arg) +{ + typedef typename policies::is_policy<A>::type tag; + return boost::math::detail::beta(a, b, arg, static_cast<tag*>(0)); +} + +template <class RT1, class RT2> +inline typename tools::promote_args<RT1, RT2>::type + beta(RT1 a, RT2 b) +{ + return boost::math::beta(a, b, policies::policy<>()); +} + +template <class RT1, class RT2, class RT3, class Policy> +inline typename tools::promote_args<RT1, RT2, RT3>::type + beta(RT1 a, RT2 b, RT3 x, const Policy&) +{ + BOOST_FPU_EXCEPTION_GUARD + typedef typename tools::promote_args<RT1, RT2, RT3>::type result_type; + typedef typename policies::evaluation<result_type, Policy>::type value_type; + typedef typename lanczos::lanczos<value_type, Policy>::type evaluation_type; + typedef typename policies::normalise< + Policy, + policies::promote_float<false>, + policies::promote_double<false>, + policies::discrete_quantile<>, + policies::assert_undefined<> >::type forwarding_policy; + + return policies::checked_narrowing_cast<result_type, forwarding_policy>(detail::ibeta_imp(static_cast<value_type>(a), static_cast<value_type>(b), static_cast<value_type>(x), forwarding_policy(), false, false), "boost::math::beta<%1%>(%1%,%1%,%1%)"); +} + +template <class RT1, class RT2, class RT3, class Policy> +inline typename tools::promote_args<RT1, RT2, RT3>::type + betac(RT1 a, RT2 b, RT3 x, const Policy&) +{ + BOOST_FPU_EXCEPTION_GUARD + typedef typename tools::promote_args<RT1, RT2, RT3>::type result_type; + typedef typename policies::evaluation<result_type, Policy>::type value_type; + typedef typename lanczos::lanczos<value_type, Policy>::type evaluation_type; + typedef typename policies::normalise< + Policy, + policies::promote_float<false>, + policies::promote_double<false>, + policies::discrete_quantile<>, + policies::assert_undefined<> >::type forwarding_policy; + + return policies::checked_narrowing_cast<result_type, forwarding_policy>(detail::ibeta_imp(static_cast<value_type>(a), static_cast<value_type>(b), static_cast<value_type>(x), forwarding_policy(), true, false), "boost::math::betac<%1%>(%1%,%1%,%1%)"); +} +template <class RT1, class RT2, class RT3> +inline typename tools::promote_args<RT1, RT2, RT3>::type + betac(RT1 a, RT2 b, RT3 x) +{ + return boost::math::betac(a, b, x, policies::policy<>()); +} + +template <class RT1, class RT2, class RT3, class Policy> +inline typename tools::promote_args<RT1, RT2, RT3>::type + ibeta(RT1 a, RT2 b, RT3 x, const Policy&) +{ + BOOST_FPU_EXCEPTION_GUARD + typedef typename tools::promote_args<RT1, RT2, RT3>::type result_type; + typedef typename policies::evaluation<result_type, Policy>::type value_type; + typedef typename policies::normalise< + Policy, + policies::promote_float<false>, + policies::promote_double<false>, + policies::discrete_quantile<>, + policies::assert_undefined<> >::type forwarding_policy; + + return policies::checked_narrowing_cast<result_type, forwarding_policy>(detail::ibeta_imp(static_cast<value_type>(a), static_cast<value_type>(b), static_cast<value_type>(x), forwarding_policy(), false, true), "boost::math::ibeta<%1%>(%1%,%1%,%1%)"); +} +template <class RT1, class RT2, class RT3> +inline typename tools::promote_args<RT1, RT2, RT3>::type + ibeta(RT1 a, RT2 b, RT3 x) +{ + return boost::math::ibeta(a, b, x, policies::policy<>()); +} + +template <class RT1, class RT2, class RT3, class Policy> +inline typename tools::promote_args<RT1, RT2, RT3>::type + ibetac(RT1 a, RT2 b, RT3 x, const Policy&) +{ + BOOST_FPU_EXCEPTION_GUARD + typedef typename tools::promote_args<RT1, RT2, RT3>::type result_type; + typedef typename policies::evaluation<result_type, Policy>::type value_type; + typedef typename policies::normalise< + Policy, + policies::promote_float<false>, + policies::promote_double<false>, + policies::discrete_quantile<>, + policies::assert_undefined<> >::type forwarding_policy; + + return policies::checked_narrowing_cast<result_type, forwarding_policy>(detail::ibeta_imp(static_cast<value_type>(a), static_cast<value_type>(b), static_cast<value_type>(x), forwarding_policy(), true, true), "boost::math::ibetac<%1%>(%1%,%1%,%1%)"); +} +template <class RT1, class RT2, class RT3> +inline typename tools::promote_args<RT1, RT2, RT3>::type + ibetac(RT1 a, RT2 b, RT3 x) +{ + return boost::math::ibetac(a, b, x, policies::policy<>()); +} + +template <class RT1, class RT2, class RT3, class Policy> +inline typename tools::promote_args<RT1, RT2, RT3>::type + ibeta_derivative(RT1 a, RT2 b, RT3 x, const Policy&) +{ + BOOST_FPU_EXCEPTION_GUARD + typedef typename tools::promote_args<RT1, RT2, RT3>::type result_type; + typedef typename policies::evaluation<result_type, Policy>::type value_type; + typedef typename policies::normalise< + Policy, + policies::promote_float<false>, + policies::promote_double<false>, + policies::discrete_quantile<>, + policies::assert_undefined<> >::type forwarding_policy; + + return policies::checked_narrowing_cast<result_type, forwarding_policy>(detail::ibeta_derivative_imp(static_cast<value_type>(a), static_cast<value_type>(b), static_cast<value_type>(x), forwarding_policy()), "boost::math::ibeta_derivative<%1%>(%1%,%1%,%1%)"); +} +template <class RT1, class RT2, class RT3> +inline typename tools::promote_args<RT1, RT2, RT3>::type + ibeta_derivative(RT1 a, RT2 b, RT3 x) +{ + return boost::math::ibeta_derivative(a, b, x, policies::policy<>()); +} + +} // namespace math +} // namespace boost + +#include <boost/math/special_functions/detail/ibeta_inverse.hpp> +#include <boost/math/special_functions/detail/ibeta_inv_ab.hpp> + +#endif // BOOST_MATH_SPECIAL_BETA_HPP + + + + + diff --git a/Utilities/BGL/boost/math/special_functions/binomial.hpp b/Utilities/BGL/boost/math/special_functions/binomial.hpp new file mode 100644 index 0000000000000000000000000000000000000000..2f3b2e35a53bba72ec992f008107859900472c1b --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/binomial.hpp @@ -0,0 +1,81 @@ +// Copyright John Maddock 2006. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_SF_BINOMIAL_HPP +#define BOOST_MATH_SF_BINOMIAL_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/math/special_functions/factorials.hpp> +#include <boost/math/special_functions/beta.hpp> +#include <boost/math/policies/error_handling.hpp> + +namespace boost{ namespace math{ + +template <class T, class Policy> +T binomial_coefficient(unsigned n, unsigned k, const Policy& pol) +{ + BOOST_STATIC_ASSERT(!boost::is_integral<T>::value); + BOOST_MATH_STD_USING + static const char* function = "boost::math::binomial_coefficient<%1%>(unsigned, unsigned)"; + if(k > n) + return policies::raise_domain_error<T>( + function, + "The binomial coefficient is undefined for k > n, but got k = %1%.", + k, pol); + T result; + if((k == 0) || (k == n)) + return 1; + if((k == 1) || (k == n-1)) + return n; + + if(n <= max_factorial<T>::value) + { + // Use fast table lookup: + result = unchecked_factorial<T>(n); + result /= unchecked_factorial<T>(n-k); + result /= unchecked_factorial<T>(k); + } + else + { + // Use the beta function: + if(k < n - k) + result = k * beta(static_cast<T>(k), static_cast<T>(n-k+1), pol); + else + result = (n - k) * beta(static_cast<T>(k+1), static_cast<T>(n-k), pol); + if(result == 0) + return policies::raise_overflow_error<T>(function, 0, pol); + result = 1 / result; + } + // convert to nearest integer: + return ceil(result - 0.5f); +} +// +// Type float can only store the first 35 factorials, in order to +// increase the chance that we can use a table driven implementation +// we'll promote to double: +// +template <> +inline float binomial_coefficient<float, policies::policy<> >(unsigned n, unsigned k, const policies::policy<>& pol) +{ + return policies::checked_narrowing_cast<float, policies::policy<> >(binomial_coefficient<double>(n, k, pol), "boost::math::binomial_coefficient<%1%>(unsigned,unsigned)"); +} + +template <class T> +inline T binomial_coefficient(unsigned n, unsigned k) +{ + return binomial_coefficient<T>(n, k, policies::policy<>()); +} + +} // namespace math +} // namespace boost + + +#endif // BOOST_MATH_SF_BINOMIAL_HPP + + + diff --git a/Utilities/BGL/boost/math/special_functions/cbrt.hpp b/Utilities/BGL/boost/math/special_functions/cbrt.hpp new file mode 100644 index 0000000000000000000000000000000000000000..1f8ec4f9d567e755ce8b2d3fcc0f44f273afd8da --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/cbrt.hpp @@ -0,0 +1,80 @@ +// (C) Copyright John Maddock 2006. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_SF_CBRT_HPP +#define BOOST_MATH_SF_CBRT_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/math/tools/roots.hpp> +#include <boost/math/special_functions/math_fwd.hpp> + +namespace boost{ namespace math{ + +namespace detail +{ + + template <class T> + struct cbrt_functor + { + cbrt_functor(T const& target) : a(target){} + std::tr1::tuple<T, T, T> operator()(T const& z) + { + T sqr = z * z; + return std::tr1::make_tuple(sqr * z - a, 3 * sqr, 6 * z); + } + private: + T a; + }; + +template <class T, class Policy> +T cbrt_imp(T z, const Policy& pol) +{ + BOOST_MATH_STD_USING + int i_exp, sign(1); + if(z < 0) + { + z = -z; + sign = -sign; + } + if(z == 0) + return 0; + + frexp(z, &i_exp); + T min = static_cast<T>(ldexp(0.5, i_exp/3)); + T max = static_cast<T>(ldexp(2.0, i_exp/3)); + T guess = static_cast<T>(ldexp(1.0, i_exp/3)); + int digits = (policies::digits<T, Policy>()) / 2; + boost::uintmax_t max_iter = policies::get_max_root_iterations<Policy>(); + guess = sign * tools::halley_iterate(detail::cbrt_functor<T>(z), guess, min, max, digits, max_iter); + policies::check_root_iterations("boost::math::cbrt<%1%>", max_iter, pol); + return guess; +} + +} // namespace detail + +template <class T, class Policy> +inline typename tools::promote_args<T>::type cbrt(T z, const Policy& pol) +{ + typedef typename tools::promote_args<T>::type result_type; + return detail::cbrt_imp(result_type(z), pol); +} + +template <class T> +inline typename tools::promote_args<T>::type cbrt(T z) +{ + return cbrt(z, policies::policy<>()); +} + +} // namespace math +} // namespace boost + +#endif // BOOST_MATH_SF_CBRT_HPP + + + + diff --git a/Utilities/BGL/boost/math/special_functions/cos_pi.hpp b/Utilities/BGL/boost/math/special_functions/cos_pi.hpp new file mode 100644 index 0000000000000000000000000000000000000000..be155c197c29b3abfc5932f01a6dcbc513c5ed2f --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/cos_pi.hpp @@ -0,0 +1,68 @@ +// Copyright (c) 2007 John Maddock +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_COS_PI_HPP +#define BOOST_MATH_COS_PI_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/config/no_tr1/cmath.hpp> +#include <boost/math/tools/config.hpp> +#include <boost/math/special_functions/trunc.hpp> +#include <boost/math/tools/promotion.hpp> +#include <boost/math/constants/constants.hpp> + +namespace boost{ namespace math{ namespace detail{ + +template <class T, class Policy> +T cos_pi_imp(T x, const Policy& pol) +{ + BOOST_MATH_STD_USING // ADL of std names + // cos of pi*x: + bool invert = false; + if(x < 0.5) + return cos(constants::pi<T>() * x); + if(x < 1) + { + x = -x; + } + + T rem = floor(x); + if(itrunc(rem, pol) & 1) + invert = !invert; + rem = x - rem; + if(rem > 0.5f) + { + rem = 1 - rem; + invert = !invert; + } + if(rem == 0.5f) + return 0; + + rem = cos(constants::pi<T>() * rem); + return invert ? T(-rem) : rem; +} + +} // namespace detail + +template <class T, class Policy> +inline typename tools::promote_args<T>::type cos_pi(T x, const Policy& pol) +{ + typedef typename tools::promote_args<T>::type result_type; + return boost::math::detail::cos_pi_imp<result_type>(x, pol); +} + +template <class T> +inline typename tools::promote_args<T>::type cos_pi(T x) +{ + return boost::math::cos_pi(x, policies::policy<>()); +} + +} // namespace math +} // namespace boost +#endif + diff --git a/Utilities/BGL/boost/math/special_functions/detail/bessel_i0.hpp b/Utilities/BGL/boost/math/special_functions/detail/bessel_i0.hpp new file mode 100644 index 0000000000000000000000000000000000000000..dd431c638ddb45155467477db6e49567500a3457 --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/detail/bessel_i0.hpp @@ -0,0 +1,101 @@ +// Copyright (c) 2006 Xiaogang Zhang +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_BESSEL_I0_HPP +#define BOOST_MATH_BESSEL_I0_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/math/tools/rational.hpp> +#include <boost/assert.hpp> + +// Modified Bessel function of the first kind of order zero +// minimax rational approximations on intervals, see +// Blair and Edwards, Chalk River Report AECL-4928, 1974 + +namespace boost { namespace math { namespace detail{ + +template <typename T> +T bessel_i0(T x) +{ + static const T P1[] = { + static_cast<T>(-2.2335582639474375249e+15L), + static_cast<T>(-5.5050369673018427753e+14L), + static_cast<T>(-3.2940087627407749166e+13L), + static_cast<T>(-8.4925101247114157499e+11L), + static_cast<T>(-1.1912746104985237192e+10L), + static_cast<T>(-1.0313066708737980747e+08L), + static_cast<T>(-5.9545626019847898221e+05L), + static_cast<T>(-2.4125195876041896775e+03L), + static_cast<T>(-7.0935347449210549190e+00L), + static_cast<T>(-1.5453977791786851041e-02L), + static_cast<T>(-2.5172644670688975051e-05L), + static_cast<T>(-3.0517226450451067446e-08L), + static_cast<T>(-2.6843448573468483278e-11L), + static_cast<T>(-1.5982226675653184646e-14L), + static_cast<T>(-5.2487866627945699800e-18L), + }; + static const T Q1[] = { + static_cast<T>(-2.2335582639474375245e+15L), + static_cast<T>(7.8858692566751002988e+12L), + static_cast<T>(-1.2207067397808979846e+10L), + static_cast<T>(1.0377081058062166144e+07L), + static_cast<T>(-4.8527560179962773045e+03L), + static_cast<T>(1.0L), + }; + static const T P2[] = { + static_cast<T>(-2.2210262233306573296e-04L), + static_cast<T>(1.3067392038106924055e-02L), + static_cast<T>(-4.4700805721174453923e-01L), + static_cast<T>(5.5674518371240761397e+00L), + static_cast<T>(-2.3517945679239481621e+01L), + static_cast<T>(3.1611322818701131207e+01L), + static_cast<T>(-9.6090021968656180000e+00L), + }; + static const T Q2[] = { + static_cast<T>(-5.5194330231005480228e-04L), + static_cast<T>(3.2547697594819615062e-02L), + static_cast<T>(-1.1151759188741312645e+00L), + static_cast<T>(1.3982595353892851542e+01L), + static_cast<T>(-6.0228002066743340583e+01L), + static_cast<T>(8.5539563258012929600e+01L), + static_cast<T>(-3.1446690275135491500e+01L), + static_cast<T>(1.0L), + }; + T value, factor, r; + + BOOST_MATH_STD_USING + using namespace boost::math::tools; + + if (x < 0) + { + x = -x; // even function + } + if (x == 0) + { + return static_cast<T>(1); + } + if (x <= 15) // x in (0, 15] + { + T y = x * x; + value = evaluate_polynomial(P1, y) / evaluate_polynomial(Q1, y); + } + else // x in (15, \infty) + { + T y = 1 / x - T(1) / 15; + r = evaluate_polynomial(P2, y) / evaluate_polynomial(Q2, y); + factor = exp(x) / sqrt(x); + value = factor * r; + } + + return value; +} + +}}} // namespaces + +#endif // BOOST_MATH_BESSEL_I0_HPP + diff --git a/Utilities/BGL/boost/math/special_functions/detail/bessel_i1.hpp b/Utilities/BGL/boost/math/special_functions/detail/bessel_i1.hpp new file mode 100644 index 0000000000000000000000000000000000000000..83ec84ce1968b8e139ca3db91e754b1506a68339 --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/detail/bessel_i1.hpp @@ -0,0 +1,104 @@ +// Copyright (c) 2006 Xiaogang Zhang +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_BESSEL_I1_HPP +#define BOOST_MATH_BESSEL_I1_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/math/tools/rational.hpp> +#include <boost/assert.hpp> + +// Modified Bessel function of the first kind of order one +// minimax rational approximations on intervals, see +// Blair and Edwards, Chalk River Report AECL-4928, 1974 + +namespace boost { namespace math { namespace detail{ + +template <typename T> +T bessel_i1(T x) +{ + static const T P1[] = { + static_cast<T>(-1.4577180278143463643e+15L), + static_cast<T>(-1.7732037840791591320e+14L), + static_cast<T>(-6.9876779648010090070e+12L), + static_cast<T>(-1.3357437682275493024e+11L), + static_cast<T>(-1.4828267606612366099e+09L), + static_cast<T>(-1.0588550724769347106e+07L), + static_cast<T>(-5.1894091982308017540e+04L), + static_cast<T>(-1.8225946631657315931e+02L), + static_cast<T>(-4.7207090827310162436e-01L), + static_cast<T>(-9.1746443287817501309e-04L), + static_cast<T>(-1.3466829827635152875e-06L), + static_cast<T>(-1.4831904935994647675e-09L), + static_cast<T>(-1.1928788903603238754e-12L), + static_cast<T>(-6.5245515583151902910e-16L), + static_cast<T>(-1.9705291802535139930e-19L), + }; + static const T Q1[] = { + static_cast<T>(-2.9154360556286927285e+15L), + static_cast<T>(9.7887501377547640438e+12L), + static_cast<T>(-1.4386907088588283434e+10L), + static_cast<T>(1.1594225856856884006e+07L), + static_cast<T>(-5.1326864679904189920e+03L), + static_cast<T>(1.0L), + }; + static const T P2[] = { + static_cast<T>(1.4582087408985668208e-05L), + static_cast<T>(-8.9359825138577646443e-04L), + static_cast<T>(2.9204895411257790122e-02L), + static_cast<T>(-3.4198728018058047439e-01L), + static_cast<T>(1.3960118277609544334e+00L), + static_cast<T>(-1.9746376087200685843e+00L), + static_cast<T>(8.5591872901933459000e-01L), + static_cast<T>(-6.0437159056137599999e-02L), + }; + static const T Q2[] = { + static_cast<T>(3.7510433111922824643e-05L), + static_cast<T>(-2.2835624489492512649e-03L), + static_cast<T>(7.4212010813186530069e-02L), + static_cast<T>(-8.5017476463217924408e-01L), + static_cast<T>(3.2593714889036996297e+00L), + static_cast<T>(-3.8806586721556593450e+00L), + static_cast<T>(1.0L), + }; + T value, factor, r, w; + + BOOST_MATH_STD_USING + using namespace boost::math::tools; + + w = abs(x); + if (x == 0) + { + return static_cast<T>(0); + } + if (w <= 15) // w in (0, 15] + { + T y = x * x; + r = evaluate_polynomial(P1, y) / evaluate_polynomial(Q1, y); + factor = w; + value = factor * r; + } + else // w in (15, \infty) + { + T y = 1 / w - T(1) / 15; + r = evaluate_polynomial(P2, y) / evaluate_polynomial(Q2, y); + factor = exp(w) / sqrt(w); + value = factor * r; + } + + if (x < 0) + { + value *= -value; // odd function + } + return value; +} + +}}} // namespaces + +#endif // BOOST_MATH_BESSEL_I1_HPP + diff --git a/Utilities/BGL/boost/math/special_functions/detail/bessel_ik.hpp b/Utilities/BGL/boost/math/special_functions/detail/bessel_ik.hpp new file mode 100644 index 0000000000000000000000000000000000000000..98fad41cd19b009a524bf84d2e3b339a5b47572e --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/detail/bessel_ik.hpp @@ -0,0 +1,337 @@ +// Copyright (c) 2006 Xiaogang Zhang +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_BESSEL_IK_HPP +#define BOOST_MATH_BESSEL_IK_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/math/special_functions/round.hpp> +#include <boost/math/special_functions/gamma.hpp> +#include <boost/math/special_functions/sin_pi.hpp> +#include <boost/math/constants/constants.hpp> +#include <boost/math/policies/error_handling.hpp> +#include <boost/math/tools/config.hpp> + +// Modified Bessel functions of the first and second kind of fractional order + +namespace boost { namespace math { + +namespace detail { + +// Calculate K(v, x) and K(v+1, x) by method analogous to +// Temme, Journal of Computational Physics, vol 21, 343 (1976) +template <typename T, typename Policy> +int temme_ik(T v, T x, T* K, T* K1, const Policy& pol) +{ + T f, h, p, q, coef, sum, sum1, tolerance; + T a, b, c, d, sigma, gamma1, gamma2; + unsigned long k; + + BOOST_MATH_STD_USING + using namespace boost::math::tools; + using namespace boost::math::constants; + + + // |x| <= 2, Temme series converge rapidly + // |x| > 2, the larger the |x|, the slower the convergence + BOOST_ASSERT(abs(x) <= 2); + BOOST_ASSERT(abs(v) <= 0.5f); + + T gp = boost::math::tgamma1pm1(v, pol); + T gm = boost::math::tgamma1pm1(-v, pol); + + a = log(x / 2); + b = exp(v * a); + sigma = -a * v; + c = abs(v) < tools::epsilon<T>() ? + T(1) : T(boost::math::sin_pi(v) / (v * pi<T>())); + d = abs(sigma) < tools::epsilon<T>() ? + T(1) : T(sinh(sigma) / sigma); + gamma1 = abs(v) < tools::epsilon<T>() ? + T(-euler<T>()) : T((0.5f / v) * (gp - gm) * c); + gamma2 = (2 + gp + gm) * c / 2; + + // initial values + p = (gp + 1) / (2 * b); + q = (1 + gm) * b / 2; + f = (cosh(sigma) * gamma1 + d * (-a) * gamma2) / c; + h = p; + coef = 1; + sum = coef * f; + sum1 = coef * h; + + // series summation + tolerance = tools::epsilon<T>(); + for (k = 1; k < policies::get_max_series_iterations<Policy>(); k++) + { + f = (k * f + p + q) / (k*k - v*v); + p /= k - v; + q /= k + v; + h = p - k * f; + coef *= x * x / (4 * k); + sum += coef * f; + sum1 += coef * h; + if (abs(coef * f) < abs(sum) * tolerance) + { + break; + } + } + policies::check_series_iterations("boost::math::bessel_ik<%1%>(%1%,%1%) in temme_ik", k, pol); + + *K = sum; + *K1 = 2 * sum1 / x; + + return 0; +} + +// Evaluate continued fraction fv = I_(v+1) / I_v, derived from +// Abramowitz and Stegun, Handbook of Mathematical Functions, 1972, 9.1.73 +template <typename T, typename Policy> +int CF1_ik(T v, T x, T* fv, const Policy& pol) +{ + T C, D, f, a, b, delta, tiny, tolerance; + unsigned long k; + + BOOST_MATH_STD_USING + + // |x| <= |v|, CF1_ik converges rapidly + // |x| > |v|, CF1_ik needs O(|x|) iterations to converge + + // modified Lentz's method, see + // Lentz, Applied Optics, vol 15, 668 (1976) + tolerance = 2 * tools::epsilon<T>(); + BOOST_MATH_INSTRUMENT_VARIABLE(tolerance); + tiny = sqrt(tools::min_value<T>()); + BOOST_MATH_INSTRUMENT_VARIABLE(tiny); + C = f = tiny; // b0 = 0, replace with tiny + D = 0; + for (k = 1; k < policies::get_max_series_iterations<Policy>(); k++) + { + a = 1; + b = 2 * (v + k) / x; + C = b + a / C; + D = b + a * D; + if (C == 0) { C = tiny; } + if (D == 0) { D = tiny; } + D = 1 / D; + delta = C * D; + f *= delta; + BOOST_MATH_INSTRUMENT_VARIABLE(delta-1); + if (abs(delta - 1) <= tolerance) + { + break; + } + } + BOOST_MATH_INSTRUMENT_VARIABLE(k); + policies::check_series_iterations("boost::math::bessel_ik<%1%>(%1%,%1%) in CF1_ik", k, pol); + + *fv = f; + + return 0; +} + +// Calculate K(v, x) and K(v+1, x) by evaluating continued fraction +// z1 / z0 = U(v+1.5, 2v+1, 2x) / U(v+0.5, 2v+1, 2x), see +// Thompson and Barnett, Computer Physics Communications, vol 47, 245 (1987) +template <typename T, typename Policy> +int CF2_ik(T v, T x, T* Kv, T* Kv1, const Policy& pol) +{ + BOOST_MATH_STD_USING + using namespace boost::math::constants; + + T S, C, Q, D, f, a, b, q, delta, tolerance, current, prev; + unsigned long k; + + // |x| >= |v|, CF2_ik converges rapidly + // |x| -> 0, CF2_ik fails to converge + + BOOST_ASSERT(abs(x) > 1); + + // Steed's algorithm, see Thompson and Barnett, + // Journal of Computational Physics, vol 64, 490 (1986) + tolerance = tools::epsilon<T>(); + a = v * v - 0.25f; + b = 2 * (x + 1); // b1 + D = 1 / b; // D1 = 1 / b1 + f = delta = D; // f1 = delta1 = D1, coincidence + prev = 0; // q0 + current = 1; // q1 + Q = C = -a; // Q1 = C1 because q1 = 1 + S = 1 + Q * delta; // S1 + BOOST_MATH_INSTRUMENT_VARIABLE(tolerance); + BOOST_MATH_INSTRUMENT_VARIABLE(a); + BOOST_MATH_INSTRUMENT_VARIABLE(b); + BOOST_MATH_INSTRUMENT_VARIABLE(D); + BOOST_MATH_INSTRUMENT_VARIABLE(f); + for (k = 2; k < policies::get_max_series_iterations<Policy>(); k++) // starting from 2 + { + // continued fraction f = z1 / z0 + a -= 2 * (k - 1); + b += 2; + D = 1 / (b + a * D); + delta *= b * D - 1; + f += delta; + + // series summation S = 1 + \sum_{n=1}^{\infty} C_n * z_n / z_0 + q = (prev - (b - 2) * current) / a; + prev = current; + current = q; // forward recurrence for q + C *= -a / k; + Q += C * q; + S += Q * delta; + + // S converges slower than f + BOOST_MATH_INSTRUMENT_VARIABLE(Q * delta); + BOOST_MATH_INSTRUMENT_VARIABLE(abs(S) * tolerance); + if (abs(Q * delta) < abs(S) * tolerance) + { + break; + } + } + policies::check_series_iterations("boost::math::bessel_ik<%1%>(%1%,%1%) in CF2_ik", k, pol); + + *Kv = sqrt(pi<T>() / (2 * x)) * exp(-x) / S; + *Kv1 = *Kv * (0.5f + v + x + (v * v - 0.25f) * f) / x; + BOOST_MATH_INSTRUMENT_VARIABLE(*Kv); + BOOST_MATH_INSTRUMENT_VARIABLE(*Kv1); + + return 0; +} + +enum{ + need_i = 1, + need_k = 2 +}; + +// Compute I(v, x) and K(v, x) simultaneously by Temme's method, see +// Temme, Journal of Computational Physics, vol 19, 324 (1975) +template <typename T, typename Policy> +int bessel_ik(T v, T x, T* I, T* K, int kind, const Policy& pol) +{ + // Kv1 = K_(v+1), fv = I_(v+1) / I_v + // Ku1 = K_(u+1), fu = I_(u+1) / I_u + T u, Iv, Kv, Kv1, Ku, Ku1, fv; + T W, current, prev, next; + bool reflect = false; + unsigned n, k; + BOOST_MATH_INSTRUMENT_VARIABLE(v); + BOOST_MATH_INSTRUMENT_VARIABLE(x); + BOOST_MATH_INSTRUMENT_VARIABLE(kind); + + BOOST_MATH_STD_USING + using namespace boost::math::tools; + using namespace boost::math::constants; + + static const char* function = "boost::math::bessel_ik<%1%>(%1%,%1%)"; + + if (v < 0) + { + reflect = true; + v = -v; // v is non-negative from here + kind |= need_k; + } + n = iround(v, pol); + u = v - n; // -1/2 <= u < 1/2 + BOOST_MATH_INSTRUMENT_VARIABLE(n); + BOOST_MATH_INSTRUMENT_VARIABLE(u); + + if (x < 0) + { + *I = *K = policies::raise_domain_error<T>(function, + "Got x = %1% but real argument x must be non-negative, complex number result not supported.", x, pol); + return 1; + } + if (x == 0) + { + Iv = (v == 0) ? static_cast<T>(1) : static_cast<T>(0); + if(kind & need_k) + { + Kv = policies::raise_overflow_error<T>(function, 0, pol); + } + else + { + Kv = std::numeric_limits<T>::quiet_NaN(); // any value will do + } + + if(reflect && (kind & need_i)) + { + T z = (u + n % 2); + Iv = boost::math::sin_pi(z, pol) == 0 ? + Iv : + policies::raise_overflow_error<T>(function, 0, pol); // reflection formula + } + + *I = Iv; + *K = Kv; + return 0; + } + + // x is positive until reflection + W = 1 / x; // Wronskian + if (x <= 2) // x in (0, 2] + { + temme_ik(u, x, &Ku, &Ku1, pol); // Temme series + } + else // x in (2, \infty) + { + CF2_ik(u, x, &Ku, &Ku1, pol); // continued fraction CF2_ik + } + prev = Ku; + current = Ku1; + for (k = 1; k <= n; k++) // forward recurrence for K + { + next = 2 * (u + k) * current / x + prev; + prev = current; + current = next; + } + Kv = prev; + Kv1 = current; + if(kind & need_i) + { + T lim = (4 * v * v + 10) / (8 * x); + lim *= lim; + lim *= lim; + lim /= 24; + if((lim < tools::epsilon<T>() * 10) && (x > 100)) + { + // x is huge compared to v, CF1 may be very slow + // to converge so use asymptotic expansion for large + // x case instead. Note that the asymptotic expansion + // isn't very accurate - so it's deliberately very hard + // to get here - probably we're going to overflow: + Iv = asymptotic_bessel_i_large_x(v, x, pol); + } + else + { + CF1_ik(v, x, &fv, pol); // continued fraction CF1_ik + Iv = W / (Kv * fv + Kv1); // Wronskian relation + } + } + else + Iv = std::numeric_limits<T>::quiet_NaN(); // any value will do + + if (reflect) + { + T z = (u + n % 2); + *I = Iv + (2 / pi<T>()) * boost::math::sin_pi(z) * Kv; // reflection formula + *K = Kv; + } + else + { + *I = Iv; + *K = Kv; + } + BOOST_MATH_INSTRUMENT_VARIABLE(*I); + BOOST_MATH_INSTRUMENT_VARIABLE(*K); + return 0; +} + +}}} // namespaces + +#endif // BOOST_MATH_BESSEL_IK_HPP + diff --git a/Utilities/BGL/boost/math/special_functions/detail/bessel_j0.hpp b/Utilities/BGL/boost/math/special_functions/detail/bessel_j0.hpp new file mode 100644 index 0000000000000000000000000000000000000000..8993daae8084fad7fd27285b569d0656c39b8e94 --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/detail/bessel_j0.hpp @@ -0,0 +1,152 @@ +// Copyright (c) 2006 Xiaogang Zhang +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_BESSEL_J0_HPP +#define BOOST_MATH_BESSEL_J0_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/math/constants/constants.hpp> +#include <boost/math/tools/rational.hpp> +#include <boost/assert.hpp> + +// Bessel function of the first kind of order zero +// x <= 8, minimax rational approximations on root-bracketing intervals +// x > 8, Hankel asymptotic expansion in Hart, Computer Approximations, 1968 + +namespace boost { namespace math { namespace detail{ + +template <typename T> +T bessel_j0(T x) +{ + static const T P1[] = { + static_cast<T>(-4.1298668500990866786e+11L), + static_cast<T>(2.7282507878605942706e+10L), + static_cast<T>(-6.2140700423540120665e+08L), + static_cast<T>(6.6302997904833794242e+06L), + static_cast<T>(-3.6629814655107086448e+04L), + static_cast<T>(1.0344222815443188943e+02L), + static_cast<T>(-1.2117036164593528341e-01L) + }; + static const T Q1[] = { + static_cast<T>(2.3883787996332290397e+12L), + static_cast<T>(2.6328198300859648632e+10L), + static_cast<T>(1.3985097372263433271e+08L), + static_cast<T>(4.5612696224219938200e+05L), + static_cast<T>(9.3614022392337710626e+02L), + static_cast<T>(1.0L), + static_cast<T>(0.0L) + }; + static const T P2[] = { + static_cast<T>(-1.8319397969392084011e+03L), + static_cast<T>(-1.2254078161378989535e+04L), + static_cast<T>(-7.2879702464464618998e+03L), + static_cast<T>(1.0341910641583726701e+04L), + static_cast<T>(1.1725046279757103576e+04L), + static_cast<T>(4.4176707025325087628e+03L), + static_cast<T>(7.4321196680624245801e+02L), + static_cast<T>(4.8591703355916499363e+01L) + }; + static const T Q2[] = { + static_cast<T>(-3.5783478026152301072e+05L), + static_cast<T>(2.4599102262586308984e+05L), + static_cast<T>(-8.4055062591169562211e+04L), + static_cast<T>(1.8680990008359188352e+04L), + static_cast<T>(-2.9458766545509337327e+03L), + static_cast<T>(3.3307310774649071172e+02L), + static_cast<T>(-2.5258076240801555057e+01L), + static_cast<T>(1.0L) + }; + static const T PC[] = { + static_cast<T>(2.2779090197304684302e+04L), + static_cast<T>(4.1345386639580765797e+04L), + static_cast<T>(2.1170523380864944322e+04L), + static_cast<T>(3.4806486443249270347e+03L), + static_cast<T>(1.5376201909008354296e+02L), + static_cast<T>(8.8961548424210455236e-01L) + }; + static const T QC[] = { + static_cast<T>(2.2779090197304684318e+04L), + static_cast<T>(4.1370412495510416640e+04L), + static_cast<T>(2.1215350561880115730e+04L), + static_cast<T>(3.5028735138235608207e+03L), + static_cast<T>(1.5711159858080893649e+02L), + static_cast<T>(1.0L) + }; + static const T PS[] = { + static_cast<T>(-8.9226600200800094098e+01L), + static_cast<T>(-1.8591953644342993800e+02L), + static_cast<T>(-1.1183429920482737611e+02L), + static_cast<T>(-2.2300261666214198472e+01L), + static_cast<T>(-1.2441026745835638459e+00L), + static_cast<T>(-8.8033303048680751817e-03L) + }; + static const T QS[] = { + static_cast<T>(5.7105024128512061905e+03L), + static_cast<T>(1.1951131543434613647e+04L), + static_cast<T>(7.2642780169211018836e+03L), + static_cast<T>(1.4887231232283756582e+03L), + static_cast<T>(9.0593769594993125859e+01L), + static_cast<T>(1.0L) + }; + static const T x1 = static_cast<T>(2.4048255576957727686e+00L), + x2 = static_cast<T>(5.5200781102863106496e+00L), + x11 = static_cast<T>(6.160e+02L), + x12 = static_cast<T>(-1.42444230422723137837e-03L), + x21 = static_cast<T>(1.4130e+03L), + x22 = static_cast<T>(5.46860286310649596604e-04L); + + T value, factor, r, rc, rs; + + BOOST_MATH_STD_USING + using namespace boost::math::tools; + using namespace boost::math::constants; + + if (x < 0) + { + x = -x; // even function + } + if (x == 0) + { + return static_cast<T>(1); + } + if (x <= 4) // x in (0, 4] + { + T y = x * x; + BOOST_ASSERT(sizeof(P1) == sizeof(Q1)); + r = evaluate_rational(P1, Q1, y); + factor = (x + x1) * ((x - x11/256) - x12); + value = factor * r; + } + else if (x <= 8.0) // x in (4, 8] + { + T y = 1 - (x * x)/64; + BOOST_ASSERT(sizeof(P2) == sizeof(Q2)); + r = evaluate_rational(P2, Q2, y); + factor = (x + x2) * ((x - x21/256) - x22); + value = factor * r; + } + else // x in (8, \infty) + { + T y = 8 / x; + T y2 = y * y; + T z = x - 0.25f * pi<T>(); + BOOST_ASSERT(sizeof(PC) == sizeof(QC)); + BOOST_ASSERT(sizeof(PS) == sizeof(QS)); + rc = evaluate_rational(PC, QC, y2); + rs = evaluate_rational(PS, QS, y2); + factor = sqrt(2 / (x * pi<T>())); + value = factor * (rc * cos(z) - y * rs * sin(z)); + } + + return value; +} + +}}} // namespaces + +#endif // BOOST_MATH_BESSEL_J0_HPP + diff --git a/Utilities/BGL/boost/math/special_functions/detail/bessel_j1.hpp b/Utilities/BGL/boost/math/special_functions/detail/bessel_j1.hpp new file mode 100644 index 0000000000000000000000000000000000000000..5fd206196e0559516ea8f5fc30969bd737704bf4 --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/detail/bessel_j1.hpp @@ -0,0 +1,157 @@ +// Copyright (c) 2006 Xiaogang Zhang +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_BESSEL_J1_HPP +#define BOOST_MATH_BESSEL_J1_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/math/constants/constants.hpp> +#include <boost/math/tools/rational.hpp> +#include <boost/assert.hpp> + +// Bessel function of the first kind of order one +// x <= 8, minimax rational approximations on root-bracketing intervals +// x > 8, Hankel asymptotic expansion in Hart, Computer Approximations, 1968 + +namespace boost { namespace math{ namespace detail{ + +template <typename T> +T bessel_j1(T x) +{ + static const T P1[] = { + static_cast<T>(-1.4258509801366645672e+11L), + static_cast<T>(6.6781041261492395835e+09L), + static_cast<T>(-1.1548696764841276794e+08L), + static_cast<T>(9.8062904098958257677e+05L), + static_cast<T>(-4.4615792982775076130e+03L), + static_cast<T>(1.0650724020080236441e+01L), + static_cast<T>(-1.0767857011487300348e-02L) + }; + static const T Q1[] = { + static_cast<T>(4.1868604460820175290e+12L), + static_cast<T>(4.2091902282580133541e+10L), + static_cast<T>(2.0228375140097033958e+08L), + static_cast<T>(5.9117614494174794095e+05L), + static_cast<T>(1.0742272239517380498e+03L), + static_cast<T>(1.0L), + static_cast<T>(0.0L) + }; + static const T P2[] = { + static_cast<T>(-1.7527881995806511112e+16L), + static_cast<T>(1.6608531731299018674e+15L), + static_cast<T>(-3.6658018905416665164e+13L), + static_cast<T>(3.5580665670910619166e+11L), + static_cast<T>(-1.8113931269860667829e+09L), + static_cast<T>(5.0793266148011179143e+06L), + static_cast<T>(-7.5023342220781607561e+03L), + static_cast<T>(4.6179191852758252278e+00L) + }; + static const T Q2[] = { + static_cast<T>(1.7253905888447681194e+18L), + static_cast<T>(1.7128800897135812012e+16L), + static_cast<T>(8.4899346165481429307e+13L), + static_cast<T>(2.7622777286244082666e+11L), + static_cast<T>(6.4872502899596389593e+08L), + static_cast<T>(1.1267125065029138050e+06L), + static_cast<T>(1.3886978985861357615e+03L), + static_cast<T>(1.0L) + }; + static const T PC[] = { + static_cast<T>(-4.4357578167941278571e+06L), + static_cast<T>(-9.9422465050776411957e+06L), + static_cast<T>(-6.6033732483649391093e+06L), + static_cast<T>(-1.5235293511811373833e+06L), + static_cast<T>(-1.0982405543459346727e+05L), + static_cast<T>(-1.6116166443246101165e+03L), + static_cast<T>(0.0L) + }; + static const T QC[] = { + static_cast<T>(-4.4357578167941278568e+06L), + static_cast<T>(-9.9341243899345856590e+06L), + static_cast<T>(-6.5853394797230870728e+06L), + static_cast<T>(-1.5118095066341608816e+06L), + static_cast<T>(-1.0726385991103820119e+05L), + static_cast<T>(-1.4550094401904961825e+03L), + static_cast<T>(1.0L) + }; + static const T PS[] = { + static_cast<T>(3.3220913409857223519e+04L), + static_cast<T>(8.5145160675335701966e+04L), + static_cast<T>(6.6178836581270835179e+04L), + static_cast<T>(1.8494262873223866797e+04L), + static_cast<T>(1.7063754290207680021e+03L), + static_cast<T>(3.5265133846636032186e+01L), + static_cast<T>(0.0L) + }; + static const T QS[] = { + static_cast<T>(7.0871281941028743574e+05L), + static_cast<T>(1.8194580422439972989e+06L), + static_cast<T>(1.4194606696037208929e+06L), + static_cast<T>(4.0029443582266975117e+05L), + static_cast<T>(3.7890229745772202641e+04L), + static_cast<T>(8.6383677696049909675e+02L), + static_cast<T>(1.0L) + }; + static const T x1 = static_cast<T>(3.8317059702075123156e+00L), + x2 = static_cast<T>(7.0155866698156187535e+00L), + x11 = static_cast<T>(9.810e+02L), + x12 = static_cast<T>(-3.2527979248768438556e-04L), + x21 = static_cast<T>(1.7960e+03L), + x22 = static_cast<T>(-3.8330184381246462950e-05L); + + T value, factor, r, rc, rs, w; + + BOOST_MATH_STD_USING + using namespace boost::math::tools; + using namespace boost::math::constants; + + w = abs(x); + if (x == 0) + { + return static_cast<T>(0); + } + if (w <= 4) // w in (0, 4] + { + T y = x * x; + BOOST_ASSERT(sizeof(P1) == sizeof(Q1)); + r = evaluate_rational(P1, Q1, y); + factor = w * (w + x1) * ((w - x11/256) - x12); + value = factor * r; + } + else if (w <= 8) // w in (4, 8] + { + T y = x * x; + BOOST_ASSERT(sizeof(P2) == sizeof(Q2)); + r = evaluate_rational(P2, Q2, y); + factor = w * (w + x2) * ((w - x21/256) - x22); + value = factor * r; + } + else // w in (8, \infty) + { + T y = 8 / w; + T y2 = y * y; + T z = w - 0.75f * pi<T>(); + BOOST_ASSERT(sizeof(PC) == sizeof(QC)); + BOOST_ASSERT(sizeof(PS) == sizeof(QS)); + rc = evaluate_rational(PC, QC, y2); + rs = evaluate_rational(PS, QS, y2); + factor = sqrt(2 / (w * pi<T>())); + value = factor * (rc * cos(z) - y * rs * sin(z)); + } + + if (x < 0) + { + value *= -1; // odd function + } + return value; +} + +}}} // namespaces + +#endif // BOOST_MATH_BESSEL_J1_HPP + diff --git a/Utilities/BGL/boost/math/special_functions/detail/bessel_jn.hpp b/Utilities/BGL/boost/math/special_functions/detail/bessel_jn.hpp new file mode 100644 index 0000000000000000000000000000000000000000..7772d2c1844b62f866125dcc25d0e3c145fd3c2b --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/detail/bessel_jn.hpp @@ -0,0 +1,98 @@ +// Copyright (c) 2006 Xiaogang Zhang +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_BESSEL_JN_HPP +#define BOOST_MATH_BESSEL_JN_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/math/special_functions/detail/bessel_j0.hpp> +#include <boost/math/special_functions/detail/bessel_j1.hpp> +#include <boost/math/special_functions/detail/bessel_jy.hpp> + +// Bessel function of the first kind of integer order +// J_n(z) is the minimal solution +// n < abs(z), forward recurrence stable and usable +// n >= abs(z), forward recurrence unstable, use Miller's algorithm + +namespace boost { namespace math { namespace detail{ + +template <typename T, typename Policy> +T bessel_jn(int n, T x, const Policy& pol) +{ + T value(0), factor, current, prev, next; + + BOOST_MATH_STD_USING + + // + // Reflection has to come first: + // + if (n < 0) + { + factor = (n & 0x1) ? -1 : 1; // J_{-n}(z) = (-1)^n J_n(z) + n = -n; + } + else + { + factor = 1; + } + // + // Special cases: + // + if (n == 0) + { + return factor * bessel_j0(x); + } + if (n == 1) + { + return factor * bessel_j1(x); + } + + if (x == 0) // n >= 2 + { + return static_cast<T>(0); + } + + BOOST_ASSERT(n > 1); + if (n < abs(x)) // forward recurrence + { + prev = bessel_j0(x); + current = bessel_j1(x); + for (int k = 1; k < n; k++) + { + value = 2 * k * current / x - prev; + prev = current; + current = value; + } + } + else // backward recurrence + { + T fn; int s; // fn = J_(n+1) / J_n + // |x| <= n, fast convergence for continued fraction CF1 + boost::math::detail::CF1_jy(static_cast<T>(n), x, &fn, &s, pol); + // tiny initial value to prevent overflow + T init = sqrt(tools::min_value<T>()); + prev = fn * init; + current = init; + for (int k = n; k > 0; k--) + { + next = 2 * k * current / x - prev; + prev = current; + current = next; + } + T ratio = init / current; // scaling ratio + value = bessel_j0(x) * ratio; // normalization + } + value *= factor; + + return value; +} + +}}} // namespaces + +#endif // BOOST_MATH_BESSEL_JN_HPP + diff --git a/Utilities/BGL/boost/math/special_functions/detail/bessel_jy.hpp b/Utilities/BGL/boost/math/special_functions/detail/bessel_jy.hpp new file mode 100644 index 0000000000000000000000000000000000000000..3d276c1f4ca1bb02c3143748b1d338d258c470bd --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/detail/bessel_jy.hpp @@ -0,0 +1,366 @@ +// Copyright (c) 2006 Xiaogang Zhang +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_BESSEL_JY_HPP +#define BOOST_MATH_BESSEL_JY_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/math/tools/config.hpp> +#include <boost/math/special_functions/gamma.hpp> +#include <boost/math/special_functions/sign.hpp> +#include <boost/math/special_functions/hypot.hpp> +#include <boost/math/special_functions/sin_pi.hpp> +#include <boost/math/special_functions/cos_pi.hpp> +#include <boost/math/special_functions/detail/simple_complex.hpp> +#include <boost/math/special_functions/detail/bessel_jy_asym.hpp> +#include <boost/math/constants/constants.hpp> +#include <boost/math/policies/error_handling.hpp> +#include <boost/mpl/if.hpp> +#include <boost/type_traits/is_floating_point.hpp> +#include <complex> + +// Bessel functions of the first and second kind of fractional order + +namespace boost { namespace math { + +namespace detail { + +// Calculate Y(v, x) and Y(v+1, x) by Temme's method, see +// Temme, Journal of Computational Physics, vol 21, 343 (1976) +template <typename T, typename Policy> +int temme_jy(T v, T x, T* Y, T* Y1, const Policy& pol) +{ + T g, h, p, q, f, coef, sum, sum1, tolerance; + T a, d, e, sigma; + unsigned long k; + + BOOST_MATH_STD_USING + using namespace boost::math::tools; + using namespace boost::math::constants; + + BOOST_ASSERT(fabs(v) <= 0.5f); // precondition for using this routine + + T gp = boost::math::tgamma1pm1(v, pol); + T gm = boost::math::tgamma1pm1(-v, pol); + T spv = boost::math::sin_pi(v, pol); + T spv2 = boost::math::sin_pi(v/2, pol); + T xp = pow(x/2, v); + + a = log(x / 2); + sigma = -a * v; + d = abs(sigma) < tools::epsilon<T>() ? + T(1) : sinh(sigma) / sigma; + e = abs(v) < tools::epsilon<T>() ? T(v*pi<T>()*pi<T>() / 2) + : T(2 * spv2 * spv2 / v); + + T g1 = (v == 0) ? T(-euler<T>()) : T((gp - gm) / ((1 + gp) * (1 + gm) * 2 * v)); + T g2 = (2 + gp + gm) / ((1 + gp) * (1 + gm) * 2); + T vspv = (fabs(v) < tools::epsilon<T>()) ? T(1/constants::pi<T>()) : T(v / spv); + f = (g1 * cosh(sigma) - g2 * a * d) * 2 * vspv; + + p = vspv / (xp * (1 + gm)); + q = vspv * xp / (1 + gp); + + g = f + e * q; + h = p; + coef = 1; + sum = coef * g; + sum1 = coef * h; + + T v2 = v * v; + T coef_mult = -x * x / 4; + + // series summation + tolerance = tools::epsilon<T>(); + for (k = 1; k < policies::get_max_series_iterations<Policy>(); k++) + { + f = (k * f + p + q) / (k*k - v2); + p /= k - v; + q /= k + v; + g = f + e * q; + h = p - k * g; + coef *= coef_mult / k; + sum += coef * g; + sum1 += coef * h; + if (abs(coef * g) < abs(sum) * tolerance) + { + break; + } + } + policies::check_series_iterations("boost::math::bessel_jy<%1%>(%1%,%1%) in temme_jy", k, pol); + *Y = -sum; + *Y1 = -2 * sum1 / x; + + return 0; +} + +// Evaluate continued fraction fv = J_(v+1) / J_v, see +// Abramowitz and Stegun, Handbook of Mathematical Functions, 1972, 9.1.73 +template <typename T, typename Policy> +int CF1_jy(T v, T x, T* fv, int* sign, const Policy& pol) +{ + T C, D, f, a, b, delta, tiny, tolerance; + unsigned long k; + int s = 1; + + BOOST_MATH_STD_USING + + // |x| <= |v|, CF1_jy converges rapidly + // |x| > |v|, CF1_jy needs O(|x|) iterations to converge + + // modified Lentz's method, see + // Lentz, Applied Optics, vol 15, 668 (1976) + tolerance = 2 * tools::epsilon<T>(); + tiny = sqrt(tools::min_value<T>()); + C = f = tiny; // b0 = 0, replace with tiny + D = 0; + for (k = 1; k < policies::get_max_series_iterations<Policy>() * 100; k++) + { + a = -1; + b = 2 * (v + k) / x; + C = b + a / C; + D = b + a * D; + if (C == 0) { C = tiny; } + if (D == 0) { D = tiny; } + D = 1 / D; + delta = C * D; + f *= delta; + if (D < 0) { s = -s; } + if (abs(delta - 1) < tolerance) + { break; } + } + policies::check_series_iterations("boost::math::bessel_jy<%1%>(%1%,%1%) in CF1_jy", k / 100, pol); + *fv = -f; + *sign = s; // sign of denominator + + return 0; +} + +template <class T> +struct complex_trait +{ + typedef typename mpl::if_<is_floating_point<T>, + std::complex<T>, sc::simple_complex<T> >::type type; +}; + +// Evaluate continued fraction p + iq = (J' + iY') / (J + iY), see +// Press et al, Numerical Recipes in C, 2nd edition, 1992 +template <typename T, typename Policy> +int CF2_jy(T v, T x, T* p, T* q, const Policy& pol) +{ + BOOST_MATH_STD_USING + + typedef typename complex_trait<T>::type complex_type; + + complex_type C, D, f, a, b, delta, one(1); + T tiny, zero(0); + unsigned long k; + + // |x| >= |v|, CF2_jy converges rapidly + // |x| -> 0, CF2_jy fails to converge + BOOST_ASSERT(fabs(x) > 1); + + // modified Lentz's method, complex numbers involved, see + // Lentz, Applied Optics, vol 15, 668 (1976) + T tolerance = 2 * tools::epsilon<T>(); + tiny = sqrt(tools::min_value<T>()); + C = f = complex_type(-0.5f/x, 1); + D = 0; + for (k = 1; k < policies::get_max_series_iterations<Policy>(); k++) + { + a = (k - 0.5f)*(k - 0.5f) - v*v; + if (k == 1) + { + a *= complex_type(T(0), 1/x); + } + b = complex_type(2*x, T(2*k)); + C = b + a / C; + D = b + a * D; + if (C == zero) { C = tiny; } + if (D == zero) { D = tiny; } + D = one / D; + delta = C * D; + f *= delta; + if (abs(delta - one) < tolerance) { break; } + } + policies::check_series_iterations("boost::math::bessel_jy<%1%>(%1%,%1%) in CF2_jy", k, pol); + *p = real(f); + *q = imag(f); + + return 0; +} + +enum +{ + need_j = 1, need_y = 2 +}; + +// Compute J(v, x) and Y(v, x) simultaneously by Steed's method, see +// Barnett et al, Computer Physics Communications, vol 8, 377 (1974) +template <typename T, typename Policy> +int bessel_jy(T v, T x, T* J, T* Y, int kind, const Policy& pol) +{ + BOOST_ASSERT(x >= 0); + + T u, Jv, Ju, Yv, Yv1, Yu, Yu1(0), fv, fu; + T W, p, q, gamma, current, prev, next; + bool reflect = false; + unsigned n, k; + int s; + + static const char* function = "boost::math::bessel_jy<%1%>(%1%,%1%)"; + + BOOST_MATH_STD_USING + using namespace boost::math::tools; + using namespace boost::math::constants; + + if (v < 0) + { + reflect = true; + v = -v; // v is non-negative from here + kind = need_j|need_y; // need both for reflection formula + } + n = iround(v, pol); + u = v - n; // -1/2 <= u < 1/2 + + if (x == 0) + { + *J = *Y = policies::raise_overflow_error<T>( + function, 0, pol); + return 1; + } + + // x is positive until reflection + W = T(2) / (x * pi<T>()); // Wronskian + if (x <= 2) // x in (0, 2] + { + if(temme_jy(u, x, &Yu, &Yu1, pol)) // Temme series + { + // domain error: + *J = *Y = Yu; + return 1; + } + prev = Yu; + current = Yu1; + for (k = 1; k <= n; k++) // forward recurrence for Y + { + next = 2 * (u + k) * current / x - prev; + prev = current; + current = next; + } + Yv = prev; + Yv1 = current; + if(kind&need_j) + { + CF1_jy(v, x, &fv, &s, pol); // continued fraction CF1_jy + Jv = W / (Yv * fv - Yv1); // Wronskian relation + } + else + Jv = std::numeric_limits<T>::quiet_NaN(); // any value will do, we're not using it. + } + else // x in (2, \infty) + { + // Get Y(u, x): + // define tag type that will dispatch to right limits: + typedef typename bessel_asymptotic_tag<T, Policy>::type tag_type; + + T lim; + switch(kind) + { + case need_j: + lim = asymptotic_bessel_j_limit<T>(v, tag_type()); + break; + case need_y: + lim = asymptotic_bessel_y_limit<T>(tag_type()); + break; + default: + lim = (std::max)( + asymptotic_bessel_j_limit<T>(v, tag_type()), + asymptotic_bessel_y_limit<T>(tag_type())); + break; + } + if(x > lim) + { + if(kind&need_y) + { + Yu = asymptotic_bessel_y_large_x_2(u, x); + Yu1 = asymptotic_bessel_y_large_x_2(T(u + 1), x); + } + else + Yu = std::numeric_limits<T>::quiet_NaN(); // any value will do, we're not using it. + if(kind&need_j) + { + Jv = asymptotic_bessel_j_large_x_2(v, x); + } + else + Jv = std::numeric_limits<T>::quiet_NaN(); // any value will do, we're not using it. + } + else + { + CF1_jy(v, x, &fv, &s, pol); + // tiny initial value to prevent overflow + T init = sqrt(tools::min_value<T>()); + prev = fv * s * init; + current = s * init; + for (k = n; k > 0; k--) // backward recurrence for J + { + next = 2 * (u + k) * current / x - prev; + prev = current; + current = next; + } + T ratio = (s * init) / current; // scaling ratio + // can also call CF1_jy() to get fu, not much difference in precision + fu = prev / current; + CF2_jy(u, x, &p, &q, pol); // continued fraction CF2_jy + T t = u / x - fu; // t = J'/J + gamma = (p - t) / q; + Ju = sign(current) * sqrt(W / (q + gamma * (p - t))); + + Jv = Ju * ratio; // normalization + + Yu = gamma * Ju; + Yu1 = Yu * (u/x - p - q/gamma); + } + if(kind&need_y) + { + // compute Y: + prev = Yu; + current = Yu1; + for (k = 1; k <= n; k++) // forward recurrence for Y + { + next = 2 * (u + k) * current / x - prev; + prev = current; + current = next; + } + Yv = prev; + } + else + Yv = std::numeric_limits<T>::quiet_NaN(); // any value will do, we're not using it. + } + + if (reflect) + { + T z = (u + n % 2); + *J = boost::math::cos_pi(z, pol) * Jv - boost::math::sin_pi(z, pol) * Yv; // reflection formula + *Y = boost::math::sin_pi(z, pol) * Jv + boost::math::cos_pi(z, pol) * Yv; + } + else + { + *J = Jv; + *Y = Yv; + } + + return 0; +} + +} // namespace detail + +}} // namespaces + +#endif // BOOST_MATH_BESSEL_JY_HPP + diff --git a/Utilities/BGL/boost/math/special_functions/detail/bessel_jy_asym.hpp b/Utilities/BGL/boost/math/special_functions/detail/bessel_jy_asym.hpp new file mode 100644 index 0000000000000000000000000000000000000000..3d135e89c9e56b2449688970283dd30f62a680a5 --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/detail/bessel_jy_asym.hpp @@ -0,0 +1,302 @@ +// Copyright (c) 2007 John Maddock +// Use, modification and distribution are subject to 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) + +// +// This is a partial header, do not include on it's own!!! +// +// Contains asymptotic expansions for Bessel J(v,x) and Y(v,x) +// functions, as x -> INF. +// +#ifndef BOOST_MATH_SF_DETAIL_BESSEL_JY_ASYM_HPP +#define BOOST_MATH_SF_DETAIL_BESSEL_JY_ASYM_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/math/special_functions/factorials.hpp> + +namespace boost{ namespace math{ namespace detail{ + +template <class T> +inline T asymptotic_bessel_j_large_x_P(T v, T x) +{ + // A&S 9.2.9 + T s = 1; + T mu = 4 * v * v; + T ez2 = 8 * x; + ez2 *= ez2; + s -= (mu-1) * (mu-9) / (2 * ez2); + s += (mu-1) * (mu-9) * (mu-25) * (mu - 49) / (24 * ez2 * ez2); + return s; +} + +template <class T> +inline T asymptotic_bessel_j_large_x_Q(T v, T x) +{ + // A&S 9.2.10 + T s = 0; + T mu = 4 * v * v; + T ez = 8*x; + s += (mu-1) / ez; + s -= (mu-1) * (mu-9) * (mu-25) / (6 * ez*ez*ez); + return s; +} + +template <class T> +inline T asymptotic_bessel_j_large_x(T v, T x) +{ + // + // See http://functions.wolfram.com/BesselAiryStruveFunctions/BesselJ/06/02/02/0001/ + // + // Also A&S 9.2.5 + // + BOOST_MATH_STD_USING // ADL of std names + T chi = fabs(x) - constants::pi<T>() * (2 * v + 1) / 4; + return sqrt(2 / (constants::pi<T>() * x)) + * (asymptotic_bessel_j_large_x_P(v, x) * cos(chi) + - asymptotic_bessel_j_large_x_Q(v, x) * sin(chi)); +} + +template <class T> +inline T asymptotic_bessel_y_large_x(T v, T x) +{ + // + // See http://functions.wolfram.com/BesselAiryStruveFunctions/BesselJ/06/02/02/0001/ + // + // Also A&S 9.2.5 + // + BOOST_MATH_STD_USING // ADL of std names + T chi = fabs(x) - constants::pi<T>() * (2 * v + 1) / 4; + return sqrt(2 / (constants::pi<T>() * x)) + * (asymptotic_bessel_j_large_x_P(v, x) * sin(chi) + - asymptotic_bessel_j_large_x_Q(v, x) * cos(chi)); +} + +template <class T> +inline T asymptotic_bessel_amplitude(T v, T x) +{ + // Calculate the amplitude of J(v, x) and Y(v, x) for large + // x: see A&S 9.2.28. + BOOST_MATH_STD_USING + T s = 1; + T mu = 4 * v * v; + T txq = 2 * x; + txq *= txq; + + s += (mu - 1) / (2 * txq); + s += 3 * (mu - 1) * (mu - 9) / (txq * txq * 8); + s += 15 * (mu - 1) * (mu - 9) * (mu - 25) / (txq * txq * txq * 8 * 6); + + return sqrt(s * 2 / (constants::pi<T>() * x)); +} + +template <class T> +T asymptotic_bessel_phase_mx(T v, T x) +{ + // + // Calculate the phase of J(v, x) and Y(v, x) for large x. + // See A&S 9.2.29. + // Note that the result returned is the phase less x. + // + T mu = 4 * v * v; + T denom = 4 * x; + T denom_mult = denom * denom; + + T s = -constants::pi<T>() * (v / 2 + 0.25f); + s += (mu - 1) / (2 * denom); + denom *= denom_mult; + s += (mu - 1) * (mu - 25) / (6 * denom); + denom *= denom_mult; + s += (mu - 1) * (mu * mu - 114 * mu + 1073) / (5 * denom); + denom *= denom_mult; + s += (mu - 1) * (5 * mu * mu * mu - 1535 * mu * mu + 54703 * mu - 375733) / (14 * denom); + return s; +} + +template <class T> +inline T asymptotic_bessel_y_large_x_2(T v, T x) +{ + // See A&S 9.2.19. + BOOST_MATH_STD_USING + // Get the phase and amplitude: + T ampl = asymptotic_bessel_amplitude(v, x); + T phase = asymptotic_bessel_phase_mx(v, x); + // + // Calculate the sine of the phase, using: + // sin(x+p) = sin(x)cos(p) + cos(x)sin(p) + // + T sin_phase = sin(phase) * cos(x) + cos(phase) * sin(x); + return sin_phase * ampl; +} + +template <class T> +inline T asymptotic_bessel_j_large_x_2(T v, T x) +{ + // See A&S 9.2.19. + BOOST_MATH_STD_USING + // Get the phase and amplitude: + T ampl = asymptotic_bessel_amplitude(v, x); + T phase = asymptotic_bessel_phase_mx(v, x); + // + // Calculate the sine of the phase, using: + // cos(x+p) = cos(x)cos(p) - sin(x)sin(p) + // + T sin_phase = cos(phase) * cos(x) - sin(phase) * sin(x); + return sin_phase * ampl; +} + +// +// Various limits for the J and Y asymptotics +// (the asympotic expansions are safe to use if +// x is less than the limit given). +// We assume that if we don't use these expansions then the +// error will likely be >100eps, so the limits given are chosen +// to lead to < 100eps truncation error. +// +template <class T> +inline T asymptotic_bessel_y_limit(const mpl::int_<0>&) +{ + // default case: + BOOST_MATH_STD_USING + return 2.25 / pow(100 * tools::epsilon<T>() / T(0.001f), T(0.2f)); +} +template <class T> +inline T asymptotic_bessel_y_limit(const mpl::int_<53>&) +{ + // double case: + return 304 /*780*/; +} +template <class T> +inline T asymptotic_bessel_y_limit(const mpl::int_<64>&) +{ + // 80-bit extended-double case: + return 1552 /*3500*/; +} +template <class T> +inline T asymptotic_bessel_y_limit(const mpl::int_<113>&) +{ + // 128-bit long double case: + return 1245243 /*3128000*/; +} + +template <class T, class Policy> +struct bessel_asymptotic_tag +{ + typedef typename policies::precision<T, Policy>::type precision_type; + typedef typename mpl::if_< + mpl::or_< + mpl::equal_to<precision_type, mpl::int_<0> >, + mpl::greater<precision_type, mpl::int_<113> > >, + mpl::int_<0>, + typename mpl::if_< + mpl::greater<precision_type, mpl::int_<64> >, + mpl::int_<113>, + typename mpl::if_< + mpl::greater<precision_type, mpl::int_<53> >, + mpl::int_<64>, + mpl::int_<53> + >::type + >::type + >::type type; +}; + +template <class T> +inline T asymptotic_bessel_j_limit(const T& v, const mpl::int_<0>&) +{ + // default case: + BOOST_MATH_STD_USING + T v2 = (std::max)(T(3), T(v * v)); + return v2 / pow(100 * tools::epsilon<T>() / T(2e-5f), T(0.17f)); +} +template <class T> +inline T asymptotic_bessel_j_limit(const T& v, const mpl::int_<53>&) +{ + // double case: + T v2 = (std::max)(T(3), v * v); + return v2 * 33 /*73*/; +} +template <class T> +inline T asymptotic_bessel_j_limit(const T& v, const mpl::int_<64>&) +{ + // 80-bit extended-double case: + T v2 = (std::max)(T(3), v * v); + return v2 * 121 /*266*/; +} +template <class T> +inline T asymptotic_bessel_j_limit(const T& v, const mpl::int_<113>&) +{ + // 128-bit long double case: + T v2 = (std::max)(T(3), v * v); + return v2 * 39154 /*85700*/; +} + +template <class T, class Policy> +void temme_asyptotic_y_small_x(T v, T x, T* Y, T* Y1, const Policy& pol) +{ + T c = 1; + T p = (v / boost::math::sin_pi(v, pol)) * pow(x / 2, -v) / boost::math::tgamma(1 - v, pol); + T q = (v / boost::math::sin_pi(v, pol)) * pow(x / 2, v) / boost::math::tgamma(1 + v, pol); + T f = (p - q) / v; + T g_prefix = boost::math::sin_pi(v / 2, pol); + g_prefix *= g_prefix * 2 / v; + T g = f + g_prefix * q; + T h = p; + T c_mult = -x * x / 4; + + T y(c * g), y1(c * h); + + for(int k = 1; k < policies::get_max_series_iterations<Policy>(); ++k) + { + f = (k * f + p + q) / (k*k - v*v); + p /= k - v; + q /= k + v; + c *= c_mult / k; + T c1 = pow(-x * x / 4, k) / factorial<T>(k, pol); + g = f + g_prefix * q; + h = -k * g + p; + y += c * g; + y1 += c * h; + if(c * g / tools::epsilon<T>() < y) + break; + } + + *Y = -y; + *Y1 = (-2 / x) * y1; +} + +template <class T, class Policy> +T asymptotic_bessel_i_large_x(T v, T x, const Policy& pol) +{ + BOOST_MATH_STD_USING // ADL of std names + T s = 1; + T mu = 4 * v * v; + T ex = 8 * x; + T num = mu - 1; + T denom = ex; + + s -= num / denom; + + num *= mu - 9; + denom *= ex * 2; + s += num / denom; + + num *= mu - 25; + denom *= ex * 3; + s -= num / denom; + + // Try and avoid overflow to the last minute: + T e = exp(x/2); + + s = e * (e * s / sqrt(2 * x * constants::pi<T>())); + + return (boost::math::isfinite)(s) ? + s : policies::raise_overflow_error<T>("boost::math::asymptotic_bessel_i_large_x<%1%>(%1%,%1%)", 0, pol); +} + +}}} // namespaces + +#endif + diff --git a/Utilities/BGL/boost/math/special_functions/detail/bessel_k0.hpp b/Utilities/BGL/boost/math/special_functions/detail/bessel_k0.hpp new file mode 100644 index 0000000000000000000000000000000000000000..24833f96e7cface132214dde29e660f22abbefb0 --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/detail/bessel_k0.hpp @@ -0,0 +1,121 @@ +// Copyright (c) 2006 Xiaogang Zhang +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_BESSEL_K0_HPP +#define BOOST_MATH_BESSEL_K0_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/math/tools/rational.hpp> +#include <boost/math/policies/error_handling.hpp> +#include <boost/assert.hpp> + +// Modified Bessel function of the second kind of order zero +// minimax rational approximations on intervals, see +// Russon and Blair, Chalk River Report AECL-3461, 1969 + +namespace boost { namespace math { namespace detail{ + +template <typename T, typename Policy> +T bessel_k0(T x, const Policy& pol) +{ + BOOST_MATH_INSTRUMENT_CODE(x); + + static const T P1[] = { + static_cast<T>(2.4708152720399552679e+03L), + static_cast<T>(5.9169059852270512312e+03L), + static_cast<T>(4.6850901201934832188e+02L), + static_cast<T>(1.1999463724910714109e+01L), + static_cast<T>(1.3166052564989571850e-01L), + static_cast<T>(5.8599221412826100000e-04L) + }; + static const T Q1[] = { + static_cast<T>(2.1312714303849120380e+04L), + static_cast<T>(-2.4994418972832303646e+02L), + static_cast<T>(1.0L) + }; + static const T P2[] = { + static_cast<T>(-1.6128136304458193998e+06L), + static_cast<T>(-3.7333769444840079748e+05L), + static_cast<T>(-1.7984434409411765813e+04L), + static_cast<T>(-2.9501657892958843865e+02L), + static_cast<T>(-1.6414452837299064100e+00L) + }; + static const T Q2[] = { + static_cast<T>(-1.6128136304458193998e+06L), + static_cast<T>(2.9865713163054025489e+04L), + static_cast<T>(-2.5064972445877992730e+02L), + static_cast<T>(1.0L) + }; + static const T P3[] = { + static_cast<T>(1.1600249425076035558e+02L), + static_cast<T>(2.3444738764199315021e+03L), + static_cast<T>(1.8321525870183537725e+04L), + static_cast<T>(7.1557062783764037541e+04L), + static_cast<T>(1.5097646353289914539e+05L), + static_cast<T>(1.7398867902565686251e+05L), + static_cast<T>(1.0577068948034021957e+05L), + static_cast<T>(3.1075408980684392399e+04L), + static_cast<T>(3.6832589957340267940e+03L), + static_cast<T>(1.1394980557384778174e+02L) + }; + static const T Q3[] = { + static_cast<T>(9.2556599177304839811e+01L), + static_cast<T>(1.8821890840982713696e+03L), + static_cast<T>(1.4847228371802360957e+04L), + static_cast<T>(5.8824616785857027752e+04L), + static_cast<T>(1.2689839587977598727e+05L), + static_cast<T>(1.5144644673520157801e+05L), + static_cast<T>(9.7418829762268075784e+04L), + static_cast<T>(3.1474655750295278825e+04L), + static_cast<T>(4.4329628889746408858e+03L), + static_cast<T>(2.0013443064949242491e+02L), + static_cast<T>(1.0L) + }; + T value, factor, r, r1, r2; + + BOOST_MATH_STD_USING + using namespace boost::math::tools; + + static const char* function = "boost::math::bessel_k0<%1%>(%1%,%1%)"; + + if (x < 0) + { + return policies::raise_domain_error<T>(function, + "Got x = %1%, but argument x must be non-negative, complex number result not supported", x, pol); + } + if (x == 0) + { + return policies::raise_overflow_error<T>(function, 0, pol); + } + if (x <= 1) // x in (0, 1] + { + T y = x * x; + r1 = evaluate_polynomial(P1, y) / evaluate_polynomial(Q1, y); + r2 = evaluate_polynomial(P2, y) / evaluate_polynomial(Q2, y); + factor = log(x); + value = r1 - factor * r2; + } + else // x in (1, \infty) + { + T y = 1 / x; + r = evaluate_polynomial(P3, y) / evaluate_polynomial(Q3, y); + factor = exp(-x) / sqrt(x); + value = factor * r; + BOOST_MATH_INSTRUMENT_CODE("y = " << y); + BOOST_MATH_INSTRUMENT_CODE("r = " << r); + BOOST_MATH_INSTRUMENT_CODE("factor = " << factor); + BOOST_MATH_INSTRUMENT_CODE("value = " << value); + } + + return value; +} + +}}} // namespaces + +#endif // BOOST_MATH_BESSEL_K0_HPP + diff --git a/Utilities/BGL/boost/math/special_functions/detail/bessel_k1.hpp b/Utilities/BGL/boost/math/special_functions/detail/bessel_k1.hpp new file mode 100644 index 0000000000000000000000000000000000000000..5872e838d66da2e376b5d827c4519b7655ed2209 --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/detail/bessel_k1.hpp @@ -0,0 +1,117 @@ +// Copyright (c) 2006 Xiaogang Zhang +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_BESSEL_K1_HPP +#define BOOST_MATH_BESSEL_K1_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/math/tools/rational.hpp> +#include <boost/math/policies/error_handling.hpp> +#include <boost/assert.hpp> + +// Modified Bessel function of the second kind of order one +// minimax rational approximations on intervals, see +// Russon and Blair, Chalk River Report AECL-3461, 1969 + +namespace boost { namespace math { namespace detail{ + +template <typename T, typename Policy> +T bessel_k1(T x, const Policy& pol) +{ + static const T P1[] = { + static_cast<T>(-2.2149374878243304548e+06L), + static_cast<T>(7.1938920065420586101e+05L), + static_cast<T>(1.7733324035147015630e+05L), + static_cast<T>(7.1885382604084798576e+03L), + static_cast<T>(9.9991373567429309922e+01L), + static_cast<T>(4.8127070456878442310e-01L) + }; + static const T Q1[] = { + static_cast<T>(-2.2149374878243304548e+06L), + static_cast<T>(3.7264298672067697862e+04L), + static_cast<T>(-2.8143915754538725829e+02L), + static_cast<T>(1.0L) + }; + static const T P2[] = { + static_cast<T>(0.0L), + static_cast<T>(-1.3531161492785421328e+06L), + static_cast<T>(-1.4758069205414222471e+05L), + static_cast<T>(-4.5051623763436087023e+03L), + static_cast<T>(-5.3103913335180275253e+01L), + static_cast<T>(-2.2795590826955002390e-01L) + }; + static const T Q2[] = { + static_cast<T>(-2.7062322985570842656e+06L), + static_cast<T>(4.3117653211351080007e+04L), + static_cast<T>(-3.0507151578787595807e+02L), + static_cast<T>(1.0L) + }; + static const T P3[] = { + static_cast<T>(2.2196792496874548962e+00L), + static_cast<T>(4.4137176114230414036e+01L), + static_cast<T>(3.4122953486801312910e+02L), + static_cast<T>(1.3319486433183221990e+03L), + static_cast<T>(2.8590657697910288226e+03L), + static_cast<T>(3.4540675585544584407e+03L), + static_cast<T>(2.3123742209168871550e+03L), + static_cast<T>(8.1094256146537402173e+02L), + static_cast<T>(1.3182609918569941308e+02L), + static_cast<T>(7.5584584631176030810e+00L), + static_cast<T>(6.4257745859173138767e-02L) + }; + static const T Q3[] = { + static_cast<T>(1.7710478032601086579e+00L), + static_cast<T>(3.4552228452758912848e+01L), + static_cast<T>(2.5951223655579051357e+02L), + static_cast<T>(9.6929165726802648634e+02L), + static_cast<T>(1.9448440788918006154e+03L), + static_cast<T>(2.1181000487171943810e+03L), + static_cast<T>(1.2082692316002348638e+03L), + static_cast<T>(3.3031020088765390854e+02L), + static_cast<T>(3.6001069306861518855e+01L), + static_cast<T>(1.0L) + }; + T value, factor, r, r1, r2; + + BOOST_MATH_STD_USING + using namespace boost::math::tools; + + static const char* function = "boost::math::bessel_k1<%1%>(%1%,%1%)"; + + if (x < 0) + { + return policies::raise_domain_error<T>(function, + "Got x = %1%, but argument x must be non-negative, complex number result not supported.", x, pol); + } + if (x == 0) + { + return policies::raise_overflow_error<T>(function, 0, pol); + } + if (x <= 1) // x in (0, 1] + { + T y = x * x; + r1 = evaluate_polynomial(P1, y) / evaluate_polynomial(Q1, y); + r2 = evaluate_polynomial(P2, y) / evaluate_polynomial(Q2, y); + factor = log(x); + value = (r1 + factor * r2) / x; + } + else // x in (1, \infty) + { + T y = 1 / x; + r = evaluate_polynomial(P3, y) / evaluate_polynomial(Q3, y); + factor = exp(-x) / sqrt(x); + value = factor * r; + } + + return value; +} + +}}} // namespaces + +#endif // BOOST_MATH_BESSEL_K1_HPP + diff --git a/Utilities/BGL/boost/math/special_functions/detail/bessel_kn.hpp b/Utilities/BGL/boost/math/special_functions/detail/bessel_kn.hpp new file mode 100644 index 0000000000000000000000000000000000000000..841c8baa629ab78ed91286e39603ce7ca7117b67 --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/detail/bessel_kn.hpp @@ -0,0 +1,74 @@ +// Copyright (c) 2006 Xiaogang Zhang +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_BESSEL_KN_HPP +#define BOOST_MATH_BESSEL_KN_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/math/special_functions/detail/bessel_k0.hpp> +#include <boost/math/special_functions/detail/bessel_k1.hpp> +#include <boost/math/policies/error_handling.hpp> + +// Modified Bessel function of the second kind of integer order +// K_n(z) is the dominant solution, forward recurrence always OK (though unstable) + +namespace boost { namespace math { namespace detail{ + +template <typename T, typename Policy> +T bessel_kn(int n, T x, const Policy& pol) +{ + T value, current, prev; + + using namespace boost::math::tools; + + static const char* function = "boost::math::bessel_kn<%1%>(%1%,%1%)"; + + if (x < 0) + { + return policies::raise_domain_error<T>(function, + "Got x = %1%, but argument x must be non-negative, complex number result not supported.", x, pol); + } + if (x == 0) + { + return policies::raise_overflow_error<T>(function, 0, pol); + } + + if (n < 0) + { + n = -n; // K_{-n}(z) = K_n(z) + } + if (n == 0) + { + value = bessel_k0(x, pol); + } + else if (n == 1) + { + value = bessel_k1(x, pol); + } + else + { + prev = bessel_k0(x, pol); + current = bessel_k1(x, pol); + int k = 1; + BOOST_ASSERT(k < n); + do + { + value = 2 * k * current / x + prev; + prev = current; + current = value; + ++k; + } + while(k < n); + } + return value; +} + +}}} // namespaces + +#endif // BOOST_MATH_BESSEL_KN_HPP + diff --git a/Utilities/BGL/boost/math/special_functions/detail/bessel_y0.hpp b/Utilities/BGL/boost/math/special_functions/detail/bessel_y0.hpp new file mode 100644 index 0000000000000000000000000000000000000000..66100f1ce51d73654db9553211ca6cd309d486d8 --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/detail/bessel_y0.hpp @@ -0,0 +1,182 @@ +// Copyright (c) 2006 Xiaogang Zhang +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_BESSEL_Y0_HPP +#define BOOST_MATH_BESSEL_Y0_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/math/special_functions/detail/bessel_j0.hpp> +#include <boost/math/constants/constants.hpp> +#include <boost/math/tools/rational.hpp> +#include <boost/math/policies/error_handling.hpp> +#include <boost/assert.hpp> + +// Bessel function of the second kind of order zero +// x <= 8, minimax rational approximations on root-bracketing intervals +// x > 8, Hankel asymptotic expansion in Hart, Computer Approximations, 1968 + +namespace boost { namespace math { namespace detail{ + +template <typename T, typename Policy> +T bessel_y0(T x, const Policy& pol) +{ + static const T P1[] = { + static_cast<T>(1.0723538782003176831e+11L), + static_cast<T>(-8.3716255451260504098e+09L), + static_cast<T>(2.0422274357376619816e+08L), + static_cast<T>(-2.1287548474401797963e+06L), + static_cast<T>(1.0102532948020907590e+04L), + static_cast<T>(-1.8402381979244993524e+01L), + }; + static const T Q1[] = { + static_cast<T>(5.8873865738997033405e+11L), + static_cast<T>(8.1617187777290363573e+09L), + static_cast<T>(5.5662956624278251596e+07L), + static_cast<T>(2.3889393209447253406e+05L), + static_cast<T>(6.6475986689240190091e+02L), + static_cast<T>(1.0L), + }; + static const T P2[] = { + static_cast<T>(-2.2213976967566192242e+13L), + static_cast<T>(-5.5107435206722644429e+11L), + static_cast<T>(4.3600098638603061642e+10L), + static_cast<T>(-6.9590439394619619534e+08L), + static_cast<T>(4.6905288611678631510e+06L), + static_cast<T>(-1.4566865832663635920e+04L), + static_cast<T>(1.7427031242901594547e+01L), + }; + static const T Q2[] = { + static_cast<T>(4.3386146580707264428e+14L), + static_cast<T>(5.4266824419412347550e+12L), + static_cast<T>(3.4015103849971240096e+10L), + static_cast<T>(1.3960202770986831075e+08L), + static_cast<T>(4.0669982352539552018e+05L), + static_cast<T>(8.3030857612070288823e+02L), + static_cast<T>(1.0L), + }; + static const T P3[] = { + static_cast<T>(-8.0728726905150210443e+15L), + static_cast<T>(6.7016641869173237784e+14L), + static_cast<T>(-1.2829912364088687306e+11L), + static_cast<T>(-1.9363051266772083678e+11L), + static_cast<T>(2.1958827170518100757e+09L), + static_cast<T>(-1.0085539923498211426e+07L), + static_cast<T>(2.1363534169313901632e+04L), + static_cast<T>(-1.7439661319197499338e+01L), + }; + static const T Q3[] = { + static_cast<T>(3.4563724628846457519e+17L), + static_cast<T>(3.9272425569640309819e+15L), + static_cast<T>(2.2598377924042897629e+13L), + static_cast<T>(8.6926121104209825246e+10L), + static_cast<T>(2.4727219475672302327e+08L), + static_cast<T>(5.3924739209768057030e+05L), + static_cast<T>(8.7903362168128450017e+02L), + static_cast<T>(1.0L), + }; + static const T PC[] = { + static_cast<T>(2.2779090197304684302e+04L), + static_cast<T>(4.1345386639580765797e+04L), + static_cast<T>(2.1170523380864944322e+04L), + static_cast<T>(3.4806486443249270347e+03L), + static_cast<T>(1.5376201909008354296e+02L), + static_cast<T>(8.8961548424210455236e-01L), + }; + static const T QC[] = { + static_cast<T>(2.2779090197304684318e+04L), + static_cast<T>(4.1370412495510416640e+04L), + static_cast<T>(2.1215350561880115730e+04L), + static_cast<T>(3.5028735138235608207e+03L), + static_cast<T>(1.5711159858080893649e+02L), + static_cast<T>(1.0L), + }; + static const T PS[] = { + static_cast<T>(-8.9226600200800094098e+01L), + static_cast<T>(-1.8591953644342993800e+02L), + static_cast<T>(-1.1183429920482737611e+02L), + static_cast<T>(-2.2300261666214198472e+01L), + static_cast<T>(-1.2441026745835638459e+00L), + static_cast<T>(-8.8033303048680751817e-03L), + }; + static const T QS[] = { + static_cast<T>(5.7105024128512061905e+03L), + static_cast<T>(1.1951131543434613647e+04L), + static_cast<T>(7.2642780169211018836e+03L), + static_cast<T>(1.4887231232283756582e+03L), + static_cast<T>(9.0593769594993125859e+01L), + static_cast<T>(1.0L), + }; + static const T x1 = static_cast<T>(8.9357696627916752158e-01L), + x2 = static_cast<T>(3.9576784193148578684e+00L), + x3 = static_cast<T>(7.0860510603017726976e+00L), + x11 = static_cast<T>(2.280e+02L), + x12 = static_cast<T>(2.9519662791675215849e-03L), + x21 = static_cast<T>(1.0130e+03L), + x22 = static_cast<T>(6.4716931485786837568e-04L), + x31 = static_cast<T>(1.8140e+03L), + x32 = static_cast<T>(1.1356030177269762362e-04L) + ; + T value, factor, r, rc, rs; + + BOOST_MATH_STD_USING + using namespace boost::math::tools; + using namespace boost::math::constants; + + static const char* function = "boost::math::bessel_y0<%1%>(%1%,%1%)"; + + if (x < 0) + { + return policies::raise_domain_error<T>(function, + "Got x = %1% but x must be non-negative, complex result not supported.", x, pol); + } + if (x == 0) + { + return -policies::raise_overflow_error<T>(function, 0, pol); + } + if (x <= 3) // x in (0, 3] + { + T y = x * x; + T z = 2 * log(x/x1) * bessel_j0(x) / pi<T>(); + r = evaluate_rational(P1, Q1, y); + factor = (x + x1) * ((x - x11/256) - x12); + value = z + factor * r; + } + else if (x <= 5.5f) // x in (3, 5.5] + { + T y = x * x; + T z = 2 * log(x/x2) * bessel_j0(x) / pi<T>(); + r = evaluate_rational(P2, Q2, y); + factor = (x + x2) * ((x - x21/256) - x22); + value = z + factor * r; + } + else if (x <= 8) // x in (5.5, 8] + { + T y = x * x; + T z = 2 * log(x/x3) * bessel_j0(x) / pi<T>(); + r = evaluate_rational(P3, Q3, y); + factor = (x + x3) * ((x - x31/256) - x32); + value = z + factor * r; + } + else // x in (8, \infty) + { + T y = 8 / x; + T y2 = y * y; + T z = x - 0.25f * pi<T>(); + rc = evaluate_rational(PC, QC, y2); + rs = evaluate_rational(PS, QS, y2); + factor = sqrt(2 / (x * pi<T>())); + value = factor * (rc * sin(z) + y * rs * cos(z)); + } + + return value; +} + +}}} // namespaces + +#endif // BOOST_MATH_BESSEL_Y0_HPP + diff --git a/Utilities/BGL/boost/math/special_functions/detail/bessel_y1.hpp b/Utilities/BGL/boost/math/special_functions/detail/bessel_y1.hpp new file mode 100644 index 0000000000000000000000000000000000000000..309a58671d654d7734bedf67d3b46a53d1fac02e --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/detail/bessel_y1.hpp @@ -0,0 +1,155 @@ +// Copyright (c) 2006 Xiaogang Zhang +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_BESSEL_Y1_HPP +#define BOOST_MATH_BESSEL_Y1_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/math/special_functions/detail/bessel_j1.hpp> +#include <boost/math/constants/constants.hpp> +#include <boost/math/tools/rational.hpp> +#include <boost/math/policies/error_handling.hpp> +#include <boost/assert.hpp> + +// Bessel function of the second kind of order one +// x <= 8, minimax rational approximations on root-bracketing intervals +// x > 8, Hankel asymptotic expansion in Hart, Computer Approximations, 1968 + +namespace boost { namespace math { namespace detail{ + +template <typename T, typename Policy> +T bessel_y1(T x, const Policy& pol) +{ + static const T P1[] = { + static_cast<T>(4.0535726612579544093e+13L), + static_cast<T>(5.4708611716525426053e+12L), + static_cast<T>(-3.7595974497819597599e+11L), + static_cast<T>(7.2144548214502560419e+09L), + static_cast<T>(-5.9157479997408395984e+07L), + static_cast<T>(2.2157953222280260820e+05L), + static_cast<T>(-3.1714424660046133456e+02L), + }; + static const T Q1[] = { + static_cast<T>(3.0737873921079286084e+14L), + static_cast<T>(4.1272286200406461981e+12L), + static_cast<T>(2.7800352738690585613e+10L), + static_cast<T>(1.2250435122182963220e+08L), + static_cast<T>(3.8136470753052572164e+05L), + static_cast<T>(8.2079908168393867438e+02L), + static_cast<T>(1.0L), + }; + static const T P2[] = { + static_cast<T>(1.1514276357909013326e+19L), + static_cast<T>(-5.6808094574724204577e+18L), + static_cast<T>(-2.3638408497043134724e+16L), + static_cast<T>(4.0686275289804744814e+15L), + static_cast<T>(-5.9530713129741981618e+13L), + static_cast<T>(3.7453673962438488783e+11L), + static_cast<T>(-1.1957961912070617006e+09L), + static_cast<T>(1.9153806858264202986e+06L), + static_cast<T>(-1.2337180442012953128e+03L), + }; + static const T Q2[] = { + static_cast<T>(5.3321844313316185697e+20L), + static_cast<T>(5.6968198822857178911e+18L), + static_cast<T>(3.0837179548112881950e+16L), + static_cast<T>(1.1187010065856971027e+14L), + static_cast<T>(3.0221766852960403645e+11L), + static_cast<T>(6.3550318087088919566e+08L), + static_cast<T>(1.0453748201934079734e+06L), + static_cast<T>(1.2855164849321609336e+03L), + static_cast<T>(1.0L), + }; + static const T PC[] = { + static_cast<T>(-4.4357578167941278571e+06L), + static_cast<T>(-9.9422465050776411957e+06L), + static_cast<T>(-6.6033732483649391093e+06L), + static_cast<T>(-1.5235293511811373833e+06L), + static_cast<T>(-1.0982405543459346727e+05L), + static_cast<T>(-1.6116166443246101165e+03L), + static_cast<T>(0.0L), + }; + static const T QC[] = { + static_cast<T>(-4.4357578167941278568e+06L), + static_cast<T>(-9.9341243899345856590e+06L), + static_cast<T>(-6.5853394797230870728e+06L), + static_cast<T>(-1.5118095066341608816e+06L), + static_cast<T>(-1.0726385991103820119e+05L), + static_cast<T>(-1.4550094401904961825e+03L), + static_cast<T>(1.0L), + }; + static const T PS[] = { + static_cast<T>(3.3220913409857223519e+04L), + static_cast<T>(8.5145160675335701966e+04L), + static_cast<T>(6.6178836581270835179e+04L), + static_cast<T>(1.8494262873223866797e+04L), + static_cast<T>(1.7063754290207680021e+03L), + static_cast<T>(3.5265133846636032186e+01L), + static_cast<T>(0.0L), + }; + static const T QS[] = { + static_cast<T>(7.0871281941028743574e+05L), + static_cast<T>(1.8194580422439972989e+06L), + static_cast<T>(1.4194606696037208929e+06L), + static_cast<T>(4.0029443582266975117e+05L), + static_cast<T>(3.7890229745772202641e+04L), + static_cast<T>(8.6383677696049909675e+02L), + static_cast<T>(1.0L), + }; + static const T x1 = static_cast<T>(2.1971413260310170351e+00L), + x2 = static_cast<T>(5.4296810407941351328e+00L), + x11 = static_cast<T>(5.620e+02L), + x12 = static_cast<T>(1.8288260310170351490e-03L), + x21 = static_cast<T>(1.3900e+03L), + x22 = static_cast<T>(-6.4592058648672279948e-06L) + ; + T value, factor, r, rc, rs; + + BOOST_MATH_STD_USING + using namespace boost::math::tools; + using namespace boost::math::constants; + + if (x <= 0) + { + return policies::raise_domain_error<T>("bost::math::bessel_y1<%1%>(%1%,%1%)", + "Got x == %1%, but x must be > 0, complex result not supported.", x, pol); + } + if (x <= 4) // x in (0, 4] + { + T y = x * x; + T z = 2 * log(x/x1) * bessel_j1(x) / pi<T>(); + r = evaluate_rational(P1, Q1, y); + factor = (x + x1) * ((x - x11/256) - x12) / x; + value = z + factor * r; + } + else if (x <= 8) // x in (4, 8] + { + T y = x * x; + T z = 2 * log(x/x2) * bessel_j1(x) / pi<T>(); + r = evaluate_rational(P2, Q2, y); + factor = (x + x2) * ((x - x21/256) - x22) / x; + value = z + factor * r; + } + else // x in (8, \infty) + { + T y = 8 / x; + T y2 = y * y; + T z = x - 0.75f * pi<T>(); + rc = evaluate_rational(PC, QC, y2); + rs = evaluate_rational(PS, QS, y2); + factor = sqrt(2 / (x * pi<T>())); + value = factor * (rc * sin(z) + y * rs * cos(z)); + } + + return value; +} + +}}} // namespaces + +#endif // BOOST_MATH_BESSEL_Y1_HPP + diff --git a/Utilities/BGL/boost/math/special_functions/detail/bessel_yn.hpp b/Utilities/BGL/boost/math/special_functions/detail/bessel_yn.hpp new file mode 100644 index 0000000000000000000000000000000000000000..807a3834b75f957adda8ff23d55b39c6c93ef215 --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/detail/bessel_yn.hpp @@ -0,0 +1,84 @@ +// Copyright (c) 2006 Xiaogang Zhang +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_BESSEL_YN_HPP +#define BOOST_MATH_BESSEL_YN_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/math/special_functions/detail/bessel_y0.hpp> +#include <boost/math/special_functions/detail/bessel_y1.hpp> +#include <boost/math/policies/error_handling.hpp> + +// Bessel function of the second kind of integer order +// Y_n(z) is the dominant solution, forward recurrence always OK (though unstable) + +namespace boost { namespace math { namespace detail{ + +template <typename T, typename Policy> +T bessel_yn(int n, T x, const Policy& pol) +{ + T value, factor, current, prev; + + using namespace boost::math::tools; + + static const char* function = "boost::math::bessel_yn<%1%>(%1%,%1%)"; + + if ((x == 0) && (n == 0)) + { + return -policies::raise_overflow_error<T>(function, 0, pol); + } + if (x <= 0) + { + return policies::raise_domain_error<T>(function, + "Got x = %1%, but x must be > 0, complex result not supported.", x, pol); + } + + // + // Reflection comes first: + // + if (n < 0) + { + factor = (n & 0x1) ? -1 : 1; // Y_{-n}(z) = (-1)^n Y_n(z) + n = -n; + } + else + { + factor = 1; + } + + if (n == 0) + { + value = bessel_y0(x, pol); + } + else if (n == 1) + { + value = factor * bessel_y1(x, pol); + } + else + { + prev = bessel_y0(x, pol); + current = bessel_y1(x, pol); + int k = 1; + BOOST_ASSERT(k < n); + do + { + value = 2 * k * current / x - prev; + prev = current; + current = value; + ++k; + } + while(k < n); + value *= factor; + } + return value; +} + +}}} // namespaces + +#endif // BOOST_MATH_BESSEL_YN_HPP + diff --git a/Utilities/BGL/boost/math/special_functions/detail/erf_inv.hpp b/Utilities/BGL/boost/math/special_functions/detail/erf_inv.hpp new file mode 100644 index 0000000000000000000000000000000000000000..bb617d63360f9ea1ce8cbee31e6a943b90a34281 --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/detail/erf_inv.hpp @@ -0,0 +1,471 @@ +// (C) Copyright John Maddock 2006. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_SF_ERF_INV_HPP +#define BOOST_MATH_SF_ERF_INV_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +namespace boost{ namespace math{ + +namespace detail{ +// +// The inverse erf and erfc functions share a common implementation, +// this version is for 80-bit long double's and smaller: +// +template <class T, class Policy> +T erf_inv_imp(const T& p, const T& q, const Policy&, const boost::mpl::int_<64>*) +{ + BOOST_MATH_STD_USING // for ADL of std names. + + T result = 0; + + if(p <= 0.5) + { + // + // Evaluate inverse erf using the rational approximation: + // + // x = p(p+10)(Y+R(p)) + // + // Where Y is a constant, and R(p) is optimised for a low + // absolute error compared to |Y|. + // + // double: Max error found: 2.001849e-18 + // long double: Max error found: 1.017064e-20 + // Maximum Deviation Found (actual error term at infinite precision) 8.030e-21 + // + static const float Y = 0.0891314744949340820313f; + static const T P[] = { + -0.000508781949658280665617L, + -0.00836874819741736770379L, + 0.0334806625409744615033L, + -0.0126926147662974029034L, + -0.0365637971411762664006L, + 0.0219878681111168899165L, + 0.00822687874676915743155L, + -0.00538772965071242932965L + }; + static const T Q[] = { + 1, + -0.970005043303290640362L, + -1.56574558234175846809L, + 1.56221558398423026363L, + 0.662328840472002992063L, + -0.71228902341542847553L, + -0.0527396382340099713954L, + 0.0795283687341571680018L, + -0.00233393759374190016776L, + 0.000886216390456424707504L + }; + T g = p * (p + 10); + T r = tools::evaluate_polynomial(P, p) / tools::evaluate_polynomial(Q, p); + result = g * Y + g * r; + } + else if(q >= 0.25) + { + // + // Rational approximation for 0.5 > q >= 0.25 + // + // x = sqrt(-2*log(q)) / (Y + R(q)) + // + // Where Y is a constant, and R(q) is optimised for a low + // absolute error compared to Y. + // + // double : Max error found: 7.403372e-17 + // long double : Max error found: 6.084616e-20 + // Maximum Deviation Found (error term) 4.811e-20 + // + static const float Y = 2.249481201171875f; + static const T P[] = { + -0.202433508355938759655L, + 0.105264680699391713268L, + 8.37050328343119927838L, + 17.6447298408374015486L, + -18.8510648058714251895L, + -44.6382324441786960818L, + 17.445385985570866523L, + 21.1294655448340526258L, + -3.67192254707729348546L + }; + static const T Q[] = { + 1L, + 6.24264124854247537712L, + 3.9713437953343869095L, + -28.6608180499800029974L, + -20.1432634680485188801L, + 48.5609213108739935468L, + 10.8268667355460159008L, + -22.6436933413139721736L, + 1.72114765761200282724L + }; + T g = sqrt(-2 * log(q)); + T xs = q - 0.25; + T r = tools::evaluate_polynomial(P, xs) / tools::evaluate_polynomial(Q, xs); + result = g / (Y + r); + } + else + { + // + // For q < 0.25 we have a series of rational approximations all + // of the general form: + // + // let: x = sqrt(-log(q)) + // + // Then the result is given by: + // + // x(Y+R(x-B)) + // + // where Y is a constant, B is the lowest value of x for which + // the approximation is valid, and R(x-B) is optimised for a low + // absolute error compared to Y. + // + // Note that almost all code will really go through the first + // or maybe second approximation. After than we're dealing with very + // small input values indeed: 80 and 128 bit long double's go all the + // way down to ~ 1e-5000 so the "tail" is rather long... + // + T x = sqrt(-log(q)); + if(x < 3) + { + // Max error found: 1.089051e-20 + static const float Y = 0.807220458984375f; + static const T P[] = { + -0.131102781679951906451L, + -0.163794047193317060787L, + 0.117030156341995252019L, + 0.387079738972604337464L, + 0.337785538912035898924L, + 0.142869534408157156766L, + 0.0290157910005329060432L, + 0.00214558995388805277169L, + -0.679465575181126350155e-6L, + 0.285225331782217055858e-7L, + -0.681149956853776992068e-9L + }; + static const T Q[] = { + 1, + 3.46625407242567245975L, + 5.38168345707006855425L, + 4.77846592945843778382L, + 2.59301921623620271374L, + 0.848854343457902036425L, + 0.152264338295331783612L, + 0.01105924229346489121L + }; + T xs = x - 1.125; + T R = tools::evaluate_polynomial(P, xs) / tools::evaluate_polynomial(Q, xs); + result = Y * x + R * x; + } + else if(x < 6) + { + // Max error found: 8.389174e-21 + static const float Y = 0.93995571136474609375f; + static const T P[] = { + -0.0350353787183177984712L, + -0.00222426529213447927281L, + 0.0185573306514231072324L, + 0.00950804701325919603619L, + 0.00187123492819559223345L, + 0.000157544617424960554631L, + 0.460469890584317994083e-5L, + -0.230404776911882601748e-9L, + 0.266339227425782031962e-11L + }; + static const T Q[] = { + 1L, + 1.3653349817554063097L, + 0.762059164553623404043L, + 0.220091105764131249824L, + 0.0341589143670947727934L, + 0.00263861676657015992959L, + 0.764675292302794483503e-4L + }; + T xs = x - 3; + T R = tools::evaluate_polynomial(P, xs) / tools::evaluate_polynomial(Q, xs); + result = Y * x + R * x; + } + else if(x < 18) + { + // Max error found: 1.481312e-19 + static const float Y = 0.98362827301025390625f; + static const T P[] = { + -0.0167431005076633737133L, + -0.00112951438745580278863L, + 0.00105628862152492910091L, + 0.000209386317487588078668L, + 0.149624783758342370182e-4L, + 0.449696789927706453732e-6L, + 0.462596163522878599135e-8L, + -0.281128735628831791805e-13L, + 0.99055709973310326855e-16L + }; + static const T Q[] = { + 1L, + 0.591429344886417493481L, + 0.138151865749083321638L, + 0.0160746087093676504695L, + 0.000964011807005165528527L, + 0.275335474764726041141e-4L, + 0.282243172016108031869e-6L + }; + T xs = x - 6; + T R = tools::evaluate_polynomial(P, xs) / tools::evaluate_polynomial(Q, xs); + result = Y * x + R * x; + } + else if(x < 44) + { + // Max error found: 5.697761e-20 + static const float Y = 0.99714565277099609375f; + static const T P[] = { + -0.0024978212791898131227L, + -0.779190719229053954292e-5L, + 0.254723037413027451751e-4L, + 0.162397777342510920873e-5L, + 0.396341011304801168516e-7L, + 0.411632831190944208473e-9L, + 0.145596286718675035587e-11L, + -0.116765012397184275695e-17L + }; + static const T Q[] = { + 1L, + 0.207123112214422517181L, + 0.0169410838120975906478L, + 0.000690538265622684595676L, + 0.145007359818232637924e-4L, + 0.144437756628144157666e-6L, + 0.509761276599778486139e-9L + }; + T xs = x - 18; + T R = tools::evaluate_polynomial(P, xs) / tools::evaluate_polynomial(Q, xs); + result = Y * x + R * x; + } + else + { + // Max error found: 1.279746e-20 + static const float Y = 0.99941349029541015625f; + static const T P[] = { + -0.000539042911019078575891L, + -0.28398759004727721098e-6L, + 0.899465114892291446442e-6L, + 0.229345859265920864296e-7L, + 0.225561444863500149219e-9L, + 0.947846627503022684216e-12L, + 0.135880130108924861008e-14L, + -0.348890393399948882918e-21L + }; + static const T Q[] = { + 1L, + 0.0845746234001899436914L, + 0.00282092984726264681981L, + 0.468292921940894236786e-4L, + 0.399968812193862100054e-6L, + 0.161809290887904476097e-8L, + 0.231558608310259605225e-11L + }; + T xs = x - 44; + T R = tools::evaluate_polynomial(P, xs) / tools::evaluate_polynomial(Q, xs); + result = Y * x + R * x; + } + } + return result; +} + +template <class T, class Policy> +struct erf_roots +{ + std::tr1::tuple<T,T,T> operator()(const T& guess) + { + BOOST_MATH_STD_USING + T derivative = sign * (2 / sqrt(constants::pi<T>())) * exp(-(guess * guess)); + T derivative2 = -2 * guess * derivative; + return std::tr1::make_tuple(((sign > 0) ? boost::math::erf(guess, Policy()) : boost::math::erfc(guess, Policy())) - target, derivative, derivative2); + } + erf_roots(T z, int s) : target(z), sign(s) {} +private: + T target; + int sign; +}; + +template <class T, class Policy> +T erf_inv_imp(const T& p, const T& q, const Policy& pol, const boost::mpl::int_<0>*) +{ + // + // Generic version, get a guess that's accurate to 64-bits (10^-19) + // + T guess = erf_inv_imp(p, q, pol, static_cast<mpl::int_<64> const*>(0)); + T result; + // + // If T has more bit's than 64 in it's mantissa then we need to iterate, + // otherwise we can just return the result: + // + if(policies::digits<T, Policy>() > 64) + { + boost::uintmax_t max_iter = policies::get_max_root_iterations<Policy>(); + if(p <= 0.5) + { + result = tools::halley_iterate(detail::erf_roots<typename remove_cv<T>::type, Policy>(p, 1), guess, static_cast<T>(0), tools::max_value<T>(), (policies::digits<T, Policy>() * 2) / 3, max_iter); + } + else + { + result = tools::halley_iterate(detail::erf_roots<typename remove_cv<T>::type, Policy>(q, -1), guess, static_cast<T>(0), tools::max_value<T>(), (policies::digits<T, Policy>() * 2) / 3, max_iter); + } + policies::check_root_iterations("boost::math::erf_inv<%1%>", max_iter, pol); + } + else + { + result = guess; + } + return result; +} + +} // namespace detail + +template <class T, class Policy> +typename tools::promote_args<T>::type erfc_inv(T z, const Policy& pol) +{ + typedef typename tools::promote_args<T>::type result_type; + // + // Begin by testing for domain errors, and other special cases: + // + static const char* function = "boost::math::erfc_inv<%1%>(%1%, %1%)"; + if((z < 0) || (z > 2)) + policies::raise_domain_error<result_type>(function, "Argument outside range [0,2] in inverse erfc function (got p=%1%).", z, pol); + if(z == 0) + return policies::raise_overflow_error<result_type>(function, 0, pol); + if(z == 2) + return -policies::raise_overflow_error<result_type>(function, 0, pol); + // + // Normalise the input, so it's in the range [0,1], we will + // negate the result if z is outside that range. This is a simple + // application of the erfc reflection formula: erfc(-z) = 2 - erfc(z) + // + result_type p, q, s; + if(z > 1) + { + q = 2 - z; + p = 1 - q; + s = -1; + } + else + { + p = 1 - z; + q = z; + s = 1; + } + // + // A bit of meta-programming to figure out which implementation + // to use, based on the number of bits in the mantissa of T: + // + typedef typename policies::precision<result_type, Policy>::type precision_type; + typedef typename mpl::if_< + mpl::or_<mpl::less_equal<precision_type, mpl::int_<0> >, mpl::greater<precision_type, mpl::int_<64> > >, + mpl::int_<0>, + mpl::int_<64> + >::type tag_type; + // + // Likewise use internal promotion, so we evaluate at a higher + // precision internally if it's appropriate: + // + typedef typename policies::evaluation<result_type, Policy>::type eval_type; + typedef typename policies::normalise< + Policy, + policies::promote_float<false>, + policies::promote_double<false>, + policies::discrete_quantile<>, + policies::assert_undefined<> >::type forwarding_policy; + + // + // And get the result, negating where required: + // + return s * policies::checked_narrowing_cast<result_type, forwarding_policy>( + detail::erf_inv_imp(static_cast<eval_type>(p), static_cast<eval_type>(q), forwarding_policy(), static_cast<tag_type const*>(0)), function); +} + +template <class T, class Policy> +typename tools::promote_args<T>::type erf_inv(T z, const Policy& pol) +{ + typedef typename tools::promote_args<T>::type result_type; + // + // Begin by testing for domain errors, and other special cases: + // + static const char* function = "boost::math::erf_inv<%1%>(%1%, %1%)"; + if((z < -1) || (z > 1)) + policies::raise_domain_error<result_type>(function, "Argument outside range [-1, 1] in inverse erf function (got p=%1%).", z, pol); + if(z == 1) + return policies::raise_overflow_error<result_type>(function, 0, pol); + if(z == -1) + return -policies::raise_overflow_error<result_type>(function, 0, pol); + if(z == 0) + return 0; + // + // Normalise the input, so it's in the range [0,1], we will + // negate the result if z is outside that range. This is a simple + // application of the erf reflection formula: erf(-z) = -erf(z) + // + result_type p, q, s; + if(z < 0) + { + p = -z; + q = 1 - p; + s = -1; + } + else + { + p = z; + q = 1 - z; + s = 1; + } + // + // A bit of meta-programming to figure out which implementation + // to use, based on the number of bits in the mantissa of T: + // + typedef typename policies::precision<result_type, Policy>::type precision_type; + typedef typename mpl::if_< + mpl::or_<mpl::less_equal<precision_type, mpl::int_<0> >, mpl::greater<precision_type, mpl::int_<64> > >, + mpl::int_<0>, + mpl::int_<64> + >::type tag_type; + // + // Likewise use internal promotion, so we evaluate at a higher + // precision internally if it's appropriate: + // + typedef typename policies::evaluation<result_type, Policy>::type eval_type; + typedef typename policies::normalise< + Policy, + policies::promote_float<false>, + policies::promote_double<false>, + policies::discrete_quantile<>, + policies::assert_undefined<> >::type forwarding_policy; + // + // Likewise use internal promotion, so we evaluate at a higher + // precision internally if it's appropriate: + // + typedef typename policies::evaluation<result_type, Policy>::type eval_type; + // + // And get the result, negating where required: + // + return s * policies::checked_narrowing_cast<result_type, forwarding_policy>( + detail::erf_inv_imp(static_cast<eval_type>(p), static_cast<eval_type>(q), forwarding_policy(), static_cast<tag_type const*>(0)), function); +} + +template <class T> +inline typename tools::promote_args<T>::type erfc_inv(T z) +{ + return erfc_inv(z, policies::policy<>()); +} + +template <class T> +inline typename tools::promote_args<T>::type erf_inv(T z) +{ + return erf_inv(z, policies::policy<>()); +} + +} // namespace math +} // namespace boost + +#endif // BOOST_MATH_SF_ERF_INV_HPP + diff --git a/Utilities/BGL/boost/math/special_functions/detail/fp_traits.hpp b/Utilities/BGL/boost/math/special_functions/detail/fp_traits.hpp new file mode 100644 index 0000000000000000000000000000000000000000..48313babc817994c6dac65d21ec3f4e22cf900c0 --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/detail/fp_traits.hpp @@ -0,0 +1,568 @@ +// fp_traits.hpp + +#ifndef BOOST_MATH_FP_TRAITS_HPP +#define BOOST_MATH_FP_TRAITS_HPP + +// Copyright (c) 2006 Johan Rade + +// 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) + +/* +To support old compilers, care has been taken to avoid partial template +specialization and meta function forwarding. +With these techniques, the code could be simplified. +*/ + +#if defined(__vms) && defined(__DECCXX) && !__IEEE_FLOAT +// The VAX floating point formats are used (for float and double) +# define BOOST_FPCLASSIFY_VAX_FORMAT +#endif + +#include <cstring> + +#include <boost/assert.hpp> +#include <boost/cstdint.hpp> +#include <boost/detail/endian.hpp> +#include <boost/static_assert.hpp> +#include <boost/type_traits/is_floating_point.hpp> + +#ifdef BOOST_NO_STDC_NAMESPACE + namespace std{ using ::memcpy; } +#endif + +#ifndef FP_NORMAL + +#define FP_ZERO 0 +#define FP_NORMAL 1 +#define FP_INFINITE 2 +#define FP_NAN 3 +#define FP_SUBNORMAL 4 + +#else + +#define BOOST_HAS_FPCLASSIFY + +#ifndef fpclassify +# if (defined(__GLIBCPP__) || defined(__GLIBCXX__)) \ + && defined(_GLIBCXX_USE_C99_MATH) \ + && !(defined(_GLIBCXX_USE_C99_FP_MACROS_DYNAMIC) \ + && (_GLIBCXX_USE_C99_FP_MACROS_DYNAMIC != 0)) +# ifdef _STLP_VENDOR_CSTD +# if _STLPORT_VERSION >= 0x520 +# define BOOST_FPCLASSIFY_PREFIX ::__std_alias:: +# else +# define BOOST_FPCLASSIFY_PREFIX ::_STLP_VENDOR_CSTD:: +# endif +# else +# define BOOST_FPCLASSIFY_PREFIX ::std:: +# endif +# else +# undef BOOST_HAS_FPCLASSIFY +# define BOOST_FPCLASSIFY_PREFIX +# endif +#elif (defined(__HP_aCC) && !defined(__hppa)) +// aCC 6 appears to do "#define fpclassify fpclassify" which messes us up a bit! +# define BOOST_FPCLASSIFY_PREFIX :: +#else +# define BOOST_FPCLASSIFY_PREFIX +#endif + +#ifdef __MINGW32__ +# undef BOOST_HAS_FPCLASSIFY +#endif + +#endif + + +//------------------------------------------------------------------------------ + +namespace boost { +namespace math { +namespace detail { + +//------------------------------------------------------------------------------ + +/* +The following classes are used to tag the different methods that are used +for floating point classification +*/ + +struct native_tag {}; +template <bool has_limits> +struct generic_tag {}; +struct ieee_tag {}; +struct ieee_copy_all_bits_tag : public ieee_tag {}; +struct ieee_copy_leading_bits_tag : public ieee_tag {}; + +#ifdef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS +// +// These helper functions are used only when numeric_limits<> +// members are not compile time constants: +// +inline bool is_generic_tag_false(const generic_tag<false>&) +{ + return true; +} +inline bool is_generic_tag_false(...) +{ + return false; +} +#endif + +//------------------------------------------------------------------------------ + +/* +Most processors support three different floating point precisions: +single precision (32 bits), double precision (64 bits) +and extended double precision (80 - 128 bits, depending on the processor) + +Note that the C++ type long double can be implemented +both as double precision and extended double precision. +*/ + +struct unknown_precision{}; +struct single_precision {}; +struct double_precision {}; +struct extended_double_precision {}; + +// native_tag version -------------------------------------------------------------- + +template<class T> struct fp_traits_native +{ + typedef native_tag method; +}; + +// generic_tag version ------------------------------------------------------------- + +template<class T, class U> struct fp_traits_non_native +{ +#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS + typedef generic_tag<std::numeric_limits<T>::is_specialized> method; +#else + typedef generic_tag<false> method; +#endif +}; + +// ieee_tag versions --------------------------------------------------------------- + +/* +These specializations of fp_traits_non_native contain information needed +to "parse" the binary representation of a floating point number. + +Typedef members: + + bits -- the target type when copying the leading bytes of a floating + point number. It is a typedef for uint32_t or uint64_t. + + method -- tells us whether all bytes are copied or not. + It is a typedef for ieee_copy_all_bits_tag or ieee_copy_leading_bits_tag. + +Static data members: + + sign, exponent, flag, significand -- bit masks that give the meaning of the + bits in the leading bytes. + +Static function members: + + get_bits(), set_bits() -- provide access to the leading bytes. + +*/ + +// ieee_tag version, float (32 bits) ----------------------------------------------- + +#ifndef BOOST_FPCLASSIFY_VAX_FORMAT + +template<> struct fp_traits_non_native<float, single_precision> +{ + typedef ieee_copy_all_bits_tag method; + + BOOST_STATIC_CONSTANT(uint32_t, sign = 0x80000000u); + BOOST_STATIC_CONSTANT(uint32_t, exponent = 0x7f800000); + BOOST_STATIC_CONSTANT(uint32_t, flag = 0x00000000); + BOOST_STATIC_CONSTANT(uint32_t, significand = 0x007fffff); + + typedef uint32_t bits; + static void get_bits(float x, uint32_t& a) { std::memcpy(&a, &x, 4); } + static void set_bits(float& x, uint32_t a) { std::memcpy(&x, &a, 4); } +}; + +// ieee_tag version, double (64 bits) ---------------------------------------------- + +#if defined(BOOST_NO_INT64_T) || defined(BOOST_NO_INCLASS_MEMBER_INITIALIZATION) \ + || defined(__BORLANDC__) || defined(__CODEGEAR__) + +template<> struct fp_traits_non_native<double, double_precision> +{ + typedef ieee_copy_leading_bits_tag method; + + BOOST_STATIC_CONSTANT(uint32_t, sign = 0x80000000u); + BOOST_STATIC_CONSTANT(uint32_t, exponent = 0x7ff00000); + BOOST_STATIC_CONSTANT(uint32_t, flag = 0); + BOOST_STATIC_CONSTANT(uint32_t, significand = 0x000fffff); + + typedef uint32_t bits; + + static void get_bits(double x, uint32_t& a) + { + std::memcpy(&a, reinterpret_cast<const unsigned char*>(&x) + offset_, 4); + } + + static void set_bits(double& x, uint32_t a) + { + std::memcpy(reinterpret_cast<unsigned char*>(&x) + offset_, &a, 4); + } + +private: + +#if defined(BOOST_BIG_ENDIAN) + BOOST_STATIC_CONSTANT(int, offset_ = 0); +#elif defined(BOOST_LITTLE_ENDIAN) + BOOST_STATIC_CONSTANT(int, offset_ = 4); +#else + BOOST_STATIC_ASSERT(false); +#endif +}; + +//.............................................................................. + +#else + +template<> struct fp_traits_non_native<double, double_precision> +{ + typedef ieee_copy_all_bits_tag method; + + static const uint64_t sign = ((uint64_t)0x80000000u) << 32; + static const uint64_t exponent = ((uint64_t)0x7ff00000) << 32; + static const uint64_t flag = 0; + static const uint64_t significand + = (((uint64_t)0x000fffff) << 32) + ((uint64_t)0xffffffffu); + + typedef uint64_t bits; + static void get_bits(double x, uint64_t& a) { std::memcpy(&a, &x, 8); } + static void set_bits(double& x, uint64_t a) { std::memcpy(&x, &a, 8); } +}; + +#endif + +#endif // #ifndef BOOST_FPCLASSIFY_VAX_FORMAT + +// long double (64 bits) ------------------------------------------------------- + +#if defined(BOOST_NO_INT64_T) || defined(BOOST_NO_INCLASS_MEMBER_INITIALIZATION)\ + || defined(__BORLANDC__) || defined(__CODEGEAR__) + +template<> struct fp_traits_non_native<long double, double_precision> +{ + typedef ieee_copy_leading_bits_tag method; + + BOOST_STATIC_CONSTANT(uint32_t, sign = 0x80000000u); + BOOST_STATIC_CONSTANT(uint32_t, exponent = 0x7ff00000); + BOOST_STATIC_CONSTANT(uint32_t, flag = 0); + BOOST_STATIC_CONSTANT(uint32_t, significand = 0x000fffff); + + typedef uint32_t bits; + + static void get_bits(long double x, uint32_t& a) + { + std::memcpy(&a, reinterpret_cast<const unsigned char*>(&x) + offset_, 4); + } + + static void set_bits(long double& x, uint32_t a) + { + std::memcpy(reinterpret_cast<unsigned char*>(&x) + offset_, &a, 4); + } + +private: + +#if defined(BOOST_BIG_ENDIAN) + BOOST_STATIC_CONSTANT(int, offset_ = 0); +#elif defined(BOOST_LITTLE_ENDIAN) + BOOST_STATIC_CONSTANT(int, offset_ = 4); +#else + BOOST_STATIC_ASSERT(false); +#endif +}; + +//.............................................................................. + +#else + +template<> struct fp_traits_non_native<long double, double_precision> +{ + typedef ieee_copy_all_bits_tag method; + + static const uint64_t sign = (uint64_t)0x80000000u << 32; + static const uint64_t exponent = (uint64_t)0x7ff00000 << 32; + static const uint64_t flag = 0; + static const uint64_t significand + = ((uint64_t)0x000fffff << 32) + (uint64_t)0xffffffffu; + + typedef uint64_t bits; + static void get_bits(long double x, uint64_t& a) { std::memcpy(&a, &x, 8); } + static void set_bits(long double& x, uint64_t a) { std::memcpy(&x, &a, 8); } +}; + +#endif + + +// long double (>64 bits), x86 and x64 ----------------------------------------- + +#if defined(__i386) || defined(__i386__) || defined(_M_IX86) \ + || defined(__amd64) || defined(__amd64__) || defined(_M_AMD64) \ + || defined(__x86_64) || defined(__x86_64__) || defined(_M_X64) + +// Intel extended double precision format (80 bits) + +template<> +struct fp_traits_non_native<long double, extended_double_precision> +{ + typedef ieee_copy_leading_bits_tag method; + + BOOST_STATIC_CONSTANT(uint32_t, sign = 0x80000000u); + BOOST_STATIC_CONSTANT(uint32_t, exponent = 0x7fff0000); + BOOST_STATIC_CONSTANT(uint32_t, flag = 0x00008000); + BOOST_STATIC_CONSTANT(uint32_t, significand = 0x00007fff); + + typedef uint32_t bits; + + static void get_bits(long double x, uint32_t& a) + { + std::memcpy(&a, reinterpret_cast<const unsigned char*>(&x) + 6, 4); + } + + static void set_bits(long double& x, uint32_t a) + { + std::memcpy(reinterpret_cast<unsigned char*>(&x) + 6, &a, 4); + } +}; + + +// long double (>64 bits), Itanium --------------------------------------------- + +#elif defined(__ia64) || defined(__ia64__) || defined(_M_IA64) + +// The floating point format is unknown at compile time +// No template specialization is provided. +// The generic_tag definition is used. + +// The Itanium supports both +// the Intel extended double precision format (80 bits) and +// the IEEE extended double precision format with 15 exponent bits (128 bits). + + +// long double (>64 bits), PowerPC --------------------------------------------- + +#elif defined(__powerpc) || defined(__powerpc__) || defined(__POWERPC__) \ + || defined(__ppc) || defined(__ppc__) || defined(__PPC__) + +// PowerPC extended double precision format (128 bits) + +template<> +struct fp_traits_non_native<long double, extended_double_precision> +{ + typedef ieee_copy_leading_bits_tag method; + + BOOST_STATIC_CONSTANT(uint32_t, sign = 0x80000000u); + BOOST_STATIC_CONSTANT(uint32_t, exponent = 0x7ff00000); + BOOST_STATIC_CONSTANT(uint32_t, flag = 0x00000000); + BOOST_STATIC_CONSTANT(uint32_t, significand = 0x000fffff); + + typedef uint32_t bits; + + static void get_bits(long double x, uint32_t& a) + { + std::memcpy(&a, reinterpret_cast<const unsigned char*>(&x) + offset_, 4); + } + + static void set_bits(long double& x, uint32_t a) + { + std::memcpy(reinterpret_cast<unsigned char*>(&x) + offset_, &a, 4); + } + +private: + +#if defined(BOOST_BIG_ENDIAN) + BOOST_STATIC_CONSTANT(int, offset_ = 0); +#elif defined(BOOST_LITTLE_ENDIAN) + BOOST_STATIC_CONSTANT(int, offset_ = 12); +#else + BOOST_STATIC_ASSERT(false); +#endif +}; + + +// long double (>64 bits), Motorola 68K ---------------------------------------- + +#elif defined(__m68k) || defined(__m68k__) \ + || defined(__mc68000) || defined(__mc68000__) \ + +// Motorola extended double precision format (96 bits) + +// It is the same format as the Intel extended double precision format, +// except that 1) it is big-endian, 2) the 3rd and 4th byte are padding, and +// 3) the flag bit is not set for infinity + +template<> +struct fp_traits_non_native<long double, extended_double_precision> +{ + typedef ieee_copy_leading_bits_tag method; + + BOOST_STATIC_CONSTANT(uint32_t, sign = 0x80000000u); + BOOST_STATIC_CONSTANT(uint32_t, exponent = 0x7fff0000); + BOOST_STATIC_CONSTANT(uint32_t, flag = 0x00008000); + BOOST_STATIC_CONSTANT(uint32_t, significand = 0x00007fff); + + // copy 1st, 2nd, 5th and 6th byte. 3rd and 4th byte are padding. + + typedef uint32_t bits; + + static void get_bits(long double x, uint32_t& a) + { + std::memcpy(&a, &x, 2); + std::memcpy(reinterpret_cast<unsigned char*>(&a) + 2, + reinterpret_cast<const unsigned char*>(&x) + 4, 2); + } + + static void set_bits(long double& x, uint32_t a) + { + std::memcpy(&x, &a, 2); + std::memcpy(reinterpret_cast<unsigned char*>(&x) + 4, + reinterpret_cast<const unsigned char*>(&a) + 2, 2); + } +}; + + +// long double (>64 bits), All other processors -------------------------------- + +#else + +// IEEE extended double precision format with 15 exponent bits (128 bits) + +template<> +struct fp_traits_non_native<long double, extended_double_precision> +{ + typedef ieee_copy_leading_bits_tag method; + + BOOST_STATIC_CONSTANT(uint32_t, sign = 0x80000000u); + BOOST_STATIC_CONSTANT(uint32_t, exponent = 0x7fff0000); + BOOST_STATIC_CONSTANT(uint32_t, flag = 0x00000000); + BOOST_STATIC_CONSTANT(uint32_t, significand = 0x0000ffff); + + typedef uint32_t bits; + + static void get_bits(long double x, uint32_t& a) + { + std::memcpy(&a, reinterpret_cast<const unsigned char*>(&x) + offset_, 4); + } + + static void set_bits(long double& x, uint32_t a) + { + std::memcpy(reinterpret_cast<unsigned char*>(&x) + offset_, &a, 4); + } + +private: + +#if defined(BOOST_BIG_ENDIAN) + BOOST_STATIC_CONSTANT(int, offset_ = 0); +#elif defined(BOOST_LITTLE_ENDIAN) + BOOST_STATIC_CONSTANT(int, offset_ = 12); +#else + BOOST_STATIC_ASSERT(false); +#endif +}; + +#endif + +//------------------------------------------------------------------------------ + +// size_to_precision is a type switch for converting a C++ floating point type +// to the corresponding precision type. + +template<int n, bool fp> struct size_to_precision +{ + typedef unknown_precision type; +}; + +template<> struct size_to_precision<4, true> +{ + typedef single_precision type; +}; + +template<> struct size_to_precision<8, true> +{ + typedef double_precision type; +}; + +template<> struct size_to_precision<10, true> +{ + typedef extended_double_precision type; +}; + +template<> struct size_to_precision<12, true> +{ + typedef extended_double_precision type; +}; + +template<> struct size_to_precision<16, true> +{ + typedef extended_double_precision type; +}; + +//------------------------------------------------------------------------------ +// +// Figure out whether to use native classification functions based on +// whether T is a built in floating point type or not: +// +template <class T> +struct select_native +{ + typedef BOOST_DEDUCED_TYPENAME size_to_precision<sizeof(T), ::boost::is_floating_point<T>::value>::type precision; + typedef fp_traits_non_native<T, precision> type; +}; +template<> +struct select_native<float> +{ + typedef fp_traits_native<float> type; +}; +template<> +struct select_native<double> +{ + typedef fp_traits_native<double> type; +}; +template<> +struct select_native<long double> +{ + typedef fp_traits_native<long double> type; +}; + +//------------------------------------------------------------------------------ + +// fp_traits is a type switch that selects the right fp_traits_non_native + +#if (defined(BOOST_MATH_USE_C99) && !(defined(__GNUC__) && (__GNUC__ < 4))) \ + && !defined(__hpux) \ + && !defined(__DECCXX)\ + && !defined(__osf__) \ + && !defined(__SGI_STL_PORT) && !defined(_STLPORT_VERSION) +# define BOOST_MATH_USE_STD_FPCLASSIFY +#endif + +template<class T> struct fp_traits +{ +#if defined(BOOST_MATH_USE_STD_FPCLASSIFY) && !defined(BOOST_MATH_DISABLE_STD_FPCLASSIFY) + typedef typename select_native<T>::type type; +#else + typedef BOOST_DEDUCED_TYPENAME size_to_precision<sizeof(T), ::boost::is_floating_point<T>::value>::type precision; + typedef fp_traits_non_native<T, precision> type; +#endif +}; + +//------------------------------------------------------------------------------ + +} // namespace detail +} // namespace math +} // namespace boost + +#endif diff --git a/Utilities/BGL/boost/math/special_functions/detail/gamma_inva.hpp b/Utilities/BGL/boost/math/special_functions/detail/gamma_inva.hpp new file mode 100644 index 0000000000000000000000000000000000000000..d07639f29ce94c8106bc1efb76ea0b3664d898b8 --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/detail/gamma_inva.hpp @@ -0,0 +1,233 @@ +// (C) Copyright John Maddock 2006. +// Use, modification and distribution are subject to 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) + +// +// This is not a complete header file, it is included by gamma.hpp +// after it has defined it's definitions. This inverts the incomplete +// gamma functions P and Q on the first parameter "a" using a generic +// root finding algorithm (TOMS Algorithm 748). +// + +#ifndef BOOST_MATH_SP_DETAIL_GAMMA_INVA +#define BOOST_MATH_SP_DETAIL_GAMMA_INVA + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/math/tools/toms748_solve.hpp> +#include <boost/cstdint.hpp> + +namespace boost{ namespace math{ namespace detail{ + +template <class T, class Policy> +struct gamma_inva_t +{ + gamma_inva_t(T z_, T p_, bool invert_) : z(z_), p(p_), invert(invert_) {} + T operator()(T a) + { + return invert ? p - boost::math::gamma_q(a, z, Policy()) : boost::math::gamma_p(a, z, Policy()) - p; + } +private: + T z, p; + bool invert; +}; + +template <class T, class Policy> +T inverse_poisson_cornish_fisher(T lambda, T p, T q, const Policy& pol) +{ + BOOST_MATH_STD_USING + // mean: + T m = lambda; + // standard deviation: + T sigma = sqrt(lambda); + // skewness + T sk = 1 / sigma; + // kurtosis: + // T k = 1/lambda; + // Get the inverse of a std normal distribution: + T x = boost::math::erfc_inv(p > q ? 2 * q : 2 * p, pol) * constants::root_two<T>(); + // Set the sign: + if(p < 0.5) + x = -x; + T x2 = x * x; + // w is correction term due to skewness + T w = x + sk * (x2 - 1) / 6; + /* + // Add on correction due to kurtosis. + // Disabled for now, seems to make things worse? + // + if(lambda >= 10) + w += k * x * (x2 - 3) / 24 + sk * sk * x * (2 * x2 - 5) / -36; + */ + w = m + sigma * w; + return w > tools::min_value<T>() ? w : tools::min_value<T>(); +} + +template <class T, class Policy> +T gamma_inva_imp(const T& z, const T& p, const T& q, const Policy& pol) +{ + BOOST_MATH_STD_USING // for ADL of std lib math functions + // + // Special cases first: + // + if(p == 0) + { + return tools::max_value<T>(); + } + if(q == 0) + { + return tools::min_value<T>(); + } + // + // Function object, this is the functor whose root + // we have to solve: + // + gamma_inva_t<T, Policy> f(z, (p < q) ? p : q, (p < q) ? false : true); + // + // Tolerance: full precision. + // + tools::eps_tolerance<T> tol(policies::digits<T, Policy>()); + // + // Now figure out a starting guess for what a may be, + // we'll start out with a value that'll put p or q + // right bang in the middle of their range, the functions + // are quite sensitive so we should need too many steps + // to bracket the root from there: + // + T guess; + T factor = 8; + if(z >= 1) + { + // + // We can use the relationship between the incomplete + // gamma function and the poisson distribution to + // calculate an approximate inverse, for large z + // this is actually pretty accurate, but it fails badly + // when z is very small. Also set our step-factor according + // to how accurate we think the result is likely to be: + // + guess = 1 + inverse_poisson_cornish_fisher(z, q, p, pol); + if(z > 5) + { + if(z > 1000) + factor = 1.01f; + else if(z > 50) + factor = 1.1f; + else if(guess > 10) + factor = 1.25f; + else + factor = 2; + if(guess < 1.1) + factor = 8; + } + } + else if(z > 0.5) + { + guess = z * 1.2f; + } + else + { + guess = -0.4f / log(z); + } + // + // Max iterations permitted: + // + boost::uintmax_t max_iter = policies::get_max_root_iterations<Policy>(); + // + // Use our generic derivative-free root finding procedure. + // We could use Newton steps here, taking the PDF of the + // Poisson distribution as our derivative, but that's + // even worse performance-wise than the generic method :-( + // + std::pair<T, T> r = bracket_and_solve_root(f, guess, factor, false, tol, max_iter, pol); + if(max_iter >= policies::get_max_root_iterations<Policy>()) + policies::raise_evaluation_error<T>("boost::math::gamma_p_inva<%1%>(%1%, %1%)", "Unable to locate the root within a reasonable number of iterations, closest approximation so far was %1%", r.first, pol); + return (r.first + r.second) / 2; +} + +} // namespace detail + +template <class T1, class T2, class Policy> +inline typename tools::promote_args<T1, T2>::type + gamma_p_inva(T1 x, T2 p, const Policy& pol) +{ + typedef typename tools::promote_args<T1, T2>::type result_type; + typedef typename policies::evaluation<result_type, Policy>::type value_type; + typedef typename policies::normalise< + Policy, + policies::promote_float<false>, + policies::promote_double<false>, + policies::discrete_quantile<>, + policies::assert_undefined<> >::type forwarding_policy; + + if(p == 0) + { + return tools::max_value<result_type>(); + } + if(p == 1) + { + return tools::min_value<result_type>(); + } + + return policies::checked_narrowing_cast<result_type, forwarding_policy>( + detail::gamma_inva_imp( + static_cast<value_type>(x), + static_cast<value_type>(p), + static_cast<value_type>(1 - static_cast<value_type>(p)), + pol), "boost::math::gamma_p_inva<%1%>(%1%, %1%)"); +} + +template <class T1, class T2, class Policy> +inline typename tools::promote_args<T1, T2>::type + gamma_q_inva(T1 x, T2 q, const Policy& pol) +{ + typedef typename tools::promote_args<T1, T2>::type result_type; + typedef typename policies::evaluation<result_type, Policy>::type value_type; + typedef typename policies::normalise< + Policy, + policies::promote_float<false>, + policies::promote_double<false>, + policies::discrete_quantile<>, + policies::assert_undefined<> >::type forwarding_policy; + + if(q == 1) + { + return tools::max_value<result_type>(); + } + if(q == 0) + { + return tools::min_value<result_type>(); + } + + return policies::checked_narrowing_cast<result_type, forwarding_policy>( + detail::gamma_inva_imp( + static_cast<value_type>(x), + static_cast<value_type>(1 - static_cast<value_type>(q)), + static_cast<value_type>(q), + pol), "boost::math::gamma_q_inva<%1%>(%1%, %1%)"); +} + +template <class T1, class T2> +inline typename tools::promote_args<T1, T2>::type + gamma_p_inva(T1 x, T2 p) +{ + return boost::math::gamma_p_inva(x, p, policies::policy<>()); +} + +template <class T1, class T2> +inline typename tools::promote_args<T1, T2>::type + gamma_q_inva(T1 x, T2 q) +{ + return boost::math::gamma_q_inva(x, q, policies::policy<>()); +} + +} // namespace math +} // namespace boost + +#endif // BOOST_MATH_SP_DETAIL_GAMMA_INVA + + + diff --git a/Utilities/BGL/boost/math/special_functions/detail/ibeta_inv_ab.hpp b/Utilities/BGL/boost/math/special_functions/detail/ibeta_inv_ab.hpp new file mode 100644 index 0000000000000000000000000000000000000000..0c8fe16a3c8e7291c43376d48098b3e9d354e2c6 --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/detail/ibeta_inv_ab.hpp @@ -0,0 +1,324 @@ +// (C) Copyright John Maddock 2006. +// Use, modification and distribution are subject to 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) + +// +// This is not a complete header file, it is included by beta.hpp +// after it has defined it's definitions. This inverts the incomplete +// beta functions ibeta and ibetac on the first parameters "a" +// and "b" using a generic root finding algorithm (TOMS Algorithm 748). +// + +#ifndef BOOST_MATH_SP_DETAIL_BETA_INV_AB +#define BOOST_MATH_SP_DETAIL_BETA_INV_AB + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/math/tools/toms748_solve.hpp> +#include <boost/cstdint.hpp> + +namespace boost{ namespace math{ namespace detail{ + +template <class T, class Policy> +struct beta_inv_ab_t +{ + beta_inv_ab_t(T b_, T z_, T p_, bool invert_, bool swap_ab_) : b(b_), z(z_), p(p_), invert(invert_), swap_ab(swap_ab_) {} + T operator()(T a) + { + return invert ? + p - boost::math::ibetac(swap_ab ? b : a, swap_ab ? a : b, z, Policy()) + : boost::math::ibeta(swap_ab ? b : a, swap_ab ? a : b, z, Policy()) - p; + } +private: + T b, z, p; + bool invert, swap_ab; +}; + +template <class T, class Policy> +T inverse_negative_binomial_cornish_fisher(T n, T sf, T sfc, T p, T q, const Policy& pol) +{ + BOOST_MATH_STD_USING + // mean: + T m = n * (sfc) / sf; + T t = sqrt(n * (sfc)); + // standard deviation: + T sigma = t / sf; + // skewness + T sk = (1 + sfc) / t; + // kurtosis: + T k = (6 - sf * (5+sfc)) / (n * (sfc)); + // Get the inverse of a std normal distribution: + T x = boost::math::erfc_inv(p > q ? 2 * q : 2 * p, pol) * constants::root_two<T>(); + // Set the sign: + if(p < 0.5) + x = -x; + T x2 = x * x; + // w is correction term due to skewness + T w = x + sk * (x2 - 1) / 6; + // + // Add on correction due to kurtosis. + // + if(n >= 10) + w += k * x * (x2 - 3) / 24 + sk * sk * x * (2 * x2 - 5) / -36; + + w = m + sigma * w; + if(w < tools::min_value<T>()) + return tools::min_value<T>(); + return w; +} + +template <class T, class Policy> +T ibeta_inv_ab_imp(const T& b, const T& z, const T& p, const T& q, bool swap_ab, const Policy& pol) +{ + BOOST_MATH_STD_USING // for ADL of std lib math functions + // + // Special cases first: + // + BOOST_MATH_INSTRUMENT_CODE("b = " << b << " z = " << z << " p = " << p << " q = " << " swap = " << swap_ab); + if(p == 0) + { + return swap_ab ? tools::min_value<T>() : tools::max_value<T>(); + } + if(q == 0) + { + return swap_ab ? tools::max_value<T>() : tools::min_value<T>(); + } + // + // Function object, this is the functor whose root + // we have to solve: + // + beta_inv_ab_t<T, Policy> f(b, z, (p < q) ? p : q, (p < q) ? false : true, swap_ab); + // + // Tolerance: full precision. + // + tools::eps_tolerance<T> tol(policies::digits<T, Policy>()); + // + // Now figure out a starting guess for what a may be, + // we'll start out with a value that'll put p or q + // right bang in the middle of their range, the functions + // are quite sensitive so we should need too many steps + // to bracket the root from there: + // + T guess = 0; + T factor = 5; + // + // Convert variables to parameters of a negative binomial distribution: + // + T n = b; + T sf = swap_ab ? z : 1-z; + T sfc = swap_ab ? 1-z : z; + T u = swap_ab ? p : q; + T v = swap_ab ? q : p; + if(u <= pow(sf, n)) + { + // + // Result is less than 1, negative binomial approximation + // is useless.... + // + if((p < q) != swap_ab) + { + guess = (std::min)(T(b * 2), T(1)); + } + else + { + guess = (std::min)(T(b / 2), T(1)); + } + } + if(n * n * n * u * sf > 0.005) + guess = 1 + inverse_negative_binomial_cornish_fisher(n, sf, sfc, u, v, pol); + + if(guess < 10) + { + // + // Negative binomial approximation not accurate in this area: + // + if((p < q) != swap_ab) + { + guess = (std::min)(T(b * 2), T(10)); + } + else + { + guess = (std::min)(T(b / 2), T(10)); + } + } + else + factor = (v < sqrt(tools::epsilon<T>())) ? 2 : (guess < 20 ? 1.2f : 1.1f); + BOOST_MATH_INSTRUMENT_CODE("guess = " << guess); + // + // Max iterations permitted: + // + boost::uintmax_t max_iter = policies::get_max_root_iterations<Policy>(); + std::pair<T, T> r = bracket_and_solve_root(f, guess, factor, swap_ab ? true : false, tol, max_iter, pol); + if(max_iter >= policies::get_max_root_iterations<Policy>()) + policies::raise_evaluation_error<T>("boost::math::ibeta_invab_imp<%1%>(%1%,%1%,%1%)", "Unable to locate the root within a reasonable number of iterations, closest approximation so far was %1%", r.first, pol); + return (r.first + r.second) / 2; +} + +} // namespace detail + +template <class RT1, class RT2, class RT3, class Policy> +typename tools::promote_args<RT1, RT2, RT3>::type + ibeta_inva(RT1 b, RT2 x, RT3 p, const Policy& pol) +{ + typedef typename tools::promote_args<RT1, RT2, RT3>::type result_type; + typedef typename policies::evaluation<result_type, Policy>::type value_type; + typedef typename policies::normalise< + Policy, + policies::promote_float<false>, + policies::promote_double<false>, + policies::discrete_quantile<>, + policies::assert_undefined<> >::type forwarding_policy; + + if(p == 0) + { + return tools::max_value<result_type>(); + } + if(p == 1) + { + return tools::min_value<result_type>(); + } + + return policies::checked_narrowing_cast<result_type, forwarding_policy>( + detail::ibeta_inv_ab_imp( + static_cast<value_type>(b), + static_cast<value_type>(x), + static_cast<value_type>(p), + static_cast<value_type>(1 - static_cast<value_type>(p)), + false, pol), + "boost::math::ibeta_inva<%1%>(%1%,%1%,%1%)"); +} + +template <class RT1, class RT2, class RT3, class Policy> +typename tools::promote_args<RT1, RT2, RT3>::type + ibetac_inva(RT1 b, RT2 x, RT3 q, const Policy& pol) +{ + typedef typename tools::promote_args<RT1, RT2, RT3>::type result_type; + typedef typename policies::evaluation<result_type, Policy>::type value_type; + typedef typename policies::normalise< + Policy, + policies::promote_float<false>, + policies::promote_double<false>, + policies::discrete_quantile<>, + policies::assert_undefined<> >::type forwarding_policy; + + if(q == 1) + { + return tools::max_value<result_type>(); + } + if(q == 0) + { + return tools::min_value<result_type>(); + } + + return policies::checked_narrowing_cast<result_type, forwarding_policy>( + detail::ibeta_inv_ab_imp( + static_cast<value_type>(b), + static_cast<value_type>(x), + static_cast<value_type>(1 - static_cast<value_type>(q)), + static_cast<value_type>(q), + false, pol), + "boost::math::ibetac_inva<%1%>(%1%,%1%,%1%)"); +} + +template <class RT1, class RT2, class RT3, class Policy> +typename tools::promote_args<RT1, RT2, RT3>::type + ibeta_invb(RT1 a, RT2 x, RT3 p, const Policy& pol) +{ + typedef typename tools::promote_args<RT1, RT2, RT3>::type result_type; + typedef typename policies::evaluation<result_type, Policy>::type value_type; + typedef typename policies::normalise< + Policy, + policies::promote_float<false>, + policies::promote_double<false>, + policies::discrete_quantile<>, + policies::assert_undefined<> >::type forwarding_policy; + + if(p == 0) + { + return tools::min_value<result_type>(); + } + if(p == 1) + { + return tools::max_value<result_type>(); + } + + return policies::checked_narrowing_cast<result_type, forwarding_policy>( + detail::ibeta_inv_ab_imp( + static_cast<value_type>(a), + static_cast<value_type>(x), + static_cast<value_type>(p), + static_cast<value_type>(1 - static_cast<value_type>(p)), + true, pol), + "boost::math::ibeta_invb<%1%>(%1%,%1%,%1%)"); +} + +template <class RT1, class RT2, class RT3, class Policy> +typename tools::promote_args<RT1, RT2, RT3>::type + ibetac_invb(RT1 a, RT2 x, RT3 q, const Policy& pol) +{ + typedef typename tools::promote_args<RT1, RT2, RT3>::type result_type; + typedef typename policies::evaluation<result_type, Policy>::type value_type; + typedef typename policies::normalise< + Policy, + policies::promote_float<false>, + policies::promote_double<false>, + policies::discrete_quantile<>, + policies::assert_undefined<> >::type forwarding_policy; + + if(q == 1) + { + return tools::min_value<result_type>(); + } + if(q == 0) + { + return tools::max_value<result_type>(); + } + + return policies::checked_narrowing_cast<result_type, forwarding_policy>( + detail::ibeta_inv_ab_imp( + static_cast<value_type>(a), + static_cast<value_type>(x), + static_cast<value_type>(1 - static_cast<value_type>(q)), + static_cast<value_type>(q), + true, pol), + "boost::math::ibetac_invb<%1%>(%1%,%1%,%1%)"); +} + +template <class RT1, class RT2, class RT3> +inline typename tools::promote_args<RT1, RT2, RT3>::type + ibeta_inva(RT1 b, RT2 x, RT3 p) +{ + return boost::math::ibeta_inva(b, x, p, policies::policy<>()); +} + +template <class RT1, class RT2, class RT3> +inline typename tools::promote_args<RT1, RT2, RT3>::type + ibetac_inva(RT1 b, RT2 x, RT3 q) +{ + return boost::math::ibetac_inva(b, x, q, policies::policy<>()); +} + +template <class RT1, class RT2, class RT3> +inline typename tools::promote_args<RT1, RT2, RT3>::type + ibeta_invb(RT1 a, RT2 x, RT3 p) +{ + return boost::math::ibeta_invb(a, x, p, policies::policy<>()); +} + +template <class RT1, class RT2, class RT3> +inline typename tools::promote_args<RT1, RT2, RT3>::type + ibetac_invb(RT1 a, RT2 x, RT3 q) +{ + return boost::math::ibetac_invb(a, x, q, policies::policy<>()); +} + +} // namespace math +} // namespace boost + +#endif // BOOST_MATH_SP_DETAIL_BETA_INV_AB + + + diff --git a/Utilities/BGL/boost/math/special_functions/detail/ibeta_inverse.hpp b/Utilities/BGL/boost/math/special_functions/detail/ibeta_inverse.hpp new file mode 100644 index 0000000000000000000000000000000000000000..b78d353f3947cf93ef441144003826613e57125b --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/detail/ibeta_inverse.hpp @@ -0,0 +1,941 @@ +// Copyright John Maddock 2006. +// Copyright Paul A. Bristow 2007 +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_SPECIAL_FUNCTIONS_IBETA_INVERSE_HPP +#define BOOST_MATH_SPECIAL_FUNCTIONS_IBETA_INVERSE_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/math/special_functions/beta.hpp> +#include <boost/math/special_functions/erf.hpp> +#include <boost/math/tools/roots.hpp> +#include <boost/math/special_functions/detail/t_distribution_inv.hpp> + +namespace boost{ namespace math{ namespace detail{ + +// +// Helper object used by root finding +// code to convert eta to x. +// +template <class T> +struct temme_root_finder +{ + temme_root_finder(const T t_, const T a_) : t(t_), a(a_) {} + + std::tr1::tuple<T, T> operator()(T x) + { + BOOST_MATH_STD_USING // ADL of std names + + T y = 1 - x; + if(y == 0) + { + T big = tools::max_value<T>() / 4; + return std::tr1::make_tuple(-big, -big); + } + if(x == 0) + { + T big = tools::max_value<T>() / 4; + return std::tr1::make_tuple(-big, big); + } + T f = log(x) + a * log(y) + t; + T f1 = (1 / x) - (a / (y)); + return std::tr1::make_tuple(f, f1); + } +private: + T t, a; +}; +// +// See: +// "Asymptotic Inversion of the Incomplete Beta Function" +// N.M. Temme +// Journal of Computation and Applied Mathematics 41 (1992) 145-157. +// Section 2. +// +template <class T, class Policy> +T temme_method_1_ibeta_inverse(T a, T b, T z, const Policy& pol) +{ + BOOST_MATH_STD_USING // ADL of std names + + const T r2 = sqrt(T(2)); + // + // get the first approximation for eta from the inverse + // error function (Eq: 2.9 and 2.10). + // + T eta0 = boost::math::erfc_inv(2 * z, pol); + eta0 /= -sqrt(a / 2); + + T terms[4] = { eta0 }; + T workspace[7]; + // + // calculate powers: + // + T B = b - a; + T B_2 = B * B; + T B_3 = B_2 * B; + // + // Calculate correction terms: + // + + // See eq following 2.15: + workspace[0] = -B * r2 / 2; + workspace[1] = (1 - 2 * B) / 8; + workspace[2] = -(B * r2 / 48); + workspace[3] = T(-1) / 192; + workspace[4] = -B * r2 / 3840; + terms[1] = tools::evaluate_polynomial(workspace, eta0, 5); + // Eq Following 2.17: + workspace[0] = B * r2 * (3 * B - 2) / 12; + workspace[1] = (20 * B_2 - 12 * B + 1) / 128; + workspace[2] = B * r2 * (20 * B - 1) / 960; + workspace[3] = (16 * B_2 + 30 * B - 15) / 4608; + workspace[4] = B * r2 * (21 * B + 32) / 53760; + workspace[5] = (-32 * B_2 + 63) / 368640; + workspace[6] = -B * r2 * (120 * B + 17) / 25804480; + terms[2] = tools::evaluate_polynomial(workspace, eta0, 7); + // Eq Following 2.17: + workspace[0] = B * r2 * (-75 * B_2 + 80 * B - 16) / 480; + workspace[1] = (-1080 * B_3 + 868 * B_2 - 90 * B - 45) / 9216; + workspace[2] = B * r2 * (-1190 * B_2 + 84 * B + 373) / 53760; + workspace[3] = (-2240 * B_3 - 2508 * B_2 + 2100 * B - 165) / 368640; + terms[3] = tools::evaluate_polynomial(workspace, eta0, 4); + // + // Bring them together to get a final estimate for eta: + // + T eta = tools::evaluate_polynomial(terms, T(1/a), 4); + // + // now we need to convert eta to x, by solving the appropriate + // quadratic equation: + // + T eta_2 = eta * eta; + T c = -exp(-eta_2 / 2); + T x; + if(eta_2 == 0) + x = 0.5; + else + x = (1 + eta * sqrt((1 + c) / eta_2)) / 2; + + BOOST_ASSERT(x >= 0); + BOOST_ASSERT(x <= 1); + BOOST_ASSERT(eta * (x - 0.5) >= 0); +#ifdef BOOST_INSTRUMENT + std::cout << "Estimating x with Temme method 1: " << x << std::endl; +#endif + return x; +} +// +// See: +// "Asymptotic Inversion of the Incomplete Beta Function" +// N.M. Temme +// Journal of Computation and Applied Mathematics 41 (1992) 145-157. +// Section 3. +// +template <class T, class Policy> +T temme_method_2_ibeta_inverse(T /*a*/, T /*b*/, T z, T r, T theta, const Policy& pol) +{ + BOOST_MATH_STD_USING // ADL of std names + + // + // Get first estimate for eta, see Eq 3.9 and 3.10, + // but note there is a typo in Eq 3.10: + // + T eta0 = boost::math::erfc_inv(2 * z, pol); + eta0 /= -sqrt(r / 2); + + T s = sin(theta); + T c = cos(theta); + // + // Now we need to purturb eta0 to get eta, which we do by + // evaluating the polynomial in 1/r at the bottom of page 151, + // to do this we first need the error terms e1, e2 e3 + // which we'll fill into the array "terms". Since these + // terms are themselves polynomials, we'll need another + // array "workspace" to calculate those... + // + T terms[4] = { eta0 }; + T workspace[6]; + // + // some powers of sin(theta)cos(theta) that we'll need later: + // + T sc = s * c; + T sc_2 = sc * sc; + T sc_3 = sc_2 * sc; + T sc_4 = sc_2 * sc_2; + T sc_5 = sc_2 * sc_3; + T sc_6 = sc_3 * sc_3; + T sc_7 = sc_4 * sc_3; + // + // Calculate e1 and put it in terms[1], see the middle of page 151: + // + workspace[0] = (2 * s * s - 1) / (3 * s * c); + static const BOOST_MATH_INT_TABLE_TYPE(T, int) co1[] = { -1, -5, 5 }; + workspace[1] = -tools::evaluate_even_polynomial(co1, s, 3) / (36 * sc_2); + static const BOOST_MATH_INT_TABLE_TYPE(T, int) co2[] = { 1, 21, -69, 46 }; + workspace[2] = tools::evaluate_even_polynomial(co2, s, 4) / (1620 * sc_3); + static const BOOST_MATH_INT_TABLE_TYPE(T, int) co3[] = { 7, -2, 33, -62, 31 }; + workspace[3] = -tools::evaluate_even_polynomial(co3, s, 5) / (6480 * sc_4); + static const BOOST_MATH_INT_TABLE_TYPE(T, int) co4[] = { 25, -52, -17, 88, -115, 46 }; + workspace[4] = tools::evaluate_even_polynomial(co4, s, 6) / (90720 * sc_5); + terms[1] = tools::evaluate_polynomial(workspace, eta0, 5); + // + // Now evaluate e2 and put it in terms[2]: + // + static const BOOST_MATH_INT_TABLE_TYPE(T, int) co5[] = { 7, 12, -78, 52 }; + workspace[0] = -tools::evaluate_even_polynomial(co5, s, 4) / (405 * sc_3); + static const BOOST_MATH_INT_TABLE_TYPE(T, int) co6[] = { -7, 2, 183, -370, 185 }; + workspace[1] = tools::evaluate_even_polynomial(co6, s, 5) / (2592 * sc_4); + static const BOOST_MATH_INT_TABLE_TYPE(T, int) co7[] = { -533, 776, -1835, 10240, -13525, 5410 }; + workspace[2] = -tools::evaluate_even_polynomial(co7, s, 6) / (204120 * sc_5); + static const BOOST_MATH_INT_TABLE_TYPE(T, int) co8[] = { -1579, 3747, -3372, -15821, 45588, -45213, 15071 }; + workspace[3] = -tools::evaluate_even_polynomial(co8, s, 7) / (2099520 * sc_6); + terms[2] = tools::evaluate_polynomial(workspace, eta0, 4); + // + // And e3, and put it in terms[3]: + // + static const BOOST_MATH_INT_TABLE_TYPE(T, int) co9[] = {449, -1259, -769, 6686, -9260, 3704 }; + workspace[0] = tools::evaluate_even_polynomial(co9, s, 6) / (102060 * sc_5); + static const BOOST_MATH_INT_TABLE_TYPE(T, int) co10[] = { 63149, -151557, 140052, -727469, 2239932, -2251437, 750479 }; + workspace[1] = -tools::evaluate_even_polynomial(co10, s, 7) / (20995200 * sc_6); + static const BOOST_MATH_INT_TABLE_TYPE(T, int) co11[] = { 29233, -78755, 105222, 146879, -1602610, 3195183, -2554139, 729754 }; + workspace[2] = tools::evaluate_even_polynomial(co11, s, 8) / (36741600 * sc_7); + terms[3] = tools::evaluate_polynomial(workspace, eta0, 3); + // + // Bring the correction terms together to evaluate eta, + // this is the last equation on page 151: + // + T eta = tools::evaluate_polynomial(terms, T(1/r), 4); + // + // Now that we have eta we need to back solve for x, + // we seek the value of x that gives eta in Eq 3.2. + // The two methods used are described in section 5. + // + // Begin by defining a few variables we'll need later: + // + T x; + T s_2 = s * s; + T c_2 = c * c; + T alpha = c / s; + alpha *= alpha; + T lu = (-(eta * eta) / (2 * s_2) + log(s_2) + c_2 * log(c_2) / s_2); + // + // Temme doesn't specify what value to switch on here, + // but this seems to work pretty well: + // + if(fabs(eta) < 0.7) + { + // + // Small eta use the expansion Temme gives in the second equation + // of section 5, it's a polynomial in eta: + // + workspace[0] = s * s; + workspace[1] = s * c; + workspace[2] = (1 - 2 * workspace[0]) / 3; + static const BOOST_MATH_INT_TABLE_TYPE(T, int) co12[] = { 1, -13, 13 }; + workspace[3] = tools::evaluate_polynomial(co12, workspace[0], 3) / (36 * s * c); + static const BOOST_MATH_INT_TABLE_TYPE(T, int) co13[] = { 1, 21, -69, 46 }; + workspace[4] = tools::evaluate_polynomial(co13, workspace[0], 4) / (270 * workspace[0] * c * c); + x = tools::evaluate_polynomial(workspace, eta, 5); +#ifdef BOOST_INSTRUMENT + std::cout << "Estimating x with Temme method 2 (small eta): " << x << std::endl; +#endif + } + else + { + // + // If eta is large we need to solve Eq 3.2 more directly, + // begin by getting an initial approximation for x from + // the last equation on page 155, this is a polynomial in u: + // + T u = exp(lu); + workspace[0] = u; + workspace[1] = alpha; + workspace[2] = 0; + workspace[3] = 3 * alpha * (3 * alpha + 1) / 6; + workspace[4] = 4 * alpha * (4 * alpha + 1) * (4 * alpha + 2) / 24; + workspace[5] = 5 * alpha * (5 * alpha + 1) * (5 * alpha + 2) * (5 * alpha + 3) / 120; + x = tools::evaluate_polynomial(workspace, u, 6); + // + // At this point we may or may not have the right answer, Eq-3.2 has + // two solutions for x for any given eta, however the mapping in 3.2 + // is 1:1 with the sign of eta and x-sin^2(theta) being the same. + // So we can check if we have the right root of 3.2, and if not + // switch x for 1-x. This transformation is motivated by the fact + // that the distribution is *almost* symetric so 1-x will be in the right + // ball park for the solution: + // + if((x - s_2) * eta < 0) + x = 1 - x; +#ifdef BOOST_INSTRUMENT + std::cout << "Estimating x with Temme method 2 (large eta): " << x << std::endl; +#endif + } + // + // The final step is a few Newton-Raphson iterations to + // clean up our approximation for x, this is pretty cheap + // in general, and very cheap compared to an incomplete beta + // evaluation. The limits set on x come from the observation + // that the sign of eta and x-sin^2(theta) are the same. + // + T lower, upper; + if(eta < 0) + { + lower = 0; + upper = s_2; + } + else + { + lower = s_2; + upper = 1; + } + // + // If our initial approximation is out of bounds then bisect: + // + if((x < lower) || (x > upper)) + x = (lower+upper) / 2; + // + // And iterate: + // + x = tools::newton_raphson_iterate( + temme_root_finder<T>(-lu, alpha), x, lower, upper, policies::digits<T, Policy>() / 2); + + return x; +} +// +// See: +// "Asymptotic Inversion of the Incomplete Beta Function" +// N.M. Temme +// Journal of Computation and Applied Mathematics 41 (1992) 145-157. +// Section 4. +// +template <class T, class Policy> +T temme_method_3_ibeta_inverse(T a, T b, T p, T q, const Policy& pol) +{ + BOOST_MATH_STD_USING // ADL of std names + + // + // Begin by getting an initial approximation for the quantity + // eta from the dominant part of the incomplete beta: + // + T eta0; + if(p < q) + eta0 = boost::math::gamma_q_inv(b, p, pol); + else + eta0 = boost::math::gamma_p_inv(b, q, pol); + eta0 /= a; + // + // Define the variables and powers we'll need later on: + // + T mu = b / a; + T w = sqrt(1 + mu); + T w_2 = w * w; + T w_3 = w_2 * w; + T w_4 = w_2 * w_2; + T w_5 = w_3 * w_2; + T w_6 = w_3 * w_3; + T w_7 = w_4 * w_3; + T w_8 = w_4 * w_4; + T w_9 = w_5 * w_4; + T w_10 = w_5 * w_5; + T d = eta0 - mu; + T d_2 = d * d; + T d_3 = d_2 * d; + T d_4 = d_2 * d_2; + T w1 = w + 1; + T w1_2 = w1 * w1; + T w1_3 = w1 * w1_2; + T w1_4 = w1_2 * w1_2; + // + // Now we need to compute the purturbation error terms that + // convert eta0 to eta, these are all polynomials of polynomials. + // Probably these should be re-written to use tabulated data + // (see examples above), but it's less of a win in this case as we + // need to calculate the individual powers for the denominator terms + // anyway, so we might as well use them for the numerator-polynomials + // as well.... + // + // Refer to p154-p155 for the details of these expansions: + // + T e1 = (w + 2) * (w - 1) / (3 * w); + e1 += (w_3 + 9 * w_2 + 21 * w + 5) * d / (36 * w_2 * w1); + e1 -= (w_4 - 13 * w_3 + 69 * w_2 + 167 * w + 46) * d_2 / (1620 * w1_2 * w_3); + e1 -= (7 * w_5 + 21 * w_4 + 70 * w_3 + 26 * w_2 - 93 * w - 31) * d_3 / (6480 * w1_3 * w_4); + e1 -= (75 * w_6 + 202 * w_5 + 188 * w_4 - 888 * w_3 - 1345 * w_2 + 118 * w + 138) * d_4 / (272160 * w1_4 * w_5); + + T e2 = (28 * w_4 + 131 * w_3 + 402 * w_2 + 581 * w + 208) * (w - 1) / (1620 * w1 * w_3); + e2 -= (35 * w_6 - 154 * w_5 - 623 * w_4 - 1636 * w_3 - 3983 * w_2 - 3514 * w - 925) * d / (12960 * w1_2 * w_4); + e2 -= (2132 * w_7 + 7915 * w_6 + 16821 * w_5 + 35066 * w_4 + 87490 * w_3 + 141183 * w_2 + 95993 * w + 21640) * d_2 / (816480 * w_5 * w1_3); + e2 -= (11053 * w_8 + 53308 * w_7 + 117010 * w_6 + 163924 * w_5 + 116188 * w_4 - 258428 * w_3 - 677042 * w_2 - 481940 * w - 105497) * d_3 / (14696640 * w1_4 * w_6); + + T e3 = -((3592 * w_7 + 8375 * w_6 - 1323 * w_5 - 29198 * w_4 - 89578 * w_3 - 154413 * w_2 - 116063 * w - 29632) * (w - 1)) / (816480 * w_5 * w1_2); + e3 -= (442043 * w_9 + 2054169 * w_8 + 3803094 * w_7 + 3470754 * w_6 + 2141568 * w_5 - 2393568 * w_4 - 19904934 * w_3 - 34714674 * w_2 - 23128299 * w - 5253353) * d / (146966400 * w_6 * w1_3); + e3 -= (116932 * w_10 + 819281 * w_9 + 2378172 * w_8 + 4341330 * w_7 + 6806004 * w_6 + 10622748 * w_5 + 18739500 * w_4 + 30651894 * w_3 + 30869976 * w_2 + 15431867 * w + 2919016) * d_2 / (146966400 * w1_4 * w_7); + // + // Combine eta0 and the error terms to compute eta (Second eqaution p155): + // + T eta = eta0 + e1 / a + e2 / (a * a) + e3 / (a * a * a); + // + // Now we need to solve Eq 4.2 to obtain x. For any given value of + // eta there are two solutions to this equation, and since the distribtion + // may be very skewed, these are not related by x ~ 1-x we used when + // implementing section 3 above. However we know that: + // + // cross < x <= 1 ; iff eta < mu + // x == cross ; iff eta == mu + // 0 <= x < cross ; iff eta > mu + // + // Where cross == 1 / (1 + mu) + // Many thanks to Prof Temme for clarifying this point. + // + // Therefore we'll just jump straight into Newton iterations + // to solve Eq 4.2 using these bounds, and simple bisection + // as the first guess, in practice this converges pretty quickly + // and we only need a few digits correct anyway: + // + if(eta <= 0) + eta = tools::min_value<T>(); + T u = eta - mu * log(eta) + (1 + mu) * log(1 + mu) - mu; + T cross = 1 / (1 + mu); + T lower = eta < mu ? cross : 0; + T upper = eta < mu ? 1 : cross; + T x = (lower + upper) / 2; + x = tools::newton_raphson_iterate( + temme_root_finder<T>(u, mu), x, lower, upper, policies::digits<T, Policy>() / 2); +#ifdef BOOST_INSTRUMENT + std::cout << "Estimating x with Temme method 3: " << x << std::endl; +#endif + return x; +} + +template <class T, class Policy> +struct ibeta_roots +{ + ibeta_roots(T _a, T _b, T t, bool inv = false) + : a(_a), b(_b), target(t), invert(inv) {} + + std::tr1::tuple<T, T, T> operator()(T x) + { + BOOST_MATH_STD_USING // ADL of std names + + BOOST_FPU_EXCEPTION_GUARD + + T f1; + T y = 1 - x; + T f = ibeta_imp(a, b, x, Policy(), invert, true, &f1) - target; + if(invert) + f1 = -f1; + if(y == 0) + y = tools::min_value<T>() * 64; + if(x == 0) + x = tools::min_value<T>() * 64; + + T f2 = f1 * (-y * a + (b - 2) * x + 1); + if(fabs(f2) < y * x * tools::max_value<T>()) + f2 /= (y * x); + if(invert) + f2 = -f2; + + // make sure we don't have a zero derivative: + if(f1 == 0) + f1 = (invert ? -1 : 1) * tools::min_value<T>() * 64; + + return std::tr1::make_tuple(f, f1, f2); + } +private: + T a, b, target; + bool invert; +}; + +template <class T, class Policy> +T ibeta_inv_imp(T a, T b, T p, T q, const Policy& pol, T* py) +{ + BOOST_MATH_STD_USING // For ADL of math functions. + + // + // The flag invert is set to true if we swap a for b and p for q, + // in which case the result has to be subtracted from 1: + // + bool invert = false; + // + // Depending upon which approximation method we use, we may end up + // calculating either x or y initially (where y = 1-x): + // + T x = 0; // Set to a safe zero to avoid a + // MSVC 2005 warning C4701: potentially uninitialized local variable 'x' used + // But code inspection appears to ensure that x IS assigned whatever the code path. + T y; + + // For some of the methods we can put tighter bounds + // on the result than simply [0,1]: + // + T lower = 0; + T upper = 1; + // + // Student's T with b = 0.5 gets handled as a special case, swap + // around if the arguments are in the "wrong" order: + // + if(a == 0.5f) + { + std::swap(a, b); + std::swap(p, q); + invert = !invert; + } + // + // Handle trivial cases first: + // + if(q == 0) + { + if(py) *py = 0; + return 1; + } + else if(p == 0) + { + if(py) *py = 1; + return 0; + } + else if((a == 1) && (b == 1)) + { + if(py) *py = 1 - p; + return p; + } + else if((b == 0.5f) && (a >= 0.5f)) + { + // + // We have a Student's T distribution: + x = find_ibeta_inv_from_t_dist(a, p, q, &y, pol); + } + else if(a + b > 5) + { + // + // When a+b is large then we can use one of Prof Temme's + // asymptotic expansions, begin by swapping things around + // so that p < 0.5, we do this to avoid cancellations errors + // when p is large. + // + if(p > 0.5) + { + std::swap(a, b); + std::swap(p, q); + invert = !invert; + } + T minv = (std::min)(a, b); + T maxv = (std::max)(a, b); + if((sqrt(minv) > (maxv - minv)) && (minv > 5)) + { + // + // When a and b differ by a small amount + // the curve is quite symmetrical and we can use an error + // function to approximate the inverse. This is the cheapest + // of the three Temme expantions, and the calculated value + // for x will never be much larger than p, so we don't have + // to worry about cancellation as long as p is small. + // + x = temme_method_1_ibeta_inverse(a, b, p, pol); + y = 1 - x; + } + else + { + T r = a + b; + T theta = asin(sqrt(a / r)); + T lambda = minv / r; + if((lambda >= 0.2) && (lambda <= 0.8) && (lambda >= 10)) + { + // + // The second error function case is the next cheapest + // to use, it brakes down when the result is likely to be + // very small, if a+b is also small, but we can use a + // cheaper expansion there in any case. As before x won't + // be much larger than p, so as long as p is small we should + // be free of cancellation error. + // + T ppa = pow(p, 1/a); + if((ppa < 0.0025) && (a + b < 200)) + { + x = ppa * pow(a * boost::math::beta(a, b, pol), 1/a); + } + else + x = temme_method_2_ibeta_inverse(a, b, p, r, theta, pol); + y = 1 - x; + } + else + { + // + // If we get here then a and b are very different in magnitude + // and we need to use the third of Temme's methods which + // involves inverting the incomplete gamma. This is much more + // expensive than the other methods. We also can only use this + // method when a > b, which can lead to cancellation errors + // if we really want y (as we will when x is close to 1), so + // a different expansion is used in that case. + // + if(a < b) + { + std::swap(a, b); + std::swap(p, q); + invert = !invert; + } + // + // Try and compute the easy way first: + // + T bet = 0; + if(b < 2) + bet = boost::math::beta(a, b, pol); + if(bet != 0) + { + y = pow(b * q * bet, 1/b); + x = 1 - y; + } + else + y = 1; + if(y > 1e-5) + { + x = temme_method_3_ibeta_inverse(a, b, p, q, pol); + y = 1 - x; + } + } + } + } + else if((a < 1) && (b < 1)) + { + // + // Both a and b less than 1, + // there is a point of inflection at xs: + // + T xs = (1 - a) / (2 - a - b); + // + // Now we need to ensure that we start our iteration from the + // right side of the inflection point: + // + T fs = boost::math::ibeta(a, b, xs, pol) - p; + if(fabs(fs) / p < tools::epsilon<T>() * 3) + { + // The result is at the point of inflection, best just return it: + *py = invert ? xs : 1 - xs; + return invert ? 1-xs : xs; + } + if(fs < 0) + { + std::swap(a, b); + std::swap(p, q); + invert = true; + xs = 1 - xs; + } + T xg = pow(a * p * boost::math::beta(a, b, pol), 1/a); + x = xg / (1 + xg); + y = 1 / (1 + xg); + // + // And finally we know that our result is below the inflection + // point, so set an upper limit on our search: + // + if(x > xs) + x = xs; + upper = xs; + } + else if((a > 1) && (b > 1)) + { + // + // Small a and b, both greater than 1, + // there is a point of inflection at xs, + // and it's complement is xs2, we must always + // start our iteration from the right side of the + // point of inflection. + // + T xs = (a - 1) / (a + b - 2); + T xs2 = (b - 1) / (a + b - 2); + T ps = boost::math::ibeta(a, b, xs, pol) - p; + + if(ps < 0) + { + std::swap(a, b); + std::swap(p, q); + std::swap(xs, xs2); + invert = true; + } + // + // Estimate x and y, using expm1 to get a good estimate + // for y when it's very small: + // + T lx = log(p * a * boost::math::beta(a, b, pol)) / a; + x = exp(lx); + y = x < 0.9 ? T(1 - x) : (T)(-boost::math::expm1(lx, pol)); + + if((b < a) && (x < 0.2)) + { + // + // Under a limited range of circumstances we can improve + // our estimate for x, frankly it's clear if this has much effect! + // + T ap1 = a - 1; + T bm1 = b - 1; + T a_2 = a * a; + T a_3 = a * a_2; + T b_2 = b * b; + T terms[5] = { 0, 1 }; + terms[2] = bm1 / ap1; + ap1 *= ap1; + terms[3] = bm1 * (3 * a * b + 5 * b + a_2 - a - 4) / (2 * (a + 2) * ap1); + ap1 *= (a + 1); + terms[4] = bm1 * (33 * a * b_2 + 31 * b_2 + 8 * a_2 * b_2 - 30 * a * b - 47 * b + 11 * a_2 * b + 6 * a_3 * b + 18 + 4 * a - a_3 + a_2 * a_2 - 10 * a_2) + / (3 * (a + 3) * (a + 2) * ap1); + x = tools::evaluate_polynomial(terms, x, 5); + } + // + // And finally we know that our result is below the inflection + // point, so set an upper limit on our search: + // + if(x > xs) + x = xs; + upper = xs; + } + else /*if((a <= 1) != (b <= 1))*/ + { + // + // If all else fails we get here, only one of a and b + // is above 1, and a+b is small. Start by swapping + // things around so that we have a concave curve with b > a + // and no points of inflection in [0,1]. As long as we expect + // x to be small then we can use the simple (and cheap) power + // term to estimate x, but when we expect x to be large then + // this greatly underestimates x and leaves us trying to + // iterate "round the corner" which may take almost forever... + // + // We could use Temme's inverse gamma function case in that case, + // this works really rather well (albeit expensively) even though + // strictly speaking we're outside it's defined range. + // + // However it's expensive to compute, and an alternative approach + // which models the curve as a distorted quarter circle is much + // cheaper to compute, and still keeps the number of iterations + // required down to a reasonable level. With thanks to Prof Temme + // for this suggestion. + // + if(b < a) + { + std::swap(a, b); + std::swap(p, q); + invert = true; + } + if(pow(p, 1/a) < 0.5) + { + x = pow(p * a * boost::math::beta(a, b, pol), 1 / a); + if(x == 0) + x = boost::math::tools::min_value<T>(); + y = 1 - x; + } + else /*if(pow(q, 1/b) < 0.1)*/ + { + // model a distorted quarter circle: + y = pow(1 - pow(p, b * boost::math::beta(a, b, pol)), 1/b); + if(y == 0) + y = boost::math::tools::min_value<T>(); + x = 1 - y; + } + } + + // + // Now we have a guess for x (and for y) we can set things up for + // iteration. If x > 0.5 it pays to swap things round: + // + if(x > 0.5) + { + std::swap(a, b); + std::swap(p, q); + std::swap(x, y); + invert = !invert; + T l = 1 - upper; + T u = 1 - lower; + lower = l; + upper = u; + } + // + // lower bound for our search: + // + // We're not interested in denormalised answers as these tend to + // these tend to take up lots of iterations, given that we can't get + // accurate derivatives in this area (they tend to be infinite). + // + if(lower == 0) + { + if(invert && (py == 0)) + { + // + // We're not interested in answers smaller than machine epsilon: + // + lower = boost::math::tools::epsilon<T>(); + if(x < lower) + x = lower; + } + else + lower = boost::math::tools::min_value<T>(); + if(x < lower) + x = lower; + } + // + // Figure out how many digits to iterate towards: + // + int digits = boost::math::policies::digits<T, Policy>() / 2; + if((x < 1e-50) && ((a < 1) || (b < 1))) + { + // + // If we're in a region where the first derivative is very + // large, then we have to take care that the root-finder + // doesn't terminate prematurely. We'll bump the precision + // up to avoid this, but we have to take care not to set the + // precision too high or the last few iterations will just + // thrash around and convergence may be slow in this case. + // Try 3/4 of machine epsilon: + // + digits *= 3; + digits /= 2; + } + // + // Now iterate, we can use either p or q as the target here + // depending on which is smaller: + // + boost::uintmax_t max_iter = policies::get_max_root_iterations<Policy>(); + x = boost::math::tools::halley_iterate( + boost::math::detail::ibeta_roots<T, Policy>(a, b, (p < q ? p : q), (p < q ? false : true)), x, lower, upper, digits, max_iter); + policies::check_root_iterations("boost::math::ibeta<%1%>(%1%, %1%, %1%)", max_iter, pol); + // + // We don't really want these asserts here, but they are useful for sanity + // checking that we have the limits right, uncomment if you suspect bugs *only*. + // + //BOOST_ASSERT(x != upper); + //BOOST_ASSERT((x != lower) || (x == boost::math::tools::min_value<T>()) || (x == boost::math::tools::epsilon<T>())); + // + // Tidy up, if we "lower" was too high then zero is the best answer we have: + // + if(x == lower) + x = 0; + if(py) + *py = invert ? x : 1 - x; + return invert ? 1-x : x; +} + +} // namespace detail + +template <class T1, class T2, class T3, class T4, class Policy> +inline typename tools::promote_args<T1, T2, T3, T4>::type + ibeta_inv(T1 a, T2 b, T3 p, T4* py, const Policy& pol) +{ + static const char* function = "boost::math::ibeta_inv<%1%>(%1%,%1%,%1%)"; + BOOST_FPU_EXCEPTION_GUARD + typedef typename tools::promote_args<T1, T2, T3, T4>::type result_type; + typedef typename policies::evaluation<result_type, Policy>::type value_type; + typedef typename policies::normalise< + Policy, + policies::promote_float<false>, + policies::promote_double<false>, + policies::discrete_quantile<>, + policies::assert_undefined<> >::type forwarding_policy; + + if(a <= 0) + return policies::raise_domain_error<result_type>(function, "The argument a to the incomplete beta function inverse must be greater than zero (got a=%1%).", a, pol); + if(b <= 0) + return policies::raise_domain_error<result_type>(function, "The argument b to the incomplete beta function inverse must be greater than zero (got b=%1%).", b, pol); + if((p < 0) || (p > 1)) + return policies::raise_domain_error<result_type>(function, "Argument p outside the range [0,1] in the incomplete beta function inverse (got p=%1%).", p, pol); + + value_type rx, ry; + + rx = detail::ibeta_inv_imp( + static_cast<value_type>(a), + static_cast<value_type>(b), + static_cast<value_type>(p), + static_cast<value_type>(1 - p), + forwarding_policy(), &ry); + + if(py) *py = policies::checked_narrowing_cast<T4, forwarding_policy>(ry, function); + return policies::checked_narrowing_cast<result_type, forwarding_policy>(rx, function); +} + +template <class T1, class T2, class T3, class T4> +inline typename tools::promote_args<T1, T2, T3, T4>::type + ibeta_inv(T1 a, T2 b, T3 p, T4* py) +{ + return ibeta_inv(a, b, p, py, policies::policy<>()); +} + +template <class T1, class T2, class T3> +inline typename tools::promote_args<T1, T2, T3>::type + ibeta_inv(T1 a, T2 b, T3 p) +{ + return ibeta_inv(a, b, p, static_cast<T1*>(0), policies::policy<>()); +} + +template <class T1, class T2, class T3, class Policy> +inline typename tools::promote_args<T1, T2, T3>::type + ibeta_inv(T1 a, T2 b, T3 p, const Policy& pol) +{ + return ibeta_inv(a, b, p, static_cast<T1*>(0), pol); +} + +template <class T1, class T2, class T3, class T4, class Policy> +inline typename tools::promote_args<T1, T2, T3, T4>::type + ibetac_inv(T1 a, T2 b, T3 q, T4* py, const Policy& pol) +{ + static const char* function = "boost::math::ibetac_inv<%1%>(%1%,%1%,%1%)"; + BOOST_FPU_EXCEPTION_GUARD + typedef typename tools::promote_args<T1, T2, T3, T4>::type result_type; + typedef typename policies::evaluation<result_type, Policy>::type value_type; + typedef typename policies::normalise< + Policy, + policies::promote_float<false>, + policies::promote_double<false>, + policies::discrete_quantile<>, + policies::assert_undefined<> >::type forwarding_policy; + + if(a <= 0) + policies::raise_domain_error<result_type>(function, "The argument a to the incomplete beta function inverse must be greater than zero (got a=%1%).", a, pol); + if(b <= 0) + policies::raise_domain_error<result_type>(function, "The argument b to the incomplete beta function inverse must be greater than zero (got b=%1%).", b, pol); + if((q < 0) || (q > 1)) + policies::raise_domain_error<result_type>(function, "Argument q outside the range [0,1] in the incomplete beta function inverse (got q=%1%).", q, pol); + + value_type rx, ry; + + rx = detail::ibeta_inv_imp( + static_cast<value_type>(a), + static_cast<value_type>(b), + static_cast<value_type>(1 - q), + static_cast<value_type>(q), + forwarding_policy(), &ry); + + if(py) *py = policies::checked_narrowing_cast<T4, forwarding_policy>(ry, function); + return policies::checked_narrowing_cast<result_type, forwarding_policy>(rx, function); +} + +template <class T1, class T2, class T3, class T4> +inline typename tools::promote_args<T1, T2, T3, T4>::type + ibetac_inv(T1 a, T2 b, T3 q, T4* py) +{ + return ibetac_inv(a, b, q, py, policies::policy<>()); +} + +template <class RT1, class RT2, class RT3> +inline typename tools::promote_args<RT1, RT2, RT3>::type + ibetac_inv(RT1 a, RT2 b, RT3 q) +{ + typedef typename remove_cv<RT1>::type dummy; + return ibetac_inv(a, b, q, static_cast<dummy*>(0), policies::policy<>()); +} + +template <class RT1, class RT2, class RT3, class Policy> +inline typename tools::promote_args<RT1, RT2, RT3>::type + ibetac_inv(RT1 a, RT2 b, RT3 q, const Policy& pol) +{ + typedef typename remove_cv<RT1>::type dummy; + return ibetac_inv(a, b, q, static_cast<dummy*>(0), pol); +} + +} // namespace math +} // namespace boost + +#endif // BOOST_MATH_SPECIAL_FUNCTIONS_IGAMMA_INVERSE_HPP + + + + diff --git a/Utilities/BGL/boost/math/special_functions/detail/igamma_inverse.hpp b/Utilities/BGL/boost/math/special_functions/detail/igamma_inverse.hpp new file mode 100644 index 0000000000000000000000000000000000000000..69aca13737b37350d5be9110f267221bc8ac1378 --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/detail/igamma_inverse.hpp @@ -0,0 +1,550 @@ +// (C) Copyright John Maddock 2006. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_SPECIAL_FUNCTIONS_IGAMMA_INVERSE_HPP +#define BOOST_MATH_SPECIAL_FUNCTIONS_IGAMMA_INVERSE_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/tr1/tuple.hpp> +#include <boost/math/special_functions/gamma.hpp> +#include <boost/math/special_functions/sign.hpp> +#include <boost/math/tools/roots.hpp> +#include <boost/math/policies/error_handling.hpp> + +namespace boost{ namespace math{ + +namespace detail{ + +template <class T> +T find_inverse_s(T p, T q) +{ + // + // Computation of the Incomplete Gamma Function Ratios and their Inverse + // ARMIDO R. DIDONATO and ALFRED H. MORRIS, JR. + // ACM Transactions on Mathematical Software, Vol. 12, No. 4, + // December 1986, Pages 377-393. + // + // See equation 32. + // + BOOST_MATH_STD_USING + T t; + if(p < 0.5) + { + t = sqrt(-2 * log(p)); + } + else + { + t = sqrt(-2 * log(q)); + } + static const double a[4] = { 3.31125922108741, 11.6616720288968, 4.28342155967104, 0.213623493715853 }; + static const double b[5] = { 1, 6.61053765625462, 6.40691597760039, 1.27364489782223, 0.3611708101884203e-1 }; + T s = t - tools::evaluate_polynomial(a, t) / tools::evaluate_polynomial(b, t); + if(p < 0.5) + s = -s; + return s; +} + +template <class T> +T didonato_SN(T a, T x, unsigned N, T tolerance = 0) +{ + // + // Computation of the Incomplete Gamma Function Ratios and their Inverse + // ARMIDO R. DIDONATO and ALFRED H. MORRIS, JR. + // ACM Transactions on Mathematical Software, Vol. 12, No. 4, + // December 1986, Pages 377-393. + // + // See equation 34. + // + T sum = 1; + if(N >= 1) + { + T partial = x / (a + 1); + sum += partial; + for(unsigned i = 2; i <= N; ++i) + { + partial *= x / (a + i); + sum += partial; + if(partial < tolerance) + break; + } + } + return sum; +} + +template <class T, class Policy> +inline T didonato_FN(T p, T a, T x, unsigned N, T tolerance, const Policy& pol) +{ + // + // Computation of the Incomplete Gamma Function Ratios and their Inverse + // ARMIDO R. DIDONATO and ALFRED H. MORRIS, JR. + // ACM Transactions on Mathematical Software, Vol. 12, No. 4, + // December 1986, Pages 377-393. + // + // See equation 34. + // + BOOST_MATH_STD_USING + T u = log(p) + boost::math::lgamma(a + 1, pol); + return exp((u + x - log(didonato_SN(a, x, N, tolerance))) / a); +} + +template <class T, class Policy> +T find_inverse_gamma(T a, T p, T q, const Policy& pol, bool* p_has_10_digits) +{ + // + // In order to understand what's going on here, you will + // need to refer to: + // + // Computation of the Incomplete Gamma Function Ratios and their Inverse + // ARMIDO R. DIDONATO and ALFRED H. MORRIS, JR. + // ACM Transactions on Mathematical Software, Vol. 12, No. 4, + // December 1986, Pages 377-393. + // + BOOST_MATH_STD_USING + + T result; + *p_has_10_digits = false; + + if(a == 1) + { + result = -log(q); + BOOST_MATH_INSTRUMENT_VARIABLE(result); + } + else if(a < 1) + { + T g = boost::math::tgamma(a, pol); + T b = q * g; + BOOST_MATH_INSTRUMENT_VARIABLE(g); + BOOST_MATH_INSTRUMENT_VARIABLE(b); + if((b > 0.6) || ((b >= 0.45) && (a >= 0.3))) + { + // DiDonato & Morris Eq 21: + // + // There is a slight variation from DiDonato and Morris here: + // the first form given here is unstable when p is close to 1, + // making it impossible to compute the inverse of Q(a,x) for small + // q. Fortunately the second form works perfectly well in this case. + // + T u; + if((b * q > 1e-8) && (q > 1e-5)) + { + u = pow(p * g * a, 1 / a); + BOOST_MATH_INSTRUMENT_VARIABLE(u); + } + else + { + u = exp((-q / a) - constants::euler<T>()); + BOOST_MATH_INSTRUMENT_VARIABLE(u); + } + result = u / (1 - (u / (a + 1))); + BOOST_MATH_INSTRUMENT_VARIABLE(result); + } + else if((a < 0.3) && (b >= 0.35)) + { + // DiDonato & Morris Eq 22: + T t = exp(-constants::euler<T>() - b); + T u = t * exp(t); + result = t * exp(u); + BOOST_MATH_INSTRUMENT_VARIABLE(result); + } + else if((b > 0.15) || (a >= 0.3)) + { + // DiDonato & Morris Eq 23: + T y = -log(b); + T u = y - (1 - a) * log(y); + result = y - (1 - a) * log(u) - log(1 + (1 - a) / (1 + u)); + BOOST_MATH_INSTRUMENT_VARIABLE(result); + } + else if (b > 0.1) + { + // DiDonato & Morris Eq 24: + T y = -log(b); + T u = y - (1 - a) * log(y); + result = y - (1 - a) * log(u) - log((u * u + 2 * (3 - a) * u + (2 - a) * (3 - a)) / (u * u + (5 - a) * u + 2)); + BOOST_MATH_INSTRUMENT_VARIABLE(result); + } + else + { + // DiDonato & Morris Eq 25: + T y = -log(b); + T c1 = (a - 1) * log(y); + T c1_2 = c1 * c1; + T c1_3 = c1_2 * c1; + T c1_4 = c1_2 * c1_2; + T a_2 = a * a; + T a_3 = a_2 * a; + + T c2 = (a - 1) * (1 + c1); + T c3 = (a - 1) * (-(c1_2 / 2) + (a - 2) * c1 + (3 * a - 5) / 2); + T c4 = (a - 1) * ((c1_3 / 3) - (3 * a - 5) * c1_2 / 2 + (a_2 - 6 * a + 7) * c1 + (11 * a_2 - 46 * a + 47) / 6); + T c5 = (a - 1) * (-(c1_4 / 4) + + (11 * a - 17) * c1_3 / 6 + + (-3 * a_2 + 13 * a -13) * c1_2 + + (2 * a_3 - 25 * a_2 + 72 * a - 61) * c1 / 2 + + (25 * a_3 - 195 * a_2 + 477 * a - 379) / 12); + + T y_2 = y * y; + T y_3 = y_2 * y; + T y_4 = y_2 * y_2; + result = y + c1 + (c2 / y) + (c3 / y_2) + (c4 / y_3) + (c5 / y_4); + BOOST_MATH_INSTRUMENT_VARIABLE(result); + if(b < 1e-28f) + *p_has_10_digits = true; + } + } + else + { + // DiDonato and Morris Eq 31: + T s = find_inverse_s(p, q); + + BOOST_MATH_INSTRUMENT_VARIABLE(s); + + T s_2 = s * s; + T s_3 = s_2 * s; + T s_4 = s_2 * s_2; + T s_5 = s_4 * s; + T ra = sqrt(a); + + BOOST_MATH_INSTRUMENT_VARIABLE(ra); + + T w = a + s * ra + (s * s -1) / 3; + w += (s_3 - 7 * s) / (36 * ra); + w -= (3 * s_4 + 7 * s_2 - 16) / (810 * a); + w += (9 * s_5 + 256 * s_3 - 433 * s) / (38880 * a * ra); + + BOOST_MATH_INSTRUMENT_VARIABLE(w); + + if((a >= 500) && (fabs(1 - w / a) < 1e-6)) + { + result = w; + *p_has_10_digits = true; + BOOST_MATH_INSTRUMENT_VARIABLE(result); + } + else if (p > 0.5) + { + if(w < 3 * a) + { + result = w; + BOOST_MATH_INSTRUMENT_VARIABLE(result); + } + else + { + T D = (std::max)(T(2), T(a * (a - 1))); + T lg = boost::math::lgamma(a, pol); + T lb = log(q) + lg; + if(lb < -D * 2.3) + { + // DiDonato and Morris Eq 25: + T y = -lb; + T c1 = (a - 1) * log(y); + T c1_2 = c1 * c1; + T c1_3 = c1_2 * c1; + T c1_4 = c1_2 * c1_2; + T a_2 = a * a; + T a_3 = a_2 * a; + + T c2 = (a - 1) * (1 + c1); + T c3 = (a - 1) * (-(c1_2 / 2) + (a - 2) * c1 + (3 * a - 5) / 2); + T c4 = (a - 1) * ((c1_3 / 3) - (3 * a - 5) * c1_2 / 2 + (a_2 - 6 * a + 7) * c1 + (11 * a_2 - 46 * a + 47) / 6); + T c5 = (a - 1) * (-(c1_4 / 4) + + (11 * a - 17) * c1_3 / 6 + + (-3 * a_2 + 13 * a -13) * c1_2 + + (2 * a_3 - 25 * a_2 + 72 * a - 61) * c1 / 2 + + (25 * a_3 - 195 * a_2 + 477 * a - 379) / 12); + + T y_2 = y * y; + T y_3 = y_2 * y; + T y_4 = y_2 * y_2; + result = y + c1 + (c2 / y) + (c3 / y_2) + (c4 / y_3) + (c5 / y_4); + BOOST_MATH_INSTRUMENT_VARIABLE(result); + } + else + { + // DiDonato and Morris Eq 33: + T u = -lb + (a - 1) * log(w) - log(1 + (1 - a) / (1 + w)); + result = -lb + (a - 1) * log(u) - log(1 + (1 - a) / (1 + u)); + BOOST_MATH_INSTRUMENT_VARIABLE(result); + } + } + } + else + { + T z = w; + T ap1 = a + 1; + if(w < 0.15f * ap1) + { + // DiDonato and Morris Eq 35: + T v = log(p) + boost::math::lgamma(ap1, pol); + T s = 1; + z = exp((v + w) / a); + s = boost::math::log1p(z / ap1 * (1 + z / (a + 2))); + z = exp((v + z - s) / a); + z = exp((v + z - s) / a); + s = boost::math::log1p(z / ap1 * (1 + z / (a + 2) * (1 + z / (a + 3)))); + z = exp((v + z - s) / a); + BOOST_MATH_INSTRUMENT_VARIABLE(z); + } + + if((z <= 0.01 * ap1) || (z > 0.7 * ap1)) + { + result = z; + if(z <= 0.002 * ap1) + *p_has_10_digits = true; + BOOST_MATH_INSTRUMENT_VARIABLE(result); + } + else + { + // DiDonato and Morris Eq 36: + T ls = log(didonato_SN(a, z, 100, T(1e-4))); + T v = log(p) + boost::math::lgamma(ap1, pol); + z = exp((v + z - ls) / a); + result = z * (1 - (a * log(z) - z - v + ls) / (a - z)); + + BOOST_MATH_INSTRUMENT_VARIABLE(result); + } + } + } + return result; +} + +template <class T, class Policy> +struct gamma_p_inverse_func +{ + gamma_p_inverse_func(T a_, T p_, bool inv) : a(a_), p(p_), invert(inv) + { + // + // If p is too near 1 then P(x) - p suffers from cancellation + // errors causing our root-finding algorithms to "thrash", better + // to invert in this case and calculate Q(x) - (1-p) instead. + // + // Of course if p is *very* close to 1, then the answer we get will + // be inaccurate anyway (because there's not enough information in p) + // but at least we will converge on the (inaccurate) answer quickly. + // + if(p > 0.9) + { + p = 1 - p; + invert = !invert; + } + } + + std::tr1::tuple<T, T, T> operator()(const T& x)const + { + BOOST_FPU_EXCEPTION_GUARD + // + // Calculate P(x) - p and the first two derivates, or if the invert + // flag is set, then Q(x) - q and it's derivatives. + // + typedef typename policies::evaluation<T, Policy>::type value_type; + typedef typename lanczos::lanczos<T, Policy>::type evaluation_type; + typedef typename policies::normalise< + Policy, + policies::promote_float<false>, + policies::promote_double<false>, + policies::discrete_quantile<>, + policies::assert_undefined<> >::type forwarding_policy; + + BOOST_MATH_STD_USING // For ADL of std functions. + + T f, f1; + value_type ft; + f = static_cast<T>(boost::math::detail::gamma_incomplete_imp( + static_cast<value_type>(a), + static_cast<value_type>(x), + true, invert, + forwarding_policy(), &ft)); + f1 = static_cast<T>(ft); + T f2; + T div = (a - x - 1) / x; + f2 = f1; + if((fabs(div) > 1) && (tools::max_value<T>() / fabs(div) < f2)) + { + // overflow: + f2 = -tools::max_value<T>() / 2; + } + else + { + f2 *= div; + } + + if(invert) + { + f1 = -f1; + f2 = -f2; + } + + return std::tr1::make_tuple(f - p, f1, f2); + } +private: + T a, p; + bool invert; +}; + +template <class T, class Policy> +T gamma_p_inv_imp(T a, T p, const Policy& pol) +{ + BOOST_MATH_STD_USING // ADL of std functions. + + static const char* function = "boost::math::gamma_p_inv<%1%>(%1%, %1%)"; + + BOOST_MATH_INSTRUMENT_VARIABLE(a); + BOOST_MATH_INSTRUMENT_VARIABLE(p); + + if(a <= 0) + policies::raise_domain_error<T>(function, "Argument a in the incomplete gamma function inverse must be >= 0 (got a=%1%).", a, pol); + if((p < 0) || (p > 1)) + policies::raise_domain_error<T>(function, "Probabilty must be in the range [0,1] in the incomplete gamma function inverse (got p=%1%).", p, pol); + if(p == 1) + return tools::max_value<T>(); + if(p == 0) + return 0; + bool has_10_digits; + T guess = detail::find_inverse_gamma<T>(a, p, 1 - p, pol, &has_10_digits); + if((policies::digits<T, Policy>() <= 36) && has_10_digits) + return guess; + T lower = tools::min_value<T>(); + if(guess <= lower) + guess = tools::min_value<T>(); + BOOST_MATH_INSTRUMENT_VARIABLE(guess); + // + // Work out how many digits to converge to, normally this is + // 2/3 of the digits in T, but if the first derivative is very + // large convergence is slow, so we'll bump it up to full + // precision to prevent premature termination of the root-finding routine. + // + unsigned digits = policies::digits<T, Policy>(); + if(digits < 30) + { + digits *= 2; + digits /= 3; + } + else + { + digits /= 2; + digits -= 1; + } + if((a < 0.125) && (fabs(gamma_p_derivative(a, guess, pol)) > 1 / sqrt(tools::epsilon<T>()))) + digits = policies::digits<T, Policy>() - 2; + // + // Go ahead and iterate: + // + boost::uintmax_t max_iter = policies::get_max_root_iterations<Policy>(); + guess = tools::halley_iterate( + detail::gamma_p_inverse_func<T, Policy>(a, p, false), + guess, + lower, + tools::max_value<T>(), + digits, + max_iter); + policies::check_root_iterations(function, max_iter, pol); + BOOST_MATH_INSTRUMENT_VARIABLE(guess); + if(guess == lower) + guess = policies::raise_underflow_error<T>(function, "Expected result known to be non-zero, but is smaller than the smallest available number.", pol); + return guess; +} + +template <class T, class Policy> +T gamma_q_inv_imp(T a, T q, const Policy& pol) +{ + BOOST_MATH_STD_USING // ADL of std functions. + + static const char* function = "boost::math::gamma_q_inv<%1%>(%1%, %1%)"; + + if(a <= 0) + policies::raise_domain_error<T>(function, "Argument a in the incomplete gamma function inverse must be >= 0 (got a=%1%).", a, pol); + if((q < 0) || (q > 1)) + policies::raise_domain_error<T>(function, "Probabilty must be in the range [0,1] in the incomplete gamma function inverse (got q=%1%).", q, pol); + if(q == 0) + return tools::max_value<T>(); + if(q == 1) + return 0; + bool has_10_digits; + T guess = detail::find_inverse_gamma<T>(a, 1 - q, q, pol, &has_10_digits); + if((policies::digits<T, Policy>() <= 36) && has_10_digits) + return guess; + T lower = tools::min_value<T>(); + if(guess <= lower) + guess = tools::min_value<T>(); + // + // Work out how many digits to converge to, normally this is + // 2/3 of the digits in T, but if the first derivative is very + // large convergence is slow, so we'll bump it up to full + // precision to prevent premature termination of the root-finding routine. + // + unsigned digits = policies::digits<T, Policy>(); + if(digits < 30) + { + digits *= 2; + digits /= 3; + } + else + { + digits /= 2; + digits -= 1; + } + if((a < 0.125) && (fabs(gamma_p_derivative(a, guess, pol)) > 1 / sqrt(tools::epsilon<T>()))) + digits = policies::digits<T, Policy>(); + // + // Go ahead and iterate: + // + boost::uintmax_t max_iter = policies::get_max_root_iterations<Policy>(); + guess = tools::halley_iterate( + detail::gamma_p_inverse_func<T, Policy>(a, q, true), + guess, + lower, + tools::max_value<T>(), + digits, + max_iter); + policies::check_root_iterations(function, max_iter, pol); + if(guess == lower) + guess = policies::raise_underflow_error<T>(function, "Expected result known to be non-zero, but is smaller than the smallest available number.", pol); + return guess; +} + +} // namespace detail + +template <class T1, class T2, class Policy> +inline typename tools::promote_args<T1, T2>::type + gamma_p_inv(T1 a, T2 p, const Policy& pol) +{ + typedef typename tools::promote_args<T1, T2>::type result_type; + return detail::gamma_p_inv_imp( + static_cast<result_type>(a), + static_cast<result_type>(p), pol); +} + +template <class T1, class T2, class Policy> +inline typename tools::promote_args<T1, T2>::type + gamma_q_inv(T1 a, T2 p, const Policy& pol) +{ + typedef typename tools::promote_args<T1, T2>::type result_type; + return detail::gamma_q_inv_imp( + static_cast<result_type>(a), + static_cast<result_type>(p), pol); +} + +template <class T1, class T2> +inline typename tools::promote_args<T1, T2>::type + gamma_p_inv(T1 a, T2 p) +{ + return gamma_p_inv(a, p, policies::policy<>()); +} + +template <class T1, class T2> +inline typename tools::promote_args<T1, T2>::type + gamma_q_inv(T1 a, T2 p) +{ + return gamma_q_inv(a, p, policies::policy<>()); +} + +} // namespace math +} // namespace boost + +#endif // BOOST_MATH_SPECIAL_FUNCTIONS_IGAMMA_INVERSE_HPP + + + diff --git a/Utilities/BGL/boost/math/special_functions/detail/igamma_large.hpp b/Utilities/BGL/boost/math/special_functions/detail/igamma_large.hpp new file mode 100644 index 0000000000000000000000000000000000000000..f1dff2d79665336634ac277f7b3b0591f5aa7b35 --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/detail/igamma_large.hpp @@ -0,0 +1,769 @@ +// Copyright John Maddock 2006. +// Use, modification and distribution are subject to 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) +// +// This file implements the asymptotic expansions of the incomplete +// gamma functions P(a, x) and Q(a, x), used when a is large and +// x ~ a. +// +// The primary reference is: +// +// "The Asymptotic Expansion of the Incomplete Gamma Functions" +// N. M. Temme. +// Siam J. Math Anal. Vol 10 No 4, July 1979, p757. +// +// A different way of evaluating these expansions, +// plus a lot of very useful background information is in: +// +// "A Set of Algorithms For the Incomplete Gamma Functions." +// N. M. Temme. +// Probability in the Engineering and Informational Sciences, +// 8, 1994, 291. +// +// An alternative implementation is in: +// +// "Computation of the Incomplete Gamma Function Ratios and their Inverse." +// A. R. Didonato and A. H. Morris. +// ACM TOMS, Vol 12, No 4, Dec 1986, p377. +// +// There are various versions of the same code below, each accurate +// to a different precision. To understand the code, refer to Didonato +// and Morris, from Eq 17 and 18 onwards. +// +// The coefficients used here are not taken from Didonato and Morris: +// the domain over which these expansions are used is slightly different +// to theirs, and their constants are not quite accurate enough for +// 128-bit long double's. Instead the coefficients were calculated +// using the methods described by Temme p762 from Eq 3.8 onwards. +// The values obtained agree with those obtained by Didonato and Morris +// (at least to the first 30 digits that they provide). +// At double precision the degrees of polynomial required for full +// machine precision are close to those recomended to Didonato and Morris, +// but of course many more terms are needed for larger types. +// +#ifndef BOOST_MATH_DETAIL_IGAMMA_LARGE +#define BOOST_MATH_DETAIL_IGAMMA_LARGE + +#ifdef _MSC_VER +#pragma once +#endif + +namespace boost{ namespace math{ namespace detail{ + +// This version will never be called (at runtime), it's a stub used +// when T is unsuitable to be passed to these routines: +// +template <class T, class Policy> +inline T igamma_temme_large(T, T, const Policy& /* pol */, mpl::int_<0> const *) +{ + // stub function, should never actually be called + BOOST_ASSERT(0); + return 0; +} +// +// This version is accurate for up to 64-bit mantissa's, +// (80-bit long double, or 10^-20). +// +template <class T, class Policy> +T igamma_temme_large(T a, T x, const Policy& pol, mpl::int_<64> const *) +{ + BOOST_MATH_STD_USING // ADL of std functions + T sigma = (x - a) / a; + T phi = -boost::math::log1pmx(sigma, pol); + T y = a * phi; + T z = sqrt(2 * phi); + if(x < a) + z = -z; + + T workspace[13]; + + static const T C0[] = { + -0.333333333333333333333L, + 0.0833333333333333333333L, + -0.0148148148148148148148L, + 0.00115740740740740740741L, + 0.000352733686067019400353L, + -0.0001787551440329218107L, + 0.39192631785224377817e-4L, + -0.218544851067999216147e-5L, + -0.18540622107151599607e-5L, + 0.829671134095308600502e-6L, + -0.176659527368260793044e-6L, + 0.670785354340149858037e-8L, + 0.102618097842403080426e-7L, + -0.438203601845335318655e-8L, + 0.914769958223679023418e-9L, + -0.255141939949462497669e-10L, + -0.583077213255042506746e-10L, + 0.243619480206674162437e-10L, + -0.502766928011417558909e-11L, + }; + workspace[0] = tools::evaluate_polynomial(C0, z); + + static const T C1[] = { + -0.00185185185185185185185L, + -0.00347222222222222222222L, + 0.00264550264550264550265L, + -0.000990226337448559670782L, + 0.000205761316872427983539L, + -0.40187757201646090535e-6L, + -0.18098550334489977837e-4L, + 0.764916091608111008464e-5L, + -0.161209008945634460038e-5L, + 0.464712780280743434226e-8L, + 0.137863344691572095931e-6L, + -0.575254560351770496402e-7L, + 0.119516285997781473243e-7L, + -0.175432417197476476238e-10L, + -0.100915437106004126275e-8L, + 0.416279299184258263623e-9L, + -0.856390702649298063807e-10L, + }; + workspace[1] = tools::evaluate_polynomial(C1, z); + + static const T C2[] = { + 0.00413359788359788359788L, + -0.00268132716049382716049L, + 0.000771604938271604938272L, + 0.200938786008230452675e-5L, + -0.000107366532263651605215L, + 0.529234488291201254164e-4L, + -0.127606351886187277134e-4L, + 0.342357873409613807419e-7L, + 0.137219573090629332056e-5L, + -0.629899213838005502291e-6L, + 0.142806142060642417916e-6L, + -0.204770984219908660149e-9L, + -0.140925299108675210533e-7L, + 0.622897408492202203356e-8L, + -0.136704883966171134993e-8L, + }; + workspace[2] = tools::evaluate_polynomial(C2, z); + + static const T C3[] = { + 0.000649434156378600823045L, + 0.000229472093621399176955L, + -0.000469189494395255712128L, + 0.000267720632062838852962L, + -0.756180167188397641073e-4L, + -0.239650511386729665193e-6L, + 0.110826541153473023615e-4L, + -0.56749528269915965675e-5L, + 0.142309007324358839146e-5L, + -0.278610802915281422406e-10L, + -0.169584040919302772899e-6L, + 0.809946490538808236335e-7L, + -0.191111684859736540607e-7L, + }; + workspace[3] = tools::evaluate_polynomial(C3, z); + + static const T C4[] = { + -0.000861888290916711698605L, + 0.000784039221720066627474L, + -0.000299072480303190179733L, + -0.146384525788434181781e-5L, + 0.664149821546512218666e-4L, + -0.396836504717943466443e-4L, + 0.113757269706784190981e-4L, + 0.250749722623753280165e-9L, + -0.169541495365583060147e-5L, + 0.890750753220530968883e-6L, + -0.229293483400080487057e-6L, + }; + workspace[4] = tools::evaluate_polynomial(C4, z); + + static const T C5[] = { + -0.000336798553366358150309L, + -0.697281375836585777429e-4L, + 0.000277275324495939207873L, + -0.000199325705161888477003L, + 0.679778047793720783882e-4L, + 0.141906292064396701483e-6L, + -0.135940481897686932785e-4L, + 0.801847025633420153972e-5L, + -0.229148117650809517038e-5L, + }; + workspace[5] = tools::evaluate_polynomial(C5, z); + + static const T C6[] = { + 0.000531307936463992223166L, + -0.000592166437353693882865L, + 0.000270878209671804482771L, + 0.790235323266032787212e-6L, + -0.815396936756196875093e-4L, + 0.561168275310624965004e-4L, + -0.183291165828433755673e-4L, + -0.307961345060330478256e-8L, + 0.346515536880360908674e-5L, + -0.20291327396058603727e-5L, + 0.57887928631490037089e-6L, + }; + workspace[6] = tools::evaluate_polynomial(C6, z); + + static const T C7[] = { + 0.000344367606892377671254L, + 0.517179090826059219337e-4L, + -0.000334931610811422363117L, + 0.000281269515476323702274L, + -0.000109765822446847310235L, + -0.127410090954844853795e-6L, + 0.277444515115636441571e-4L, + -0.182634888057113326614e-4L, + 0.578769494973505239894e-5L, + }; + workspace[7] = tools::evaluate_polynomial(C7, z); + + static const T C8[] = { + -0.000652623918595309418922L, + 0.000839498720672087279993L, + -0.000438297098541721005061L, + -0.696909145842055197137e-6L, + 0.000166448466420675478374L, + -0.000127835176797692185853L, + 0.462995326369130429061e-4L, + }; + workspace[8] = tools::evaluate_polynomial(C8, z); + + static const T C9[] = { + -0.000596761290192746250124L, + -0.720489541602001055909e-4L, + 0.000678230883766732836162L, + -0.0006401475260262758451L, + 0.000277501076343287044992L, + }; + workspace[9] = tools::evaluate_polynomial(C9, z); + + static const T C10[] = { + 0.00133244544948006563713L, + -0.0019144384985654775265L, + 0.00110893691345966373396L, + }; + workspace[10] = tools::evaluate_polynomial(C10, z); + + static const T C11[] = { + 0.00157972766073083495909L, + 0.000162516262783915816899L, + -0.00206334210355432762645L, + 0.00213896861856890981541L, + -0.00101085593912630031708L, + }; + workspace[11] = tools::evaluate_polynomial(C11, z); + + static const T C12[] = { + -0.00407251211951401664727L, + 0.00640336283380806979482L, + -0.00404101610816766177474L, + }; + workspace[12] = tools::evaluate_polynomial(C12, z); + + T result = tools::evaluate_polynomial(workspace, 1/a); + result *= exp(-y) / sqrt(2 * constants::pi<T>() * a); + if(x < a) + result = -result; + + result += boost::math::erfc(sqrt(y), pol) / 2; + + return result; +} +// +// This one is accurate for 53-bit mantissa's +// (IEEE double precision or 10^-17). +// +template <class T, class Policy> +T igamma_temme_large(T a, T x, const Policy& pol, mpl::int_<53> const *) +{ + BOOST_MATH_STD_USING // ADL of std functions + T sigma = (x - a) / a; + T phi = -boost::math::log1pmx(sigma, pol); + T y = a * phi; + T z = sqrt(2 * phi); + if(x < a) + z = -z; + + T workspace[10]; + + static const T C0[] = { + static_cast<T>(-0.33333333333333333L), + static_cast<T>(0.083333333333333333L), + static_cast<T>(-0.014814814814814815L), + static_cast<T>(0.0011574074074074074L), + static_cast<T>(0.0003527336860670194L), + static_cast<T>(-0.00017875514403292181L), + static_cast<T>(0.39192631785224378e-4L), + static_cast<T>(-0.21854485106799922e-5L), + static_cast<T>(-0.185406221071516e-5L), + static_cast<T>(0.8296711340953086e-6L), + static_cast<T>(-0.17665952736826079e-6L), + static_cast<T>(0.67078535434014986e-8L), + static_cast<T>(0.10261809784240308e-7L), + static_cast<T>(-0.43820360184533532e-8L), + static_cast<T>(0.91476995822367902e-9L), + }; + workspace[0] = tools::evaluate_polynomial(C0, z); + + static const T C1[] = { + static_cast<T>(-0.0018518518518518519L), + static_cast<T>(-0.0034722222222222222L), + static_cast<T>(0.0026455026455026455L), + static_cast<T>(-0.00099022633744855967L), + static_cast<T>(0.00020576131687242798L), + static_cast<T>(-0.40187757201646091e-6L), + static_cast<T>(-0.18098550334489978e-4L), + static_cast<T>(0.76491609160811101e-5L), + static_cast<T>(-0.16120900894563446e-5L), + static_cast<T>(0.46471278028074343e-8L), + static_cast<T>(0.1378633446915721e-6L), + static_cast<T>(-0.5752545603517705e-7L), + static_cast<T>(0.11951628599778147e-7L), + }; + workspace[1] = tools::evaluate_polynomial(C1, z); + + static const T C2[] = { + static_cast<T>(0.0041335978835978836L), + static_cast<T>(-0.0026813271604938272L), + static_cast<T>(0.00077160493827160494L), + static_cast<T>(0.20093878600823045e-5L), + static_cast<T>(-0.00010736653226365161L), + static_cast<T>(0.52923448829120125e-4L), + static_cast<T>(-0.12760635188618728e-4L), + static_cast<T>(0.34235787340961381e-7L), + static_cast<T>(0.13721957309062933e-5L), + static_cast<T>(-0.6298992138380055e-6L), + static_cast<T>(0.14280614206064242e-6L), + }; + workspace[2] = tools::evaluate_polynomial(C2, z); + + static const T C3[] = { + static_cast<T>(0.00064943415637860082L), + static_cast<T>(0.00022947209362139918L), + static_cast<T>(-0.00046918949439525571L), + static_cast<T>(0.00026772063206283885L), + static_cast<T>(-0.75618016718839764e-4L), + static_cast<T>(-0.23965051138672967e-6L), + static_cast<T>(0.11082654115347302e-4L), + static_cast<T>(-0.56749528269915966e-5L), + static_cast<T>(0.14230900732435884e-5L), + }; + workspace[3] = tools::evaluate_polynomial(C3, z); + + static const T C4[] = { + static_cast<T>(-0.0008618882909167117L), + static_cast<T>(0.00078403922172006663L), + static_cast<T>(-0.00029907248030319018L), + static_cast<T>(-0.14638452578843418e-5L), + static_cast<T>(0.66414982154651222e-4L), + static_cast<T>(-0.39683650471794347e-4L), + static_cast<T>(0.11375726970678419e-4L), + }; + workspace[4] = tools::evaluate_polynomial(C4, z); + + static const T C5[] = { + static_cast<T>(-0.00033679855336635815L), + static_cast<T>(-0.69728137583658578e-4L), + static_cast<T>(0.00027727532449593921L), + static_cast<T>(-0.00019932570516188848L), + static_cast<T>(0.67977804779372078e-4L), + static_cast<T>(0.1419062920643967e-6L), + static_cast<T>(-0.13594048189768693e-4L), + static_cast<T>(0.80184702563342015e-5L), + static_cast<T>(-0.22914811765080952e-5L), + }; + workspace[5] = tools::evaluate_polynomial(C5, z); + + static const T C6[] = { + static_cast<T>(0.00053130793646399222L), + static_cast<T>(-0.00059216643735369388L), + static_cast<T>(0.00027087820967180448L), + static_cast<T>(0.79023532326603279e-6L), + static_cast<T>(-0.81539693675619688e-4L), + static_cast<T>(0.56116827531062497e-4L), + static_cast<T>(-0.18329116582843376e-4L), + }; + workspace[6] = tools::evaluate_polynomial(C6, z); + + static const T C7[] = { + static_cast<T>(0.00034436760689237767L), + static_cast<T>(0.51717909082605922e-4L), + static_cast<T>(-0.00033493161081142236L), + static_cast<T>(0.0002812695154763237L), + static_cast<T>(-0.00010976582244684731L), + }; + workspace[7] = tools::evaluate_polynomial(C7, z); + + static const T C8[] = { + static_cast<T>(-0.00065262391859530942L), + static_cast<T>(0.00083949872067208728L), + static_cast<T>(-0.00043829709854172101L), + }; + workspace[8] = tools::evaluate_polynomial(C8, z); + workspace[9] = static_cast<T>(-0.00059676129019274625L); + + T result = tools::evaluate_polynomial(workspace, 1/a); + result *= exp(-y) / sqrt(2 * constants::pi<T>() * a); + if(x < a) + result = -result; + + result += boost::math::erfc(sqrt(y), pol) / 2; + + return result; +} +// +// This one is accurate for 24-bit mantissa's +// (IEEE float precision, or 10^-8) +// +template <class T, class Policy> +T igamma_temme_large(T a, T x, const Policy& pol, mpl::int_<24> const *) +{ + BOOST_MATH_STD_USING // ADL of std functions + T sigma = (x - a) / a; + T phi = -boost::math::log1pmx(sigma, pol); + T y = a * phi; + T z = sqrt(2 * phi); + if(x < a) + z = -z; + + T workspace[3]; + + static const T C0[] = { + static_cast<T>(-0.333333333L), + static_cast<T>(0.0833333333L), + static_cast<T>(-0.0148148148L), + static_cast<T>(0.00115740741L), + static_cast<T>(0.000352733686L), + static_cast<T>(-0.000178755144L), + static_cast<T>(0.391926318e-4L), + }; + workspace[0] = tools::evaluate_polynomial(C0, z); + + static const T C1[] = { + static_cast<T>(-0.00185185185L), + static_cast<T>(-0.00347222222L), + static_cast<T>(0.00264550265L), + static_cast<T>(-0.000990226337L), + static_cast<T>(0.000205761317L), + }; + workspace[1] = tools::evaluate_polynomial(C1, z); + + static const T C2[] = { + static_cast<T>(0.00413359788L), + static_cast<T>(-0.00268132716L), + static_cast<T>(0.000771604938L), + }; + workspace[2] = tools::evaluate_polynomial(C2, z); + + T result = tools::evaluate_polynomial(workspace, 1/a); + result *= exp(-y) / sqrt(2 * constants::pi<T>() * a); + if(x < a) + result = -result; + + result += boost::math::erfc(sqrt(y), pol) / 2; + + return result; +} +// +// And finally, a version for 113-bit mantissa's +// (128-bit long doubles, or 10^-34). +// Note this one has been optimised for a > 200 +// It's use for a < 200 is not recomended, that would +// require many more terms in the polynomials. +// +template <class T, class Policy> +T igamma_temme_large(T a, T x, const Policy& pol, mpl::int_<113> const *) +{ + BOOST_MATH_STD_USING // ADL of std functions + T sigma = (x - a) / a; + T phi = -boost::math::log1pmx(sigma, pol); + T y = a * phi; + T z = sqrt(2 * phi); + if(x < a) + z = -z; + + T workspace[14]; + + static const T C0[] = { + -0.333333333333333333333333333333333333L, + 0.0833333333333333333333333333333333333L, + -0.0148148148148148148148148148148148148L, + 0.00115740740740740740740740740740740741L, + 0.0003527336860670194003527336860670194L, + -0.000178755144032921810699588477366255144L, + 0.391926317852243778169704095630021556e-4L, + -0.218544851067999216147364295512443661e-5L, + -0.185406221071515996070179883622956325e-5L, + 0.829671134095308600501624213166443227e-6L, + -0.17665952736826079304360054245742403e-6L, + 0.670785354340149858036939710029613572e-8L, + 0.102618097842403080425739573227252951e-7L, + -0.438203601845335318655297462244719123e-8L, + 0.914769958223679023418248817633113681e-9L, + -0.255141939949462497668779537993887013e-10L, + -0.583077213255042506746408945040035798e-10L, + 0.243619480206674162436940696707789943e-10L, + -0.502766928011417558909054985925744366e-11L, + 0.110043920319561347708374174497293411e-12L, + 0.337176326240098537882769884169200185e-12L, + -0.13923887224181620659193661848957998e-12L, + 0.285348938070474432039669099052828299e-13L, + -0.513911183424257261899064580300494205e-15L, + -0.197522882943494428353962401580710912e-14L, + 0.809952115670456133407115668702575255e-15L, + -0.165225312163981618191514820265351162e-15L, + 0.253054300974788842327061090060267385e-17L, + 0.116869397385595765888230876507793475e-16L, + -0.477003704982048475822167804084816597e-17L, + 0.969912605905623712420709685898585354e-18L, + }; + workspace[0] = tools::evaluate_polynomial(C0, z); + + static const T C1[] = { + -0.00185185185185185185185185185185185185L, + -0.00347222222222222222222222222222222222L, + 0.0026455026455026455026455026455026455L, + -0.000990226337448559670781893004115226337L, + 0.000205761316872427983539094650205761317L, + -0.401877572016460905349794238683127572e-6L, + -0.180985503344899778370285914867533523e-4L, + 0.76491609160811100846374214980916921e-5L, + -0.16120900894563446003775221882217767e-5L, + 0.464712780280743434226135033938722401e-8L, + 0.137863344691572095931187533077488877e-6L, + -0.575254560351770496402194531835048307e-7L, + 0.119516285997781473243076536699698169e-7L, + -0.175432417197476476237547551202312502e-10L, + -0.100915437106004126274577504686681675e-8L, + 0.416279299184258263623372347219858628e-9L, + -0.856390702649298063807431562579670208e-10L, + 0.606721510160475861512701762169919581e-13L, + 0.716249896481148539007961017165545733e-11L, + -0.293318664377143711740636683615595403e-11L, + 0.599669636568368872330374527568788909e-12L, + -0.216717865273233141017100472779701734e-15L, + -0.497833997236926164052815522048108548e-13L, + 0.202916288237134247736694804325894226e-13L, + -0.413125571381061004935108332558187111e-14L, + 0.828651623988309644380188591057589316e-18L, + 0.341003088693333279336339355910600992e-15L, + -0.138541953028939715357034547426313703e-15L, + 0.281234665322887466568860332727259483e-16L, + }; + workspace[1] = tools::evaluate_polynomial(C1, z); + + static const T C2[] = { + 0.0041335978835978835978835978835978836L, + -0.00268132716049382716049382716049382716L, + 0.000771604938271604938271604938271604938L, + 0.200938786008230452674897119341563786e-5L, + -0.000107366532263651605215391223621676297L, + 0.529234488291201254164217127180090143e-4L, + -0.127606351886187277133779191392360117e-4L, + 0.34235787340961380741902003904747389e-7L, + 0.137219573090629332055943852926020279e-5L, + -0.629899213838005502290672234278391876e-6L, + 0.142806142060642417915846008822771748e-6L, + -0.204770984219908660149195854409200226e-9L, + -0.140925299108675210532930244154315272e-7L, + 0.622897408492202203356394293530327112e-8L, + -0.136704883966171134992724380284402402e-8L, + 0.942835615901467819547711211663208075e-12L, + 0.128722524000893180595479368872770442e-9L, + -0.556459561343633211465414765894951439e-10L, + 0.119759355463669810035898150310311343e-10L, + -0.416897822518386350403836626692480096e-14L, + -0.109406404278845944099299008640802908e-11L, + 0.4662239946390135746326204922464679e-12L, + -0.990510576390690597844122258212382301e-13L, + 0.189318767683735145056885183170630169e-16L, + 0.885922187259112726176031067028740667e-14L, + -0.373782039804640545306560251777191937e-14L, + 0.786883363903515525774088394065960751e-15L, + }; + workspace[2] = tools::evaluate_polynomial(C2, z); + + static const T C3[] = { + 0.000649434156378600823045267489711934156L, + 0.000229472093621399176954732510288065844L, + -0.000469189494395255712128140111679206329L, + 0.000267720632062838852962309752433209223L, + -0.756180167188397641072538191879755666e-4L, + -0.239650511386729665193314027333231723e-6L, + 0.110826541153473023614770299726861227e-4L, + -0.567495282699159656749963105701560205e-5L, + 0.14230900732435883914551894470580433e-5L, + -0.278610802915281422405802158211174452e-10L, + -0.16958404091930277289864168795820267e-6L, + 0.809946490538808236335278504852724081e-7L, + -0.191111684859736540606728140872727635e-7L, + 0.239286204398081179686413514022282056e-11L, + 0.206201318154887984369925818486654549e-8L, + -0.946049666185513217375417988510192814e-9L, + 0.215410497757749078380130268468744512e-9L, + -0.138882333681390304603424682490735291e-13L, + -0.218947616819639394064123400466489455e-10L, + 0.979099895117168512568262802255883368e-11L, + -0.217821918801809621153859472011393244e-11L, + 0.62088195734079014258166361684972205e-16L, + 0.212697836327973697696702537114614471e-12L, + -0.934468879151743333127396765626749473e-13L, + 0.204536712267828493249215913063207436e-13L, + }; + workspace[3] = tools::evaluate_polynomial(C3, z); + + static const T C4[] = { + -0.000861888290916711698604702719929057378L, + 0.00078403922172006662747403488144228885L, + -0.000299072480303190179733389609932819809L, + -0.146384525788434181781232535690697556e-5L, + 0.664149821546512218665853782451862013e-4L, + -0.396836504717943466443123507595386882e-4L, + 0.113757269706784190980552042885831759e-4L, + 0.250749722623753280165221942390057007e-9L, + -0.169541495365583060147164356781525752e-5L, + 0.890750753220530968882898422505515924e-6L, + -0.229293483400080487057216364891158518e-6L, + 0.295679413754404904696572852500004588e-10L, + 0.288658297427087836297341274604184504e-7L, + -0.141897394378032193894774303903982717e-7L, + 0.344635804994648970659527720474194356e-8L, + -0.230245171745280671320192735850147087e-12L, + -0.394092330280464052750697640085291799e-9L, + 0.186023389685045019134258533045185639e-9L, + -0.435632300505661804380678327446262424e-10L, + 0.127860010162962312660550463349930726e-14L, + 0.467927502665791946200382739991760062e-11L, + -0.214924647061348285410535341910721086e-11L, + 0.490881561480965216323649688463984082e-12L, + }; + workspace[4] = tools::evaluate_polynomial(C4, z); + + static const T C5[] = { + -0.000336798553366358150308767592718210002L, + -0.697281375836585777429398828575783308e-4L, + 0.00027727532449593920787336425196507501L, + -0.000199325705161888477003360405280844238L, + 0.679778047793720783881640176604435742e-4L, + 0.141906292064396701483392727105575757e-6L, + -0.135940481897686932784583938837504469e-4L, + 0.80184702563342015397192571980419684e-5L, + -0.229148117650809517038048790128781806e-5L, + -0.325247355129845395166230137750005047e-9L, + 0.346528464910852649559195496827579815e-6L, + -0.184471871911713432765322367374920978e-6L, + 0.482409670378941807563762631738989002e-7L, + -0.179894667217435153025754291716644314e-13L, + -0.630619450001352343517516981425944698e-8L, + 0.316241762877456793773762181540969623e-8L, + -0.784092425369742929000839303523267545e-9L, + }; + workspace[5] = tools::evaluate_polynomial(C5, z); + + static const T C6[] = { + 0.00053130793646399222316574854297762391L, + -0.000592166437353693882864836225604401187L, + 0.000270878209671804482771279183488328692L, + 0.790235323266032787212032944390816666e-6L, + -0.815396936756196875092890088464682624e-4L, + 0.561168275310624965003775619041471695e-4L, + -0.183291165828433755673259749374098313e-4L, + -0.307961345060330478256414192546677006e-8L, + 0.346515536880360908673728529745376913e-5L, + -0.202913273960586037269527254582695285e-5L, + 0.578879286314900370889997586203187687e-6L, + 0.233863067382665698933480579231637609e-12L, + -0.88286007463304835250508524317926246e-7L, + 0.474359588804081278032150770595852426e-7L, + -0.125454150207103824457130611214783073e-7L, + }; + workspace[6] = tools::evaluate_polynomial(C6, z); + + static const T C7[] = { + 0.000344367606892377671254279625108523655L, + 0.517179090826059219337057843002058823e-4L, + -0.000334931610811422363116635090580012327L, + 0.000281269515476323702273722110707777978L, + -0.000109765822446847310235396824500789005L, + -0.127410090954844853794579954588107623e-6L, + 0.277444515115636441570715073933712622e-4L, + -0.182634888057113326614324442681892723e-4L, + 0.578769494973505239894178121070843383e-5L, + 0.493875893393627039981813418398565502e-9L, + -0.105953670140260427338098566209633945e-5L, + 0.616671437611040747858836254004890765e-6L, + -0.175629733590604619378669693914265388e-6L, + }; + workspace[7] = tools::evaluate_polynomial(C7, z); + + static const T C8[] = { + -0.000652623918595309418922034919726622692L, + 0.000839498720672087279993357516764983445L, + -0.000438297098541721005061087953050560377L, + -0.696909145842055197136911097362072702e-6L, + 0.00016644846642067547837384572662326101L, + -0.000127835176797692185853344001461664247L, + 0.462995326369130429061361032704489636e-4L, + 0.455790986792270771162749294232219616e-8L, + -0.105952711258051954718238500312872328e-4L, + 0.678334290486516662273073740749269432e-5L, + -0.210754766662588042469972680229376445e-5L, + }; + workspace[8] = tools::evaluate_polynomial(C8, z); + + static const T C9[] = { + -0.000596761290192746250124390067179459605L, + -0.720489541602001055908571930225015052e-4L, + 0.000678230883766732836161951166000673426L, + -0.000640147526026275845100045652582354779L, + 0.000277501076343287044992374518205845463L, + 0.181970083804651510461686554030325202e-6L, + -0.847950711706850318239732559632810086e-4L, + 0.610519208250153101764709122740859458e-4L, + -0.210739201834048624082975255893773306e-4L, + }; + workspace[9] = tools::evaluate_polynomial(C9, z); + + static const T C10[] = { + 0.00133244544948006563712694993432717968L, + -0.00191443849856547752650089885832852254L, + 0.0011089369134596637339607446329267522L, + 0.993240412264229896742295262075817566e-6L, + -0.000508745012930931989848393025305956774L, + 0.00042735056665392884328432271160040444L, + -0.000168588537679107988033552814662382059L, + }; + workspace[10] = tools::evaluate_polynomial(C10, z); + + static const T C11[] = { + 0.00157972766073083495908785631307733022L, + 0.000162516262783915816898635123980270998L, + -0.00206334210355432762645284467690276817L, + 0.00213896861856890981541061922797693947L, + -0.00101085593912630031708085801712479376L, + }; + workspace[11] = tools::evaluate_polynomial(C11, z); + + static const T C12[] = { + -0.00407251211951401664727281097914544601L, + 0.00640336283380806979482363809026579583L, + -0.00404101610816766177473974858518094879L, + }; + workspace[12] = tools::evaluate_polynomial(C12, z); + workspace[13] = -0.0059475779383993002845382844736066323L; + + T result = tools::evaluate_polynomial(workspace, 1/a); + result *= exp(-y) / sqrt(2 * constants::pi<T>() * a); + if(x < a) + result = -result; + + result += boost::math::erfc(sqrt(y), pol) / 2; + + return result; +} + + +} // namespace detail +} // namespace math +} // namespace math + + +#endif // BOOST_MATH_DETAIL_IGAMMA_LARGE + diff --git a/Utilities/BGL/boost/math/special_functions/detail/lanczos_sse2.hpp b/Utilities/BGL/boost/math/special_functions/detail/lanczos_sse2.hpp new file mode 100644 index 0000000000000000000000000000000000000000..4c50ee99d39d378749a1ef4749ea28d8a2b5a232 --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/detail/lanczos_sse2.hpp @@ -0,0 +1,201 @@ +// (C) Copyright John Maddock 2006. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_SPECIAL_FUNCTIONS_LANCZOS_SSE2 +#define BOOST_MATH_SPECIAL_FUNCTIONS_LANCZOS_SSE2 + +#ifdef _MSC_VER +#pragma once +#endif + +#include <emmintrin.h> + +#if defined(__GNUC__) || defined(__PGI) +#define ALIGN16 __attribute__((aligned(16))) +#else +#define ALIGN16 __declspec(align(16)) +#endif + +namespace boost{ namespace math{ namespace lanczos{ + +template <> +inline double lanczos13m53::lanczos_sum<double>(const double& x) +{ + static const ALIGN16 double coeff[26] = { + static_cast<double>(2.506628274631000270164908177133837338626L), + static_cast<double>(1u), + static_cast<double>(210.8242777515793458725097339207133627117L), + static_cast<double>(66u), + static_cast<double>(8071.672002365816210638002902272250613822L), + static_cast<double>(1925u), + static_cast<double>(186056.2653952234950402949897160456992822L), + static_cast<double>(32670u), + static_cast<double>(2876370.628935372441225409051620849613599L), + static_cast<double>(357423u), + static_cast<double>(31426415.58540019438061423162831820536287L), + static_cast<double>(2637558u), + static_cast<double>(248874557.8620541565114603864132294232163L), + static_cast<double>(13339535u), + static_cast<double>(1439720407.311721673663223072794912393972L), + static_cast<double>(45995730u), + static_cast<double>(6039542586.35202800506429164430729792107L), + static_cast<double>(105258076u), + static_cast<double>(17921034426.03720969991975575445893111267L), + static_cast<double>(150917976u), + static_cast<double>(35711959237.35566804944018545154716670596L), + static_cast<double>(120543840u), + static_cast<double>(42919803642.64909876895789904700198885093L), + static_cast<double>(39916800u), + static_cast<double>(23531376880.41075968857200767445163675473L), + static_cast<double>(0u) + }; + register __m128d vx = _mm_load1_pd(&x); + register __m128d sum_even = _mm_load_pd(coeff); + register __m128d sum_odd = _mm_load_pd(coeff+2); + register __m128d nc_odd, nc_even; + register __m128d vx2 = _mm_mul_pd(vx, vx); + + sum_even = _mm_mul_pd(sum_even, vx2); + nc_even = _mm_load_pd(coeff + 4); + sum_odd = _mm_mul_pd(sum_odd, vx2); + nc_odd = _mm_load_pd(coeff + 6); + sum_even = _mm_add_pd(sum_even, nc_even); + sum_odd = _mm_add_pd(sum_odd, nc_odd); + + sum_even = _mm_mul_pd(sum_even, vx2); + nc_even = _mm_load_pd(coeff + 8); + sum_odd = _mm_mul_pd(sum_odd, vx2); + nc_odd = _mm_load_pd(coeff + 10); + sum_even = _mm_add_pd(sum_even, nc_even); + sum_odd = _mm_add_pd(sum_odd, nc_odd); + + sum_even = _mm_mul_pd(sum_even, vx2); + nc_even = _mm_load_pd(coeff + 12); + sum_odd = _mm_mul_pd(sum_odd, vx2); + nc_odd = _mm_load_pd(coeff + 14); + sum_even = _mm_add_pd(sum_even, nc_even); + sum_odd = _mm_add_pd(sum_odd, nc_odd); + + sum_even = _mm_mul_pd(sum_even, vx2); + nc_even = _mm_load_pd(coeff + 16); + sum_odd = _mm_mul_pd(sum_odd, vx2); + nc_odd = _mm_load_pd(coeff + 18); + sum_even = _mm_add_pd(sum_even, nc_even); + sum_odd = _mm_add_pd(sum_odd, nc_odd); + + sum_even = _mm_mul_pd(sum_even, vx2); + nc_even = _mm_load_pd(coeff + 20); + sum_odd = _mm_mul_pd(sum_odd, vx2); + nc_odd = _mm_load_pd(coeff + 22); + sum_even = _mm_add_pd(sum_even, nc_even); + sum_odd = _mm_add_pd(sum_odd, nc_odd); + + sum_even = _mm_mul_pd(sum_even, vx2); + nc_even = _mm_load_pd(coeff + 24); + sum_odd = _mm_mul_pd(sum_odd, vx); + sum_even = _mm_add_pd(sum_even, nc_even); + sum_even = _mm_add_pd(sum_even, sum_odd); + + + double ALIGN16 t[2]; + _mm_store_pd(t, sum_even); + + return t[0] / t[1]; +} + +template <> +inline double lanczos13m53::lanczos_sum_expG_scaled<double>(const double& x) +{ + static const ALIGN16 double coeff[26] = { + static_cast<double>(0.006061842346248906525783753964555936883222L), + static_cast<double>(1u), + static_cast<double>(0.5098416655656676188125178644804694509993L), + static_cast<double>(66u), + static_cast<double>(19.51992788247617482847860966235652136208L), + static_cast<double>(1925u), + static_cast<double>(449.9445569063168119446858607650988409623L), + static_cast<double>(32670u), + static_cast<double>(6955.999602515376140356310115515198987526L), + static_cast<double>(357423u), + static_cast<double>(75999.29304014542649875303443598909137092L), + static_cast<double>(2637558u), + static_cast<double>(601859.6171681098786670226533699352302507L), + static_cast<double>(13339535u), + static_cast<double>(3481712.15498064590882071018964774556468L), + static_cast<double>(45995730u), + static_cast<double>(14605578.08768506808414169982791359218571L), + static_cast<double>(105258076u), + static_cast<double>(43338889.32467613834773723740590533316085L), + static_cast<double>(150917976u), + static_cast<double>(86363131.28813859145546927288977868422342L), + static_cast<double>(120543840u), + static_cast<double>(103794043.1163445451906271053616070238554L), + static_cast<double>(39916800u), + static_cast<double>(56906521.91347156388090791033559122686859L), + static_cast<double>(0u) + }; + register __m128d vx = _mm_load1_pd(&x); + register __m128d sum_even = _mm_load_pd(coeff); + register __m128d sum_odd = _mm_load_pd(coeff+2); + register __m128d nc_odd, nc_even; + register __m128d vx2 = _mm_mul_pd(vx, vx); + + sum_even = _mm_mul_pd(sum_even, vx2); + nc_even = _mm_load_pd(coeff + 4); + sum_odd = _mm_mul_pd(sum_odd, vx2); + nc_odd = _mm_load_pd(coeff + 6); + sum_even = _mm_add_pd(sum_even, nc_even); + sum_odd = _mm_add_pd(sum_odd, nc_odd); + + sum_even = _mm_mul_pd(sum_even, vx2); + nc_even = _mm_load_pd(coeff + 8); + sum_odd = _mm_mul_pd(sum_odd, vx2); + nc_odd = _mm_load_pd(coeff + 10); + sum_even = _mm_add_pd(sum_even, nc_even); + sum_odd = _mm_add_pd(sum_odd, nc_odd); + + sum_even = _mm_mul_pd(sum_even, vx2); + nc_even = _mm_load_pd(coeff + 12); + sum_odd = _mm_mul_pd(sum_odd, vx2); + nc_odd = _mm_load_pd(coeff + 14); + sum_even = _mm_add_pd(sum_even, nc_even); + sum_odd = _mm_add_pd(sum_odd, nc_odd); + + sum_even = _mm_mul_pd(sum_even, vx2); + nc_even = _mm_load_pd(coeff + 16); + sum_odd = _mm_mul_pd(sum_odd, vx2); + nc_odd = _mm_load_pd(coeff + 18); + sum_even = _mm_add_pd(sum_even, nc_even); + sum_odd = _mm_add_pd(sum_odd, nc_odd); + + sum_even = _mm_mul_pd(sum_even, vx2); + nc_even = _mm_load_pd(coeff + 20); + sum_odd = _mm_mul_pd(sum_odd, vx2); + nc_odd = _mm_load_pd(coeff + 22); + sum_even = _mm_add_pd(sum_even, nc_even); + sum_odd = _mm_add_pd(sum_odd, nc_odd); + + sum_even = _mm_mul_pd(sum_even, vx2); + nc_even = _mm_load_pd(coeff + 24); + sum_odd = _mm_mul_pd(sum_odd, vx); + sum_even = _mm_add_pd(sum_even, nc_even); + sum_even = _mm_add_pd(sum_even, sum_odd); + + + double ALIGN16 t[2]; + _mm_store_pd(t, sum_even); + + return t[0] / t[1]; +} + +} // namespace lanczos +} // namespace math +} // namespace boost + +#endif // BOOST_MATH_SPECIAL_FUNCTIONS_LANCZOS + + + + diff --git a/Utilities/BGL/boost/math/special_functions/detail/lgamma_small.hpp b/Utilities/BGL/boost/math/special_functions/detail/lgamma_small.hpp new file mode 100644 index 0000000000000000000000000000000000000000..18d37cac9805cc9bd024407b996caaa5e15b4306 --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/detail/lgamma_small.hpp @@ -0,0 +1,512 @@ +// (C) Copyright John Maddock 2006. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_SPECIAL_FUNCTIONS_DETAIL_LGAMMA_SMALL +#define BOOST_MATH_SPECIAL_FUNCTIONS_DETAIL_LGAMMA_SMALL + +#ifdef _MSC_VER +#pragma once +#endif + +namespace boost{ namespace math{ namespace detail{ + +// +// lgamma for small arguments: +// +template <class T, class Policy, class L> +T lgamma_small_imp(T z, T zm1, T zm2, const mpl::int_<64>&, const Policy& /* l */, const L&) +{ + // This version uses rational approximations for small + // values of z accurate enough for 64-bit mantissas + // (80-bit long doubles), works well for 53-bit doubles as well. + // L is only used to select the Lanczos function. + + BOOST_MATH_STD_USING // for ADL of std names + T result = 0; + if(z < tools::epsilon<T>()) + { + result = -log(z); + } + else if((zm1 == 0) || (zm2 == 0)) + { + // nothing to do, result is zero.... + } + else if(z > 2) + { + // + // Begin by performing argument reduction until + // z is in [2,3): + // + if(z >= 3) + { + do + { + z -= 1; + zm2 -= 1; + result += log(z); + }while(z >= 3); + // Update zm2, we need it below: + zm2 = z - 2; + } + + // + // Use the following form: + // + // lgamma(z) = (z-2)(z+1)(Y + R(z-2)) + // + // where R(z-2) is a rational approximation optimised for + // low absolute error - as long as it's absolute error + // is small compared to the constant Y - then any rounding + // error in it's computation will get wiped out. + // + // R(z-2) has the following properties: + // + // At double: Max error found: 4.231e-18 + // At long double: Max error found: 1.987e-21 + // Maximum Deviation Found (approximation error): 5.900e-24 + // + static const T P[] = { + static_cast<T>(-0.180355685678449379109e-1L), + static_cast<T>(0.25126649619989678683e-1L), + static_cast<T>(0.494103151567532234274e-1L), + static_cast<T>(0.172491608709613993966e-1L), + static_cast<T>(-0.259453563205438108893e-3L), + static_cast<T>(-0.541009869215204396339e-3L), + static_cast<T>(-0.324588649825948492091e-4L) + }; + static const T Q[] = { + static_cast<T>(0.1e1), + static_cast<T>(0.196202987197795200688e1L), + static_cast<T>(0.148019669424231326694e1L), + static_cast<T>(0.541391432071720958364e0L), + static_cast<T>(0.988504251128010129477e-1L), + static_cast<T>(0.82130967464889339326e-2L), + static_cast<T>(0.224936291922115757597e-3L), + static_cast<T>(-0.223352763208617092964e-6L) + }; + + static const float Y = 0.158963680267333984375e0f; + + T r = zm2 * (z + 1); + T R = tools::evaluate_polynomial(P, zm2); + R /= tools::evaluate_polynomial(Q, zm2); + + result += r * Y + r * R; + } + else + { + // + // If z is less than 1 use recurrance to shift to + // z in the interval [1,2]: + // + if(z < 1) + { + result += -log(z); + zm2 = zm1; + zm1 = z; + z += 1; + } + // + // Two approximations, on for z in [1,1.5] and + // one for z in [1.5,2]: + // + if(z <= 1.5) + { + // + // Use the following form: + // + // lgamma(z) = (z-1)(z-2)(Y + R(z-1)) + // + // where R(z-1) is a rational approximation optimised for + // low absolute error - as long as it's absolute error + // is small compared to the constant Y - then any rounding + // error in it's computation will get wiped out. + // + // R(z-1) has the following properties: + // + // At double precision: Max error found: 1.230011e-17 + // At 80-bit long double precision: Max error found: 5.631355e-21 + // Maximum Deviation Found: 3.139e-021 + // Expected Error Term: 3.139e-021 + + // + static const float Y = 0.52815341949462890625f; + + static const T P[] = { + static_cast<T>(0.490622454069039543534e-1L), + static_cast<T>(-0.969117530159521214579e-1L), + static_cast<T>(-0.414983358359495381969e0L), + static_cast<T>(-0.406567124211938417342e0L), + static_cast<T>(-0.158413586390692192217e0L), + static_cast<T>(-0.240149820648571559892e-1L), + static_cast<T>(-0.100346687696279557415e-2L) + }; + static const T Q[] = { + static_cast<T>(0.1e1L), + static_cast<T>(0.302349829846463038743e1L), + static_cast<T>(0.348739585360723852576e1L), + static_cast<T>(0.191415588274426679201e1L), + static_cast<T>(0.507137738614363510846e0L), + static_cast<T>(0.577039722690451849648e-1L), + static_cast<T>(0.195768102601107189171e-2L) + }; + + T r = tools::evaluate_polynomial(P, zm1) / tools::evaluate_polynomial(Q, zm1); + T prefix = zm1 * zm2; + + result += prefix * Y + prefix * r; + } + else + { + // + // Use the following form: + // + // lgamma(z) = (2-z)(1-z)(Y + R(2-z)) + // + // where R(2-z) is a rational approximation optimised for + // low absolute error - as long as it's absolute error + // is small compared to the constant Y - then any rounding + // error in it's computation will get wiped out. + // + // R(2-z) has the following properties: + // + // At double precision, max error found: 1.797565e-17 + // At 80-bit long double precision, max error found: 9.306419e-21 + // Maximum Deviation Found: 2.151e-021 + // Expected Error Term: 2.150e-021 + // + static const float Y = 0.452017307281494140625f; + + static const T P[] = { + static_cast<T>(-0.292329721830270012337e-1L), + static_cast<T>(0.144216267757192309184e0L), + static_cast<T>(-0.142440390738631274135e0L), + static_cast<T>(0.542809694055053558157e-1L), + static_cast<T>(-0.850535976868336437746e-2L), + static_cast<T>(0.431171342679297331241e-3L) + }; + static const T Q[] = { + static_cast<T>(0.1e1), + static_cast<T>(-0.150169356054485044494e1L), + static_cast<T>(0.846973248876495016101e0L), + static_cast<T>(-0.220095151814995745555e0L), + static_cast<T>(0.25582797155975869989e-1L), + static_cast<T>(-0.100666795539143372762e-2L), + static_cast<T>(-0.827193521891290553639e-6L) + }; + T r = zm2 * zm1; + T R = tools::evaluate_polynomial(P, -zm2) / tools::evaluate_polynomial(Q, -zm2); + + result += r * Y + r * R; + } + } + return result; +} +template <class T, class Policy, class L> +T lgamma_small_imp(T z, T zm1, T zm2, const mpl::int_<113>&, const Policy& /* l */, const L&) +{ + // + // This version uses rational approximations for small + // values of z accurate enough for 113-bit mantissas + // (128-bit long doubles). + // + BOOST_MATH_STD_USING // for ADL of std names + T result = 0; + if(z < tools::epsilon<T>()) + { + result = -log(z); + BOOST_MATH_INSTRUMENT_CODE(result); + } + else if((zm1 == 0) || (zm2 == 0)) + { + // nothing to do, result is zero.... + } + else if(z > 2) + { + // + // Begin by performing argument reduction until + // z is in [2,3): + // + if(z >= 3) + { + do + { + z -= 1; + result += log(z); + }while(z >= 3); + zm2 = z - 2; + } + BOOST_MATH_INSTRUMENT_CODE(zm2); + BOOST_MATH_INSTRUMENT_CODE(z); + BOOST_MATH_INSTRUMENT_CODE(result); + + // + // Use the following form: + // + // lgamma(z) = (z-2)(z+1)(Y + R(z-2)) + // + // where R(z-2) is a rational approximation optimised for + // low absolute error - as long as it's absolute error + // is small compared to the constant Y - then any rounding + // error in it's computation will get wiped out. + // + // Maximum Deviation Found (approximation error) 3.73e-37 + + static const T P[] = { + -0.018035568567844937910504030027467476655L, + 0.013841458273109517271750705401202404195L, + 0.062031842739486600078866923383017722399L, + 0.052518418329052161202007865149435256093L, + 0.01881718142472784129191838493267755758L, + 0.0025104830367021839316463675028524702846L, + -0.00021043176101831873281848891452678568311L, + -0.00010249622350908722793327719494037981166L, + -0.11381479670982006841716879074288176994e-4L, + -0.49999811718089980992888533630523892389e-6L, + -0.70529798686542184668416911331718963364e-8L + }; + static const T Q[] = { + 1L, + 2.5877485070422317542808137697939233685L, + 2.8797959228352591788629602533153837126L, + 1.8030885955284082026405495275461180977L, + 0.69774331297747390169238306148355428436L, + 0.17261566063277623942044077039756583802L, + 0.02729301254544230229429621192443000121L, + 0.0026776425891195270663133581960016620433L, + 0.00015244249160486584591370355730402168106L, + 0.43997034032479866020546814475414346627e-5L, + 0.46295080708455613044541885534408170934e-7L, + -0.93326638207459533682980757982834180952e-11L, + 0.42316456553164995177177407325292867513e-13L + }; + + T R = tools::evaluate_polynomial(P, zm2); + R /= tools::evaluate_polynomial(Q, zm2); + + static const float Y = 0.158963680267333984375F; + + T r = zm2 * (z + 1); + + result += r * Y + r * R; + BOOST_MATH_INSTRUMENT_CODE(result); + } + else + { + // + // If z is less than 1 use recurrance to shift to + // z in the interval [1,2]: + // + if(z < 1) + { + result += -log(z); + zm2 = zm1; + zm1 = z; + z += 1; + } + BOOST_MATH_INSTRUMENT_CODE(result); + BOOST_MATH_INSTRUMENT_CODE(z); + BOOST_MATH_INSTRUMENT_CODE(zm2); + // + // Three approximations, on for z in [1,1.35], [1.35,1.625] and [1.625,1] + // + if(z <= 1.35) + { + // + // Use the following form: + // + // lgamma(z) = (z-1)(z-2)(Y + R(z-1)) + // + // where R(z-1) is a rational approximation optimised for + // low absolute error - as long as it's absolute error + // is small compared to the constant Y - then any rounding + // error in it's computation will get wiped out. + // + // R(z-1) has the following properties: + // + // Maximum Deviation Found (approximation error) 1.659e-36 + // Expected Error Term (theoretical error) 1.343e-36 + // Max error found at 128-bit long double precision 1.007e-35 + // + static const float Y = 0.54076099395751953125f; + + static const T P[] = { + 0.036454670944013329356512090082402429697L, + -0.066235835556476033710068679907798799959L, + -0.67492399795577182387312206593595565371L, + -1.4345555263962411429855341651960000166L, + -1.4894319559821365820516771951249649563L, + -0.87210277668067964629483299712322411566L, + -0.29602090537771744401524080430529369136L, + -0.0561832587517836908929331992218879676L, + -0.0053236785487328044334381502530383140443L, + -0.00018629360291358130461736386077971890789L, + -0.10164985672213178500790406939467614498e-6L, + 0.13680157145361387405588201461036338274e-8L + }; + static const T Q[] = { + 1, + 4.9106336261005990534095838574132225599L, + 10.258804800866438510889341082793078432L, + 11.88588976846826108836629960537466889L, + 8.3455000546999704314454891036700998428L, + 3.6428823682421746343233362007194282703L, + 0.97465989807254572142266753052776132252L, + 0.15121052897097822172763084966793352524L, + 0.012017363555383555123769849654484594893L, + 0.0003583032812720649835431669893011257277L + }; + + T r = tools::evaluate_polynomial(P, zm1) / tools::evaluate_polynomial(Q, zm1); + T prefix = zm1 * zm2; + + result += prefix * Y + prefix * r; + BOOST_MATH_INSTRUMENT_CODE(result); + } + else if(z <= 1.625) + { + // + // Use the following form: + // + // lgamma(z) = (2-z)(1-z)(Y + R(2-z)) + // + // where R(2-z) is a rational approximation optimised for + // low absolute error - as long as it's absolute error + // is small compared to the constant Y - then any rounding + // error in it's computation will get wiped out. + // + // R(2-z) has the following properties: + // + // Max error found at 128-bit long double precision 9.634e-36 + // Maximum Deviation Found (approximation error) 1.538e-37 + // Expected Error Term (theoretical error) 2.350e-38 + // + static const float Y = 0.483787059783935546875f; + + static const T P[] = { + -0.017977422421608624353488126610933005432L, + 0.18484528905298309555089509029244135703L, + -0.40401251514859546989565001431430884082L, + 0.40277179799147356461954182877921388182L, + -0.21993421441282936476709677700477598816L, + 0.069595742223850248095697771331107571011L, + -0.012681481427699686635516772923547347328L, + 0.0012489322866834830413292771335113136034L, + -0.57058739515423112045108068834668269608e-4L, + 0.8207548771933585614380644961342925976e-6L + }; + static const T Q[] = { + 1, + -2.9629552288944259229543137757200262073L, + 3.7118380799042118987185957298964772755L, + -2.5569815272165399297600586376727357187L, + 1.0546764918220835097855665680632153367L, + -0.26574021300894401276478730940980810831L, + 0.03996289731752081380552901986471233462L, + -0.0033398680924544836817826046380586480873L, + 0.00013288854760548251757651556792598235735L, + -0.17194794958274081373243161848194745111e-5L + }; + T r = zm2 * zm1; + T R = tools::evaluate_polynomial(P, 0.625 - zm1) / tools::evaluate_polynomial(Q, 0.625 - zm1); + + result += r * Y + r * R; + BOOST_MATH_INSTRUMENT_CODE(result); + } + else + { + // + // Same form as above. + // + // Max error found (at 128-bit long double precision) 1.831e-35 + // Maximum Deviation Found (approximation error) 8.588e-36 + // Expected Error Term (theoretical error) 1.458e-36 + // + static const float Y = 0.443811893463134765625f; + + static const T P[] = { + -0.021027558364667626231512090082402429494L, + 0.15128811104498736604523586803722368377L, + -0.26249631480066246699388544451126410278L, + 0.21148748610533489823742352180628489742L, + -0.093964130697489071999873506148104370633L, + 0.024292059227009051652542804957550866827L, + -0.0036284453226534839926304745756906117066L, + 0.0002939230129315195346843036254392485984L, + -0.11088589183158123733132268042570710338e-4L, + 0.13240510580220763969511741896361984162e-6L + }; + static const T Q[] = { + 1, + -2.4240003754444040525462170802796471996L, + 2.4868383476933178722203278602342786002L, + -1.4047068395206343375520721509193698547L, + 0.47583809087867443858344765659065773369L, + -0.09865724264554556400463655444270700132L, + 0.012238223514176587501074150988445109735L, + -0.00084625068418239194670614419707491797097L, + 0.2796574430456237061420839429225710602e-4L, + -0.30202973883316730694433702165188835331e-6L + }; + // (2 - x) * (1 - x) * (c + R(2 - x)) + T r = zm2 * zm1; + T R = tools::evaluate_polynomial(P, -zm2) / tools::evaluate_polynomial(Q, -zm2); + + result += r * Y + r * R; + BOOST_MATH_INSTRUMENT_CODE(result); + } + } + BOOST_MATH_INSTRUMENT_CODE(result); + return result; +} +template <class T, class Policy, class L> +T lgamma_small_imp(T z, T zm1, T zm2, const mpl::int_<0>&, const Policy& pol, const L&) +{ + // + // No rational approximations are available because either + // T has no numeric_limits support (so we can't tell how + // many digits it has), or T has more digits than we know + // what to do with.... we do have a Lanczos approximation + // though, and that can be used to keep errors under control. + // + BOOST_MATH_STD_USING // for ADL of std names + T result = 0; + if(z < tools::epsilon<T>()) + { + result = -log(z); + } + else if(z < 0.5) + { + // taking the log of tgamma reduces the error, no danger of overflow here: + result = log(gamma_imp(z, pol, L())); + } + else if(z >= 3) + { + // taking the log of tgamma reduces the error, no danger of overflow here: + result = log(gamma_imp(z, pol, L())); + } + else if(z >= 1.5) + { + // special case near 2: + T dz = zm2; + result = dz * log((z + L::g() - T(0.5)) / boost::math::constants::e<T>()); + result += boost::math::log1p(dz / (L::g() + T(1.5)), pol) * T(1.5); + result += boost::math::log1p(L::lanczos_sum_near_2(dz), pol); + } + else + { + // special case near 1: + T dz = zm1; + result = dz * log((z + L::g() - T(0.5)) / boost::math::constants::e<T>()); + result += boost::math::log1p(dz / (L::g() + T(0.5)), pol) / 2; + result += boost::math::log1p(L::lanczos_sum_near_1(dz), pol); + } + return result; +} + +}}} // namespaces + +#endif // BOOST_MATH_SPECIAL_FUNCTIONS_DETAIL_LGAMMA_SMALL + diff --git a/Utilities/BGL/boost/math/special_functions/detail/round_fwd.hpp b/Utilities/BGL/boost/math/special_functions/detail/round_fwd.hpp new file mode 100644 index 0000000000000000000000000000000000000000..b24fe4929e932293c856f4bc1a015089e7d9aecd --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/detail/round_fwd.hpp @@ -0,0 +1,80 @@ +// Copyright John Maddock 2008. + +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_SPECIAL_ROUND_FWD_HPP +#define BOOST_MATH_SPECIAL_ROUND_FWD_HPP + +#include <boost/config.hpp> + +#ifdef _MSC_VER +#pragma once +#endif + +namespace boost +{ + namespace math + { + + template <class T, class Policy> + T trunc(const T& v, const Policy& pol); + template <class T> + T trunc(const T& v); + template <class T, class Policy> + int itrunc(const T& v, const Policy& pol); + template <class T> + int itrunc(const T& v); + template <class T, class Policy> + long ltrunc(const T& v, const Policy& pol); + template <class T> + long ltrunc(const T& v); +#ifdef BOOST_HAS_LONG_LONG + template <class T, class Policy> + boost::long_long_type lltrunc(const T& v, const Policy& pol); + template <class T> + boost::long_long_type lltrunc(const T& v); +#endif + template <class T, class Policy> + T round(const T& v, const Policy& pol); + template <class T> + T round(const T& v); + template <class T, class Policy> + int iround(const T& v, const Policy& pol); + template <class T> + int iround(const T& v); + template <class T, class Policy> + long lround(const T& v, const Policy& pol); + template <class T> + long lround(const T& v); +#ifdef BOOST_HAS_LONG_LONG + template <class T, class Policy> + boost::long_long_type llround(const T& v, const Policy& pol); + template <class T> + boost::long_long_type llround(const T& v); +#endif + template <class T, class Policy> + T modf(const T& v, T* ipart, const Policy& pol); + template <class T> + T modf(const T& v, T* ipart); + template <class T, class Policy> + T modf(const T& v, int* ipart, const Policy& pol); + template <class T> + T modf(const T& v, int* ipart); + template <class T, class Policy> + T modf(const T& v, long* ipart, const Policy& pol); + template <class T> + T modf(const T& v, long* ipart); +#ifdef BOOST_HAS_LONG_LONG + template <class T, class Policy> + T modf(const T& v, boost::long_long_type* ipart, const Policy& pol); + template <class T> + T modf(const T& v, boost::long_long_type* ipart); +#endif + + } +} +#endif // BOOST_MATH_SPECIAL_ROUND_FWD_HPP + diff --git a/Utilities/BGL/boost/math/special_functions/detail/simple_complex.hpp b/Utilities/BGL/boost/math/special_functions/detail/simple_complex.hpp new file mode 100644 index 0000000000000000000000000000000000000000..36db26988636148ce3522f5d26cfd7e749ef6bfb --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/detail/simple_complex.hpp @@ -0,0 +1,172 @@ +// Copyright (c) 2007 John Maddock +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_SF_DETAIL_SIMPLE_COMPLEX_HPP +#define BOOST_MATH_SF_DETAIL_SIMPLE_COMPLEX_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +namespace boost{ namespace math{ namespace detail{ namespace sc{ + +template <class T> +class simple_complex +{ +public: + simple_complex() : r(0), i(0) {} + simple_complex(T a) : r(a) {} + template <class U> + simple_complex(U a) : r(a) {} + simple_complex(T a, T b) : r(a), i(b) {} + + simple_complex& operator += (const simple_complex& o) + { + r += o.r; + i += o.i; + return *this; + } + simple_complex& operator -= (const simple_complex& o) + { + r -= o.r; + i -= o.i; + return *this; + } + simple_complex& operator *= (const simple_complex& o) + { + T lr = r * o.r - i * o.i; + T li = i * o.r + r * o.i; + r = lr; + i = li; + return *this; + } + simple_complex& operator /= (const simple_complex& o) + { + BOOST_MATH_STD_USING + T lr; + T li; + if(fabs(o.r) > fabs(o.i)) + { + T rat = o.i / o.r; + lr = r + i * rat; + li = i - r * rat; + rat = o.r + o.i * rat; + lr /= rat; + li /= rat; + } + else + { + T rat = o.r / o.i; + lr = i + r * rat; + li = i * rat - r; + rat = o.r * rat + o.i; + lr /= rat; + li /= rat; + } + r = lr; + i = li; + return *this; + } + bool operator == (const simple_complex& o) + { + return (r == o.r) && (i == o.i); + } + bool operator != (const simple_complex& o) + { + return !((r == o.r) && (i == o.i)); + } + bool operator == (const T& o) + { + return (r == o) && (i == 0); + } + simple_complex& operator += (const T& o) + { + r += o; + return *this; + } + simple_complex& operator -= (const T& o) + { + r -= o; + return *this; + } + simple_complex& operator *= (const T& o) + { + r *= o; + i *= o; + return *this; + } + simple_complex& operator /= (const T& o) + { + r /= o; + i /= o; + return *this; + } + T real()const + { + return r; + } + T imag()const + { + return i; + } +private: + T r, i; +}; + +template <class T> +inline simple_complex<T> operator+(const simple_complex<T>& a, const simple_complex<T>& b) +{ + simple_complex<T> result(a); + result += b; + return result; +} + +template <class T> +inline simple_complex<T> operator-(const simple_complex<T>& a, const simple_complex<T>& b) +{ + simple_complex<T> result(a); + result -= b; + return result; +} + +template <class T> +inline simple_complex<T> operator*(const simple_complex<T>& a, const simple_complex<T>& b) +{ + simple_complex<T> result(a); + result *= b; + return result; +} + +template <class T> +inline simple_complex<T> operator/(const simple_complex<T>& a, const simple_complex<T>& b) +{ + simple_complex<T> result(a); + result /= b; + return result; +} + +template <class T> +inline T real(const simple_complex<T>& c) +{ + return c.real(); +} + +template <class T> +inline T imag(const simple_complex<T>& c) +{ + return c.imag(); +} + +template <class T> +inline T abs(const simple_complex<T>& c) +{ + return hypot(c.real(), c.imag()); +} + +}}}} // namespace + +#endif + + diff --git a/Utilities/BGL/boost/math/special_functions/detail/t_distribution_inv.hpp b/Utilities/BGL/boost/math/special_functions/detail/t_distribution_inv.hpp new file mode 100644 index 0000000000000000000000000000000000000000..402daf8a4d267263b0a862a400b85e599bea5a60 --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/detail/t_distribution_inv.hpp @@ -0,0 +1,541 @@ +// Copyright John Maddock 2007. +// Copyright Paul A. Bristow 2007 +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_SF_DETAIL_INV_T_HPP +#define BOOST_MATH_SF_DETAIL_INV_T_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/math/special_functions/cbrt.hpp> +#include <boost/math/special_functions/round.hpp> +#include <boost/math/special_functions/trunc.hpp> + +namespace boost{ namespace math{ namespace detail{ + +// +// The main method used is due to Hill: +// +// G. W. Hill, Algorithm 396, Student's t-Quantiles, +// Communications of the ACM, 13(10): 619-620, Oct., 1970. +// +template <class T, class Policy> +T inverse_students_t_hill(T ndf, T u, const Policy& pol) +{ + BOOST_MATH_STD_USING + BOOST_ASSERT(u <= 0.5); + + T a, b, c, d, q, x, y; + + if (ndf > 1e20f) + return -boost::math::erfc_inv(2 * u, pol) * constants::root_two<T>(); + + a = 1 / (ndf - 0.5f); + b = 48 / (a * a); + c = ((20700 * a / b - 98) * a - 16) * a + 96.36f; + d = ((94.5f / (b + c) - 3) / b + 1) * sqrt(a * constants::pi<T>() / 2) * ndf; + y = pow(d * 2 * u, 2 / ndf); + + if (y > (0.05f + a)) + { + // + // Asymptotic inverse expansion about normal: + // + x = -boost::math::erfc_inv(2 * u, pol) * constants::root_two<T>(); + y = x * x; + + if (ndf < 5) + c += 0.3f * (ndf - 4.5f) * (x + 0.6f); + c += (((0.05f * d * x - 5) * x - 7) * x - 2) * x + b; + y = (((((0.4f * y + 6.3f) * y + 36) * y + 94.5f) / c - y - 3) / b + 1) * x; + y = boost::math::expm1(a * y * y, pol); + } + else + { + y = ((1 / (((ndf + 6) / (ndf * y) - 0.089f * d - 0.822f) + * (ndf + 2) * 3) + 0.5 / (ndf + 4)) * y - 1) + * (ndf + 1) / (ndf + 2) + 1 / y; + } + q = sqrt(ndf * y); + + return -q; +} +// +// Tail and body series are due to Shaw: +// +// www.mth.kcl.ac.uk/~shaww/web_page/papers/Tdistribution06.pdf +// +// Shaw, W.T., 2006, "Sampling Student's T distribution - use of +// the inverse cumulative distribution function." +// Journal of Computational Finance, Vol 9 Issue 4, pp 37-73, Summer 2006 +// +template <class T, class Policy> +T inverse_students_t_tail_series(T df, T v, const Policy& pol) +{ + BOOST_MATH_STD_USING + // Tail series expansion, see section 6 of Shaw's paper. + // w is calculated using Eq 60: + T w = boost::math::tgamma_delta_ratio(df / 2, constants::half<T>(), pol) + * sqrt(df * constants::pi<T>()) * v; + // define some variables: + T np2 = df + 2; + T np4 = df + 4; + T np6 = df + 6; + // + // Calculate the coefficients d(k), these depend only on the + // number of degrees of freedom df, so at least in theory + // we could tabulate these for fixed df, see p15 of Shaw: + // + T d[7] = { 1, }; + d[1] = -(df + 1) / (2 * np2); + np2 *= (df + 2); + d[2] = -df * (df + 1) * (df + 3) / (8 * np2 * np4); + np2 *= df + 2; + d[3] = -df * (df + 1) * (df + 5) * (((3 * df) + 7) * df -2) / (48 * np2 * np4 * np6); + np2 *= (df + 2); + np4 *= (df + 4); + d[4] = -df * (df + 1) * (df + 7) * + ( (((((15 * df) + 154) * df + 465) * df + 286) * df - 336) * df + 64 ) + / (384 * np2 * np4 * np6 * (df + 8)); + np2 *= (df + 2); + d[5] = -df * (df + 1) * (df + 3) * (df + 9) + * (((((((35 * df + 452) * df + 1573) * df + 600) * df - 2020) * df) + 928) * df -128) + / (1280 * np2 * np4 * np6 * (df + 8) * (df + 10)); + np2 *= (df + 2); + np4 *= (df + 4); + np6 *= (df + 6); + d[6] = -df * (df + 1) * (df + 11) + * ((((((((((((945 * df) + 31506) * df + 425858) * df + 2980236) * df + 11266745) * df + 20675018) * df + 7747124) * df - 22574632) * df - 8565600) * df + 18108416) * df - 7099392) * df + 884736) + / (46080 * np2 * np4 * np6 * (df + 8) * (df + 10) * (df +12)); + // + // Now bring everthing together to provide the result, + // this is Eq 62 of Shaw: + // + T rn = sqrt(df); + T div = pow(rn * w, 1 / df); + T power = div * div; + T result = tools::evaluate_polynomial(d, power); + result *= rn; + result /= div; + return -result; +} + +template <class T, class Policy> +T inverse_students_t_body_series(T df, T u, const Policy& pol) +{ + BOOST_MATH_STD_USING + // + // Body series for small N: + // + // Start with Eq 56 of Shaw: + // + T v = boost::math::tgamma_delta_ratio(df / 2, constants::half<T>(), pol) + * sqrt(df * constants::pi<T>()) * (u - constants::half<T>()); + // + // Workspace for the polynomial coefficients: + // + T c[11] = { 0, 1, }; + // + // Figure out what the coefficients are, note these depend + // only on the degrees of freedom (Eq 57 of Shaw): + // + c[2] = 0.16666666666666666667 + 0.16666666666666666667 / df; + T in = 1 / df; + c[3] = (0.0083333333333333333333 * in + + 0.066666666666666666667) * in + + 0.058333333333333333333; + c[4] = ((0.00019841269841269841270 * in + + 0.0017857142857142857143) * in + + 0.026785714285714285714) * in + + 0.025198412698412698413; + c[5] = (((2.7557319223985890653e10-6 * in + + 0.00037477954144620811287) * in + - 0.0011078042328042328042) * in + + 0.010559964726631393298) * in + + 0.012039792768959435626; + c[6] = ((((2.5052108385441718775e-8 * in + - 0.000062705427288760622094) * in + + 0.00059458674042007375341) * in + - 0.0016095979637646304313) * in + + 0.0061039211560044893378) * in + + 0.0038370059724226390893; + c[7] = (((((1.6059043836821614599e-10 * in + + 0.000015401265401265401265) * in + - 0.00016376804137220803887) * in + + 0.00069084207973096861986) * in + - 0.0012579159844784844785) * in + + 0.0010898206731540064873) * in + + 0.0032177478835464946576; + c[8] = ((((((7.6471637318198164759e-13 * in + - 3.9851014346715404916e-6) * in + + 0.000049255746366361445727) * in + - 0.00024947258047043099953) * in + + 0.00064513046951456342991) * in + - 0.00076245135440323932387) * in + + 0.000033530976880017885309) * in + + 0.0017438262298340009980; + c[9] = (((((((2.8114572543455207632e-15 * in + + 1.0914179173496789432e-6) * in + - 0.000015303004486655377567) * in + + 0.000090867107935219902229) * in + - 0.00029133414466938067350) * in + + 0.00051406605788341121363) * in + - 0.00036307660358786885787) * in + - 0.00031101086326318780412) * in + + 0.00096472747321388644237; + c[10] = ((((((((8.2206352466243297170e-18 * in + - 3.1239569599829868045e-7) * in + + 4.8903045291975346210e-6) * in + - 0.000033202652391372058698) * in + + 0.00012645437628698076975) * in + - 0.00028690924218514613987) * in + + 0.00035764655430568632777) * in + - 0.00010230378073700412687) * in + - 0.00036942667800009661203) * in + + 0.00054229262813129686486; + // + // The result is then a polynomial in v (see Eq 56 of Shaw): + // + return tools::evaluate_odd_polynomial(c, v); +} + +template <class T, class Policy> +T inverse_students_t(T df, T u, T v, const Policy& pol, bool* pexact = 0) +{ + // + // df = number of degrees of freedom. + // u = probablity. + // v = 1 - u. + // l = lanczos type to use. + // + BOOST_MATH_STD_USING + bool invert = false; + T result = 0; + if(pexact) + *pexact = false; + if(u > v) + { + // function is symmetric, invert it: + std::swap(u, v); + invert = true; + } + if((floor(df) == df) && (df < 20)) + { + // + // we have integer degrees of freedom, try for the special + // cases first: + // + T tolerance = ldexp(1.0f, (2 * policies::digits<T, Policy>()) / 3); + + switch(itrunc(df, Policy())) + { + case 1: + { + // + // df = 1 is the same as the Cauchy distribution, see + // Shaw Eq 35: + // + if(u == 0.5) + result = 0; + else + result = -cos(constants::pi<T>() * u) / sin(constants::pi<T>() * u); + if(pexact) + *pexact = true; + break; + } + case 2: + { + // + // df = 2 has an exact result, see Shaw Eq 36: + // + result =(2 * u - 1) / sqrt(2 * u * v); + if(pexact) + *pexact = true; + break; + } + case 4: + { + // + // df = 4 has an exact result, see Shaw Eq 38 & 39: + // + T alpha = 4 * u * v; + T root_alpha = sqrt(alpha); + T r = 4 * cos(acos(root_alpha) / 3) / root_alpha; + T x = sqrt(r - 4); + result = u - 0.5f < 0 ? (T)-x : x; + if(pexact) + *pexact = true; + break; + } + case 6: + { + // + // We get numeric overflow in this area: + // + if(u < 1e-150) + return (invert ? -1 : 1) * inverse_students_t_hill(df, u, pol); + // + // Newton-Raphson iteration of a polynomial case, + // choice of seed value is taken from Shaw's online + // supplement: + // + T a = 4 * (u - u * u);//1 - 4 * (u - 0.5f) * (u - 0.5f); + T b = boost::math::cbrt(a); + static const T c = 0.85498797333834849467655443627193; + T p = 6 * (1 + c * (1 / b - 1)); + T p0; + do{ + T p2 = p * p; + T p4 = p2 * p2; + T p5 = p * p4; + p0 = p; + // next term is given by Eq 41: + p = 2 * (8 * a * p5 - 270 * p2 + 2187) / (5 * (4 * a * p4 - 216 * p - 243)); + }while(fabs((p - p0) / p) > tolerance); + // + // Use Eq 45 to extract the result: + // + p = sqrt(p - df); + result = (u - 0.5f) < 0 ? (T)-p : p; + break; + } +#if 0 + // + // These are Shaw's "exact" but iterative solutions + // for even df, the numerical accuracy of these is + // rather less than Hill's method, so these are disabled + // for now, which is a shame because they are reasonably + // quick to evaluate... + // + case 8: + { + // + // Newton-Raphson iteration of a polynomial case, + // choice of seed value is taken from Shaw's online + // supplement: + // + static const T c8 = 0.85994765706259820318168359251872L; + T a = 4 * (u - u * u); //1 - 4 * (u - 0.5f) * (u - 0.5f); + T b = pow(a, T(1) / 4); + T p = 8 * (1 + c8 * (1 / b - 1)); + T p0 = p; + do{ + T p5 = p * p; + p5 *= p5 * p; + p0 = p; + // Next term is given by Eq 42: + p = 2 * (3 * p + (640 * (160 + p * (24 + p * (p + 4)))) / (-5120 + p * (-2048 - 960 * p + a * p5))) / 7; + }while(fabs((p - p0) / p) > tolerance); + // + // Use Eq 45 to extract the result: + // + p = sqrt(p - df); + result = (u - 0.5f) < 0 ? -p : p; + break; + } + case 10: + { + // + // Newton-Raphson iteration of a polynomial case, + // choice of seed value is taken from Shaw's online + // supplement: + // + static const T c10 = 0.86781292867813396759105692122285L; + T a = 4 * (u - u * u); //1 - 4 * (u - 0.5f) * (u - 0.5f); + T b = pow(a, T(1) / 5); + T p = 10 * (1 + c10 * (1 / b - 1)); + T p0; + do{ + T p6 = p * p; + p6 *= p6 * p6; + p0 = p; + // Next term given by Eq 43: + p = (8 * p) / 9 + (218750 * (21875 + 4 * p * (625 + p * (75 + 2 * p * (5 + p))))) / + (9 * (-68359375 + 8 * p * (-2343750 + p * (-546875 - 175000 * p + 8 * a * p6)))); + }while(fabs((p - p0) / p) > tolerance); + // + // Use Eq 45 to extract the result: + // + p = sqrt(p - df); + result = (u - 0.5f) < 0 ? -p : p; + break; + } +#endif + default: + goto calculate_real; + } + } + else + { +calculate_real: + if(df < 3) + { + // + // Use a roughly linear scheme to choose between Shaw's + // tail series and body series: + // + T crossover = 0.2742f - df * 0.0242143f; + if(u > crossover) + { + result = boost::math::detail::inverse_students_t_body_series(df, u, pol); + } + else + { + result = boost::math::detail::inverse_students_t_tail_series(df, u, pol); + } + } + else + { + // + // Use Hill's method except in the exteme tails + // where we use Shaw's tail series. + // The crossover point is roughly exponential in -df: + // + T crossover = ldexp(1.0f, iround(T(df / -0.654f), pol)); + if(u > crossover) + { + result = boost::math::detail::inverse_students_t_hill(df, u, pol); + } + else + { + result = boost::math::detail::inverse_students_t_tail_series(df, u, pol); + } + } + } + return invert ? (T)-result : result; +} + +template <class T, class Policy> +inline T find_ibeta_inv_from_t_dist(T a, T p, T q, T* py, const Policy& pol) +{ + T u = (p > q) ? T(0.5f - q) / T(2) : T(p / 2); + T v = 1 - u; // u < 0.5 so no cancellation error + T df = a * 2; + T t = boost::math::detail::inverse_students_t(df, u, v, pol); + T x = df / (df + t * t); + *py = t * t / (df + t * t); + return x; +} + +template <class T, class Policy> +inline T fast_students_t_quantile_imp(T df, T p, const Policy& pol, const mpl::false_*) +{ + BOOST_MATH_STD_USING + // + // Need to use inverse incomplete beta to get + // required precision so not so fast: + // + T probability = (p > 0.5) ? 1 - p : p; + T t, x, y; + x = ibeta_inv(df / 2, T(0.5), 2 * probability, &y, pol); + if(df * y > tools::max_value<T>() * x) + t = policies::raise_overflow_error<T>("boost::math::students_t_quantile<%1%>(%1%,%1%)", 0, pol); + else + t = sqrt(df * y / x); + // + // Figure out sign based on the size of p: + // + if(p < 0.5) + t = -t; + return t; +} + +template <class T, class Policy> +T fast_students_t_quantile_imp(T df, T p, const Policy& pol, const mpl::true_*) +{ + BOOST_MATH_STD_USING + bool invert = false; + if((df < 2) && (floor(df) != df)) + return boost::math::detail::fast_students_t_quantile_imp(df, p, pol, static_cast<mpl::false_*>(0)); + if(p > 0.5) + { + p = 1 - p; + invert = true; + } + // + // Get an estimate of the result: + // + bool exact; + T t = inverse_students_t(df, p, 1-p, pol, &exact); + if((t == 0) || exact) + return invert ? -t : t; // can't do better! + // + // Change variables to inverse incomplete beta: + // + T t2 = t * t; + T xb = df / (df + t2); + T y = t2 / (df + t2); + T a = df / 2; + // + // t can be so large that x underflows, + // just return our estimate in that case: + // + if(xb == 0) + return t; + // + // Get incomplete beta and it's derivative: + // + T f1; + T f0 = xb < y ? ibeta_imp(a, constants::half<T>(), xb, pol, false, true, &f1) + : ibeta_imp(constants::half<T>(), a, y, pol, true, true, &f1); + + // Get cdf from incomplete beta result: + T p0 = f0 / 2 - p; + // Get pdf from derivative: + T p1 = f1 * sqrt(y * xb * xb * xb / df); + // + // Second derivative divided by p1: + // + // yacas gives: + // + // In> PrettyForm(Simplify(D(t) (1 + t^2/v) ^ (-(v+1)/2))) + // + // | | v + 1 | | + // | -| ----- + 1 | | + // | | 2 | | + // -| | 2 | | + // | | t | | + // | | -- + 1 | | + // | ( v + 1 ) * | v | * t | + // --------------------------------------------- + // v + // + // Which after some manipulation is: + // + // -p1 * t * (df + 1) / (t^2 + df) + // + T p2 = t * (df + 1) / (t * t + df); + // Halley step: + t = fabs(t); + t += p0 / (p1 + p0 * p2 / 2); + return !invert ? -t : t; +} + +template <class T, class Policy> +inline T fast_students_t_quantile(T df, T p, const Policy& pol) +{ + typedef typename policies::evaluation<T, Policy>::type value_type; + typedef typename policies::normalise< + Policy, + policies::promote_float<false>, + policies::promote_double<false>, + policies::discrete_quantile<>, + policies::assert_undefined<> >::type forwarding_policy; + + typedef mpl::bool_< + (std::numeric_limits<T>::digits <= 53) + && + (std::numeric_limits<T>::is_specialized)> tag_type; + return policies::checked_narrowing_cast<T, forwarding_policy>(fast_students_t_quantile_imp(static_cast<value_type>(df), static_cast<value_type>(p), pol, static_cast<tag_type*>(0)), "boost::math::students_t_quantile<%1%>(%1%,%1%,%1%)"); +} + +}}} // namespaces + +#endif // BOOST_MATH_SF_DETAIL_INV_T_HPP + + + diff --git a/Utilities/BGL/boost/math/special_functions/detail/unchecked_factorial.hpp b/Utilities/BGL/boost/math/special_functions/detail/unchecked_factorial.hpp new file mode 100644 index 0000000000000000000000000000000000000000..dd22052e06750cff584e1ebd4e4951d1d96250ce --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/detail/unchecked_factorial.hpp @@ -0,0 +1,402 @@ +// Copyright John Maddock 2006. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_SP_UC_FACTORIALS_HPP +#define BOOST_MATH_SP_UC_FACTORIALS_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/array.hpp> +#ifdef BOOST_MSVC +#pragma warning(push) // Temporary until lexical cast fixed. +#pragma warning(disable: 4127 4701) +#endif +#include <boost/lexical_cast.hpp> +#ifdef BOOST_MSVC +#pragma warning(pop) +#endif +#include <boost/config/no_tr1/cmath.hpp> +#include <boost/math/special_functions/math_fwd.hpp> + +namespace boost { namespace math +{ +// Forward declarations: +template <class T> +struct max_factorial; + +// efinitions: +template <> +inline float unchecked_factorial<float>(unsigned i BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE_SPEC(float)) +{ + static const boost::array<float, 35> factorials = {{ + 1.0F, + 1.0F, + 2.0F, + 6.0F, + 24.0F, + 120.0F, + 720.0F, + 5040.0F, + 40320.0F, + 362880.0F, + 3628800.0F, + 39916800.0F, + 479001600.0F, + 6227020800.0F, + 87178291200.0F, + 1307674368000.0F, + 20922789888000.0F, + 355687428096000.0F, + 6402373705728000.0F, + 121645100408832000.0F, + 0.243290200817664e19F, + 0.5109094217170944e20F, + 0.112400072777760768e22F, + 0.2585201673888497664e23F, + 0.62044840173323943936e24F, + 0.15511210043330985984e26F, + 0.403291461126605635584e27F, + 0.10888869450418352160768e29F, + 0.304888344611713860501504e30F, + 0.8841761993739701954543616e31F, + 0.26525285981219105863630848e33F, + 0.822283865417792281772556288e34F, + 0.26313083693369353016721801216e36F, + 0.868331761881188649551819440128e37F, + 0.29523279903960414084761860964352e39F, + }}; + + return factorials[i]; +} + +template <> +struct max_factorial<float> +{ + BOOST_STATIC_CONSTANT(unsigned, value = 34); +}; + + +template <> +inline long double unchecked_factorial<long double>(unsigned i BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE_SPEC(long double)) +{ + static const boost::array<long double, 171> factorials = {{ + 1L, + 1L, + 2L, + 6L, + 24L, + 120L, + 720L, + 5040L, + 40320L, + 362880.0L, + 3628800.0L, + 39916800.0L, + 479001600.0L, + 6227020800.0L, + 87178291200.0L, + 1307674368000.0L, + 20922789888000.0L, + 355687428096000.0L, + 6402373705728000.0L, + 121645100408832000.0L, + 0.243290200817664e19L, + 0.5109094217170944e20L, + 0.112400072777760768e22L, + 0.2585201673888497664e23L, + 0.62044840173323943936e24L, + 0.15511210043330985984e26L, + 0.403291461126605635584e27L, + 0.10888869450418352160768e29L, + 0.304888344611713860501504e30L, + 0.8841761993739701954543616e31L, + 0.26525285981219105863630848e33L, + 0.822283865417792281772556288e34L, + 0.26313083693369353016721801216e36L, + 0.868331761881188649551819440128e37L, + 0.29523279903960414084761860964352e39L, + 0.103331479663861449296666513375232e41L, + 0.3719933267899012174679994481508352e42L, + 0.137637530912263450463159795815809024e44L, + 0.5230226174666011117600072241000742912e45L, + 0.203978820811974433586402817399028973568e47L, + 0.815915283247897734345611269596115894272e48L, + 0.3345252661316380710817006205344075166515e50L, + 0.1405006117752879898543142606244511569936e52L, + 0.6041526306337383563735513206851399750726e53L, + 0.265827157478844876804362581101461589032e55L, + 0.1196222208654801945619631614956577150644e57L, + 0.5502622159812088949850305428800254892962e58L, + 0.2586232415111681806429643551536119799692e60L, + 0.1241391559253607267086228904737337503852e62L, + 0.6082818640342675608722521633212953768876e63L, + 0.3041409320171337804361260816606476884438e65L, + 0.1551118753287382280224243016469303211063e67L, + 0.8065817517094387857166063685640376697529e68L, + 0.427488328406002556429801375338939964969e70L, + 0.2308436973392413804720927426830275810833e72L, + 0.1269640335365827592596510084756651695958e74L, + 0.7109985878048634518540456474637249497365e75L, + 0.4052691950487721675568060190543232213498e77L, + 0.2350561331282878571829474910515074683829e79L, + 0.1386831185456898357379390197203894063459e81L, + 0.8320987112741390144276341183223364380754e82L, + 0.507580213877224798800856812176625227226e84L, + 0.3146997326038793752565312235495076408801e86L, + 0.1982608315404440064116146708361898137545e88L, + 0.1268869321858841641034333893351614808029e90L, + 0.8247650592082470666723170306785496252186e91L, + 0.5443449390774430640037292402478427526443e93L, + 0.3647111091818868528824985909660546442717e95L, + 0.2480035542436830599600990418569171581047e97L, + 0.1711224524281413113724683388812728390923e99L, + 0.1197857166996989179607278372168909873646e101L, + 0.8504785885678623175211676442399260102886e102L, + 0.6123445837688608686152407038527467274078e104L, + 0.4470115461512684340891257138125051110077e106L, + 0.3307885441519386412259530282212537821457e108L, + 0.2480914081139539809194647711659403366093e110L, + 0.188549470166605025498793226086114655823e112L, + 0.1451830920282858696340707840863082849837e114L, + 0.1132428117820629783145752115873204622873e116L, + 0.8946182130782975286851441715398316520698e117L, + 0.7156945704626380229481153372318653216558e119L, + 0.5797126020747367985879734231578109105412e121L, + 0.4753643337012841748421382069894049466438e123L, + 0.3945523969720658651189747118012061057144e125L, + 0.3314240134565353266999387579130131288001e127L, + 0.2817104114380550276949479442260611594801e129L, + 0.2422709538367273238176552320344125971528e131L, + 0.210775729837952771721360051869938959523e133L, + 0.1854826422573984391147968456455462843802e135L, + 0.1650795516090846108121691926245361930984e137L, + 0.1485715964481761497309522733620825737886e139L, + 0.1352001527678402962551665687594951421476e141L, + 0.1243841405464130725547532432587355307758e143L, + 0.1156772507081641574759205162306240436215e145L, + 0.1087366156656743080273652852567866010042e147L, + 0.103299784882390592625997020993947270954e149L, + 0.9916779348709496892095714015418938011582e150L, + 0.9619275968248211985332842594956369871234e152L, + 0.942689044888324774562618574305724247381e154L, + 0.9332621544394415268169923885626670049072e156L, + 0.9332621544394415268169923885626670049072e158L, + 0.9425947759838359420851623124482936749562e160L, + 0.9614466715035126609268655586972595484554e162L, + 0.990290071648618040754671525458177334909e164L, + 0.1029901674514562762384858386476504428305e167L, + 0.1081396758240290900504101305800329649721e169L, + 0.1146280563734708354534347384148349428704e171L, + 0.1226520203196137939351751701038733888713e173L, + 0.132464181945182897449989183712183259981e175L, + 0.1443859583202493582204882102462797533793e177L, + 0.1588245541522742940425370312709077287172e179L, + 0.1762952551090244663872161047107075788761e181L, + 0.1974506857221074023536820372759924883413e183L, + 0.2231192748659813646596607021218715118256e185L, + 0.2543559733472187557120132004189335234812e187L, + 0.2925093693493015690688151804817735520034e189L, + 0.339310868445189820119825609358857320324e191L, + 0.396993716080872089540195962949863064779e193L, + 0.4684525849754290656574312362808384164393e195L, + 0.5574585761207605881323431711741977155627e197L, + 0.6689502913449127057588118054090372586753e199L, + 0.8094298525273443739681622845449350829971e201L, + 0.9875044200833601362411579871448208012564e203L, + 0.1214630436702532967576624324188129585545e206L, + 0.1506141741511140879795014161993280686076e208L, + 0.1882677176888926099743767702491600857595e210L, + 0.237217324288004688567714730513941708057e212L, + 0.3012660018457659544809977077527059692324e214L, + 0.3856204823625804217356770659234636406175e216L, + 0.4974504222477287440390234150412680963966e218L, + 0.6466855489220473672507304395536485253155e220L, + 0.8471580690878820510984568758152795681634e222L, + 0.1118248651196004307449963076076169029976e225L, + 0.1487270706090685728908450891181304809868e227L, + 0.1992942746161518876737324194182948445223e229L, + 0.269047270731805048359538766214698040105e231L, + 0.3659042881952548657689727220519893345429e233L, + 0.5012888748274991661034926292112253883237e235L, + 0.6917786472619488492228198283114910358867e237L, + 0.9615723196941089004197195613529725398826e239L, + 0.1346201247571752460587607385894161555836e242L, + 0.1898143759076170969428526414110767793728e244L, + 0.2695364137888162776588507508037290267094e246L, + 0.3854370717180072770521565736493325081944e248L, + 0.5550293832739304789551054660550388118e250L, + 0.80479260574719919448490292577980627711e252L, + 0.1174997204390910823947958271638517164581e255L, + 0.1727245890454638911203498659308620231933e257L, + 0.2556323917872865588581178015776757943262e259L, + 0.380892263763056972698595524350736933546e261L, + 0.571338395644585459047893286526105400319e263L, + 0.8627209774233240431623188626544191544816e265L, + 0.1311335885683452545606724671234717114812e268L, + 0.2006343905095682394778288746989117185662e270L, + 0.308976961384735088795856467036324046592e272L, + 0.4789142901463393876335775239063022722176e274L, + 0.7471062926282894447083809372938315446595e276L, + 0.1172956879426414428192158071551315525115e279L, + 0.1853271869493734796543609753051078529682e281L, + 0.2946702272495038326504339507351214862195e283L, + 0.4714723635992061322406943211761943779512e285L, + 0.7590705053947218729075178570936729485014e287L, + 0.1229694218739449434110178928491750176572e290L, + 0.2004401576545302577599591653441552787813e292L, + 0.3287218585534296227263330311644146572013e294L, + 0.5423910666131588774984495014212841843822e296L, + 0.9003691705778437366474261723593317460744e298L, + 0.1503616514864999040201201707840084015944e301L, + 0.2526075744973198387538018869171341146786e303L, + 0.4269068009004705274939251888899566538069e305L, + 0.7257415615307998967396728211129263114717e307L, + }}; + + return factorials[i]; +} + +template <> +struct max_factorial<long double> +{ + BOOST_STATIC_CONSTANT(unsigned, value = 170); +}; + +template <> +inline double unchecked_factorial<double>(unsigned i BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE_SPEC(double)) +{ + return static_cast<double>(boost::math::unchecked_factorial<long double>(i)); +} + +template <> +struct max_factorial<double> +{ + BOOST_STATIC_CONSTANT(unsigned, + value = ::boost::math::max_factorial<long double>::value); +}; + +template <class T> +inline T unchecked_factorial(unsigned i BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE_SPEC(T)) +{ + static const boost::array<T, 101> factorials = {{ + boost::lexical_cast<T>("1"), + boost::lexical_cast<T>("1"), + boost::lexical_cast<T>("2"), + boost::lexical_cast<T>("6"), + boost::lexical_cast<T>("24"), + boost::lexical_cast<T>("120"), + boost::lexical_cast<T>("720"), + boost::lexical_cast<T>("5040"), + boost::lexical_cast<T>("40320"), + boost::lexical_cast<T>("362880"), + boost::lexical_cast<T>("3628800"), + boost::lexical_cast<T>("39916800"), + boost::lexical_cast<T>("479001600"), + boost::lexical_cast<T>("6227020800"), + boost::lexical_cast<T>("87178291200"), + boost::lexical_cast<T>("1307674368000"), + boost::lexical_cast<T>("20922789888000"), + boost::lexical_cast<T>("355687428096000"), + boost::lexical_cast<T>("6402373705728000"), + boost::lexical_cast<T>("121645100408832000"), + boost::lexical_cast<T>("2432902008176640000"), + boost::lexical_cast<T>("51090942171709440000"), + boost::lexical_cast<T>("1124000727777607680000"), + boost::lexical_cast<T>("25852016738884976640000"), + boost::lexical_cast<T>("620448401733239439360000"), + boost::lexical_cast<T>("15511210043330985984000000"), + boost::lexical_cast<T>("403291461126605635584000000"), + boost::lexical_cast<T>("10888869450418352160768000000"), + boost::lexical_cast<T>("304888344611713860501504000000"), + boost::lexical_cast<T>("8841761993739701954543616000000"), + boost::lexical_cast<T>("265252859812191058636308480000000"), + boost::lexical_cast<T>("8222838654177922817725562880000000"), + boost::lexical_cast<T>("263130836933693530167218012160000000"), + boost::lexical_cast<T>("8683317618811886495518194401280000000"), + boost::lexical_cast<T>("295232799039604140847618609643520000000"), + boost::lexical_cast<T>("10333147966386144929666651337523200000000"), + boost::lexical_cast<T>("371993326789901217467999448150835200000000"), + boost::lexical_cast<T>("13763753091226345046315979581580902400000000"), + boost::lexical_cast<T>("523022617466601111760007224100074291200000000"), + boost::lexical_cast<T>("20397882081197443358640281739902897356800000000"), + boost::lexical_cast<T>("815915283247897734345611269596115894272000000000"), + boost::lexical_cast<T>("33452526613163807108170062053440751665152000000000"), + boost::lexical_cast<T>("1405006117752879898543142606244511569936384000000000"), + boost::lexical_cast<T>("60415263063373835637355132068513997507264512000000000"), + boost::lexical_cast<T>("2658271574788448768043625811014615890319638528000000000"), + boost::lexical_cast<T>("119622220865480194561963161495657715064383733760000000000"), + boost::lexical_cast<T>("5502622159812088949850305428800254892961651752960000000000"), + boost::lexical_cast<T>("258623241511168180642964355153611979969197632389120000000000"), + boost::lexical_cast<T>("12413915592536072670862289047373375038521486354677760000000000"), + boost::lexical_cast<T>("608281864034267560872252163321295376887552831379210240000000000"), + boost::lexical_cast<T>("30414093201713378043612608166064768844377641568960512000000000000"), + boost::lexical_cast<T>("1551118753287382280224243016469303211063259720016986112000000000000"), + boost::lexical_cast<T>("80658175170943878571660636856403766975289505440883277824000000000000"), + boost::lexical_cast<T>("4274883284060025564298013753389399649690343788366813724672000000000000"), + boost::lexical_cast<T>("230843697339241380472092742683027581083278564571807941132288000000000000"), + boost::lexical_cast<T>("12696403353658275925965100847566516959580321051449436762275840000000000000"), + boost::lexical_cast<T>("710998587804863451854045647463724949736497978881168458687447040000000000000"), + boost::lexical_cast<T>("40526919504877216755680601905432322134980384796226602145184481280000000000000"), + boost::lexical_cast<T>("2350561331282878571829474910515074683828862318181142924420699914240000000000000"), + boost::lexical_cast<T>("138683118545689835737939019720389406345902876772687432540821294940160000000000000"), + boost::lexical_cast<T>("8320987112741390144276341183223364380754172606361245952449277696409600000000000000"), + boost::lexical_cast<T>("507580213877224798800856812176625227226004528988036003099405939480985600000000000000"), + boost::lexical_cast<T>("31469973260387937525653122354950764088012280797258232192163168247821107200000000000000"), + boost::lexical_cast<T>("1982608315404440064116146708361898137544773690227268628106279599612729753600000000000000"), + boost::lexical_cast<T>("126886932185884164103433389335161480802865516174545192198801894375214704230400000000000000"), + boost::lexical_cast<T>("8247650592082470666723170306785496252186258551345437492922123134388955774976000000000000000"), + boost::lexical_cast<T>("544344939077443064003729240247842752644293064388798874532860126869671081148416000000000000000"), + boost::lexical_cast<T>("36471110918188685288249859096605464427167635314049524593701628500267962436943872000000000000000"), + boost::lexical_cast<T>("2480035542436830599600990418569171581047399201355367672371710738018221445712183296000000000000000"), + boost::lexical_cast<T>("171122452428141311372468338881272839092270544893520369393648040923257279754140647424000000000000000"), + boost::lexical_cast<T>("11978571669969891796072783721689098736458938142546425857555362864628009582789845319680000000000000000"), + boost::lexical_cast<T>("850478588567862317521167644239926010288584608120796235886430763388588680378079017697280000000000000000"), + boost::lexical_cast<T>("61234458376886086861524070385274672740778091784697328983823014963978384987221689274204160000000000000000"), + boost::lexical_cast<T>("4470115461512684340891257138125051110076800700282905015819080092370422104067183317016903680000000000000000"), + boost::lexical_cast<T>("330788544151938641225953028221253782145683251820934971170611926835411235700971565459250872320000000000000000"), + boost::lexical_cast<T>("24809140811395398091946477116594033660926243886570122837795894512655842677572867409443815424000000000000000000"), + boost::lexical_cast<T>("1885494701666050254987932260861146558230394535379329335672487982961844043495537923117729972224000000000000000000"), + boost::lexical_cast<T>("145183092028285869634070784086308284983740379224208358846781574688061991349156420080065207861248000000000000000000"), + boost::lexical_cast<T>("11324281178206297831457521158732046228731749579488251990048962825668835325234200766245086213177344000000000000000000"), + boost::lexical_cast<T>("894618213078297528685144171539831652069808216779571907213868063227837990693501860533361810841010176000000000000000000"), + boost::lexical_cast<T>("71569457046263802294811533723186532165584657342365752577109445058227039255480148842668944867280814080000000000000000000"), + boost::lexical_cast<T>("5797126020747367985879734231578109105412357244731625958745865049716390179693892056256184534249745940480000000000000000000"), + boost::lexical_cast<T>("475364333701284174842138206989404946643813294067993328617160934076743994734899148613007131808479167119360000000000000000000"), + boost::lexical_cast<T>("39455239697206586511897471180120610571436503407643446275224357528369751562996629334879591940103770870906880000000000000000000"), + boost::lexical_cast<T>("3314240134565353266999387579130131288000666286242049487118846032383059131291716864129885722968716753156177920000000000000000000"), + boost::lexical_cast<T>("281710411438055027694947944226061159480056634330574206405101912752560026159795933451040286452340924018275123200000000000000000000"), + boost::lexical_cast<T>("24227095383672732381765523203441259715284870552429381750838764496720162249742450276789464634901319465571660595200000000000000000000"), + boost::lexical_cast<T>("2107757298379527717213600518699389595229783738061356212322972511214654115727593174080683423236414793504734471782400000000000000000000"), + boost::lexical_cast<T>("185482642257398439114796845645546284380220968949399346684421580986889562184028199319100141244804501828416633516851200000000000000000000"), + boost::lexical_cast<T>("16507955160908461081216919262453619309839666236496541854913520707833171034378509739399912570787600662729080382999756800000000000000000000"), + boost::lexical_cast<T>("1485715964481761497309522733620825737885569961284688766942216863704985393094065876545992131370884059645617234469978112000000000000000000000"), + boost::lexical_cast<T>("135200152767840296255166568759495142147586866476906677791741734597153670771559994765685283954750449427751168336768008192000000000000000000000"), + boost::lexical_cast<T>("12438414054641307255475324325873553077577991715875414356840239582938137710983519518443046123837041347353107486982656753664000000000000000000000"), + boost::lexical_cast<T>("1156772507081641574759205162306240436214753229576413535186142281213246807121467315215203289516844845303838996289387078090752000000000000000000000"), + boost::lexical_cast<T>("108736615665674308027365285256786601004186803580182872307497374434045199869417927630229109214583415458560865651202385340530688000000000000000000000"), + boost::lexical_cast<T>("10329978488239059262599702099394727095397746340117372869212250571234293987594703124871765375385424468563282236864226607350415360000000000000000000000"), + boost::lexical_cast<T>("991677934870949689209571401541893801158183648651267795444376054838492222809091499987689476037000748982075094738965754305639874560000000000000000000000"), + boost::lexical_cast<T>("96192759682482119853328425949563698712343813919172976158104477319333745612481875498805879175589072651261284189679678167647067832320000000000000000000000"), + boost::lexical_cast<T>("9426890448883247745626185743057242473809693764078951663494238777294707070023223798882976159207729119823605850588608460429412647567360000000000000000000000"), + boost::lexical_cast<T>("933262154439441526816992388562667004907159682643816214685929638952175999932299156089414639761565182862536979208272237582511852109168640000000000000000000000"), + boost::lexical_cast<T>("93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000"), + }}; + + return factorials[i]; +} + +template <class T> +struct max_factorial +{ + BOOST_STATIC_CONSTANT(unsigned, value = 100); +}; + +} // namespace math +} // namespace boost + +#endif // BOOST_MATH_SP_UC_FACTORIALS_HPP + diff --git a/Utilities/BGL/boost/math/special_functions/digamma.hpp b/Utilities/BGL/boost/math/special_functions/digamma.hpp new file mode 100644 index 0000000000000000000000000000000000000000..d44792131454181e7addaa055c4fba1578433332 --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/digamma.hpp @@ -0,0 +1,450 @@ +// (C) Copyright John Maddock 2006. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_SF_DIGAMMA_HPP +#define BOOST_MATH_SF_DIGAMMA_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/math/tools/rational.hpp> +#include <boost/math/tools/promotion.hpp> +#include <boost/math/policies/error_handling.hpp> +#include <boost/math/constants/constants.hpp> +#include <boost/mpl/comparison.hpp> + +namespace boost{ +namespace math{ +namespace detail{ +// +// Begin by defining the smallest value for which it is safe to +// use the asymptotic expansion for digamma: +// +inline unsigned digamma_large_lim(const mpl::int_<0>*) +{ return 20; } + +inline unsigned digamma_large_lim(const void*) +{ return 10; } +// +// Implementations of the asymptotic expansion come next, +// the coefficients of the series have been evaluated +// in advance at high precision, and the series truncated +// at the first term that's too small to effect the result. +// Note that the series becomes divergent after a while +// so truncation is very important. +// +// This first one gives 34-digit precision for x >= 20: +// +template <class T> +inline T digamma_imp_large(T x, const mpl::int_<0>*) +{ + BOOST_MATH_STD_USING // ADL of std functions. + static const T P[] = { + 0.083333333333333333333333333333333333333333333333333L, + -0.0083333333333333333333333333333333333333333333333333L, + 0.003968253968253968253968253968253968253968253968254L, + -0.0041666666666666666666666666666666666666666666666667L, + 0.0075757575757575757575757575757575757575757575757576L, + -0.021092796092796092796092796092796092796092796092796L, + 0.083333333333333333333333333333333333333333333333333L, + -0.44325980392156862745098039215686274509803921568627L, + 3.0539543302701197438039543302701197438039543302701L, + -26.456212121212121212121212121212121212121212121212L, + 281.4601449275362318840579710144927536231884057971L, + -3607.510546398046398046398046398046398046398046398L, + 54827.583333333333333333333333333333333333333333333L, + -974936.82385057471264367816091954022988505747126437L, + 20052695.796688078946143462272494530559046688078946L, + -472384867.72162990196078431372549019607843137254902L, + 12635724795.916666666666666666666666666666666666667L + }; + x -= 1; + T result = log(x); + result += 1 / (2 * x); + T z = 1 / (x*x); + result -= z * tools::evaluate_polynomial(P, z); + return result; +} +// +// 19-digit precision for x >= 10: +// +template <class T> +inline T digamma_imp_large(T x, const mpl::int_<64>*) +{ + BOOST_MATH_STD_USING // ADL of std functions. + static const T P[] = { + 0.083333333333333333333333333333333333333333333333333L, + -0.0083333333333333333333333333333333333333333333333333L, + 0.003968253968253968253968253968253968253968253968254L, + -0.0041666666666666666666666666666666666666666666666667L, + 0.0075757575757575757575757575757575757575757575757576L, + -0.021092796092796092796092796092796092796092796092796L, + 0.083333333333333333333333333333333333333333333333333L, + -0.44325980392156862745098039215686274509803921568627L, + 3.0539543302701197438039543302701197438039543302701L, + -26.456212121212121212121212121212121212121212121212L, + 281.4601449275362318840579710144927536231884057971L, + }; + x -= 1; + T result = log(x); + result += 1 / (2 * x); + T z = 1 / (x*x); + result -= z * tools::evaluate_polynomial(P, z); + return result; +} +// +// 17-digit precision for x >= 10: +// +template <class T> +inline T digamma_imp_large(T x, const mpl::int_<53>*) +{ + BOOST_MATH_STD_USING // ADL of std functions. + static const T P[] = { + 0.083333333333333333333333333333333333333333333333333L, + -0.0083333333333333333333333333333333333333333333333333L, + 0.003968253968253968253968253968253968253968253968254L, + -0.0041666666666666666666666666666666666666666666666667L, + 0.0075757575757575757575757575757575757575757575757576L, + -0.021092796092796092796092796092796092796092796092796L, + 0.083333333333333333333333333333333333333333333333333L, + -0.44325980392156862745098039215686274509803921568627L + }; + x -= 1; + T result = log(x); + result += 1 / (2 * x); + T z = 1 / (x*x); + result -= z * tools::evaluate_polynomial(P, z); + return result; +} +// +// 9-digit precision for x >= 10: +// +template <class T> +inline T digamma_imp_large(T x, const mpl::int_<24>*) +{ + BOOST_MATH_STD_USING // ADL of std functions. + static const T P[] = { + 0.083333333333333333333333333333333333333333333333333L, + -0.0083333333333333333333333333333333333333333333333333L, + 0.003968253968253968253968253968253968253968253968254L + }; + x -= 1; + T result = log(x); + result += 1 / (2 * x); + T z = 1 / (x*x); + result -= z * tools::evaluate_polynomial(P, z); + return result; +} +// +// Now follow rational approximations over the range [1,2]. +// +// 35-digit precision: +// +template <class T> +T digamma_imp_1_2(T x, const mpl::int_<0>*) +{ + // + // Now the approximation, we use the form: + // + // digamma(x) = (x - root) * (Y + R(x-1)) + // + // Where root is the location of the positive root of digamma, + // Y is a constant, and R is optimised for low absolute error + // compared to Y. + // + // Max error found at 128-bit long double precision: 5.541e-35 + // Maximum Deviation Found (approximation error): 1.965e-35 + // + static const float Y = 0.99558162689208984375F; + + static const T root1 = 1569415565.0 / 1073741824uL; + static const T root2 = (381566830.0 / 1073741824uL) / 1073741824uL; + static const T root3 = ((111616537.0 / 1073741824uL) / 1073741824uL) / 1073741824uL; + static const T root4 = (((503992070.0 / 1073741824uL) / 1073741824uL) / 1073741824uL) / 1073741824uL; + static const T root5 = 0.52112228569249997894452490385577338504019838794544e-36L; + + static const T P[] = { + 0.25479851061131551526977464225335883769L, + -0.18684290534374944114622235683619897417L, + -0.80360876047931768958995775910991929922L, + -0.67227342794829064330498117008564270136L, + -0.26569010991230617151285010695543858005L, + -0.05775672694575986971640757748003553385L, + -0.0071432147823164975485922555833274240665L, + -0.00048740753910766168912364555706064993274L, + -0.16454996865214115723416538844975174761e-4L, + -0.20327832297631728077731148515093164955e-6L + }; + static const T Q[] = { + 1, + 2.6210924610812025425088411043163287646L, + 2.6850757078559596612621337395886392594L, + 1.4320913706209965531250495490639289418L, + 0.4410872083455009362557012239501953402L, + 0.081385727399251729505165509278152487225L, + 0.0089478633066857163432104815183858149496L, + 0.00055861622855066424871506755481997374154L, + 0.1760168552357342401304462967950178554e-4L, + 0.20585454493572473724556649516040874384e-6L, + -0.90745971844439990284514121823069162795e-11L, + 0.48857673606545846774761343500033283272e-13L, + }; + T g = x - root1; + g -= root2; + g -= root3; + g -= root4; + g -= root5; + T r = tools::evaluate_polynomial(P, x-1) / tools::evaluate_polynomial(Q, x-1); + T result = g * Y + g * r; + + return result; +} +// +// 19-digit precision: +// +template <class T> +T digamma_imp_1_2(T x, const mpl::int_<64>*) +{ + // + // Now the approximation, we use the form: + // + // digamma(x) = (x - root) * (Y + R(x-1)) + // + // Where root is the location of the positive root of digamma, + // Y is a constant, and R is optimised for low absolute error + // compared to Y. + // + // Max error found at 80-bit long double precision: 5.016e-20 + // Maximum Deviation Found (approximation error): 3.575e-20 + // + static const float Y = 0.99558162689208984375F; + + static const T root1 = 1569415565.0 / 1073741824uL; + static const T root2 = (381566830.0 / 1073741824uL) / 1073741824uL; + static const T root3 = 0.9016312093258695918615325266959189453125e-19L; + + static const T P[] = { + 0.254798510611315515235L, + -0.314628554532916496608L, + -0.665836341559876230295L, + -0.314767657147375752913L, + -0.0541156266153505273939L, + -0.00289268368333918761452L + }; + static const T Q[] = { + 1, + 2.1195759927055347547L, + 1.54350554664961128724L, + 0.486986018231042975162L, + 0.0660481487173569812846L, + 0.00298999662592323990972L, + -0.165079794012604905639e-5L, + 0.317940243105952177571e-7L + }; + T g = x - root1; + g -= root2; + g -= root3; + T r = tools::evaluate_polynomial(P, x-1) / tools::evaluate_polynomial(Q, x-1); + T result = g * Y + g * r; + + return result; +} +// +// 18-digit precision: +// +template <class T> +T digamma_imp_1_2(T x, const mpl::int_<53>*) +{ + // + // Now the approximation, we use the form: + // + // digamma(x) = (x - root) * (Y + R(x-1)) + // + // Where root is the location of the positive root of digamma, + // Y is a constant, and R is optimised for low absolute error + // compared to Y. + // + // Maximum Deviation Found: 1.466e-18 + // At double precision, max error found: 2.452e-17 + // + static const float Y = 0.99558162689208984F; + + static const T root1 = 1569415565.0 / 1073741824uL; + static const T root2 = (381566830.0 / 1073741824uL) / 1073741824uL; + static const T root3 = 0.9016312093258695918615325266959189453125e-19L; + + static const T P[] = { + 0.25479851061131551L, + -0.32555031186804491L, + -0.65031853770896507L, + -0.28919126444774784L, + -0.045251321448739056L, + -0.0020713321167745952L + }; + static const T Q[] = { + 1L, + 2.0767117023730469L, + 1.4606242909763515L, + 0.43593529692665969L, + 0.054151797245674225L, + 0.0021284987017821144L, + -0.55789841321675513e-6L + }; + T g = x - root1; + g -= root2; + g -= root3; + T r = tools::evaluate_polynomial(P, x-1) / tools::evaluate_polynomial(Q, x-1); + T result = g * Y + g * r; + + return result; +} +// +// 9-digit precision: +// +template <class T> +inline T digamma_imp_1_2(T x, const mpl::int_<24>*) +{ + // + // Now the approximation, we use the form: + // + // digamma(x) = (x - root) * (Y + R(x-1)) + // + // Where root is the location of the positive root of digamma, + // Y is a constant, and R is optimised for low absolute error + // compared to Y. + // + // Maximum Deviation Found: 3.388e-010 + // At float precision, max error found: 2.008725e-008 + // + static const float Y = 0.99558162689208984f; + static const T root = 1532632.0f / 1048576; + static const T root_minor = static_cast<T>(0.3700660185912626595423257213284682051735604e-6L); + static const T P[] = { + 0.25479851023250261e0, + -0.44981331915268368e0, + -0.43916936919946835e0, + -0.61041765350579073e-1 + }; + static const T Q[] = { + 0.1e1, + 0.15890202430554952e1, + 0.65341249856146947e0, + 0.63851690523355715e-1 + }; + T g = x - root; + g -= root_minor; + T r = tools::evaluate_polynomial(P, x-1) / tools::evaluate_polynomial(Q, x-1); + T result = g * Y + g * r; + + return result; +} + +template <class T, class Tag, class Policy> +T digamma_imp(T x, const Tag* t, const Policy& pol) +{ + // + // This handles reflection of negative arguments, and all our + // error handling, then forwards to the T-specific approximation. + // + BOOST_MATH_STD_USING // ADL of std functions. + + T result = 0; + // + // Check for negative arguments and use reflection: + // + if(x < 0) + { + // Reflect: + x = 1 - x; + // Argument reduction for tan: + T remainder = x - floor(x); + // Shift to negative if > 0.5: + if(remainder > 0.5) + { + remainder -= 1; + } + // + // check for evaluation at a negative pole: + // + if(remainder == 0) + { + return policies::raise_pole_error<T>("boost::math::digamma<%1%>(%1%)", 0, (1-x), pol); + } + result = constants::pi<T>() / tan(constants::pi<T>() * remainder); + } + // + // If we're above the lower-limit for the + // asymptotic expansion then use it: + // + if(x >= digamma_large_lim(t)) + { + result += digamma_imp_large(x, t); + } + else + { + // + // If x > 2 reduce to the interval [1,2]: + // + while(x > 2) + { + x -= 1; + result += 1/x; + } + // + // If x < 1 use recurrance to shift to > 1: + // + if(x < 1) + { + result = -1/x; + x += 1; + } + result += digamma_imp_1_2(x, t); + } + return result; +} + +} // namespace detail + +template <class T, class Policy> +inline typename tools::promote_args<T>::type + digamma(T x, const Policy& pol) +{ + typedef typename tools::promote_args<T>::type result_type; + typedef typename policies::evaluation<result_type, Policy>::type value_type; + typedef typename policies::precision<T, Policy>::type precision_type; + typedef typename mpl::if_< + mpl::or_< + mpl::less_equal<precision_type, mpl::int_<0> >, + mpl::greater<precision_type, mpl::int_<64> > + >, + mpl::int_<0>, + typename mpl::if_< + mpl::less<precision_type, mpl::int_<25> >, + mpl::int_<24>, + typename mpl::if_< + mpl::less<precision_type, mpl::int_<54> >, + mpl::int_<53>, + mpl::int_<64> + >::type + >::type + >::type tag_type; + + return policies::checked_narrowing_cast<result_type, Policy>(detail::digamma_imp( + static_cast<value_type>(x), + static_cast<const tag_type*>(0), pol), "boost::math::digamma<%1%>(%1%)"); +} + +template <class T> +inline typename tools::promote_args<T>::type + digamma(T x) +{ + return digamma(x, policies::policy<>()); +} + +} // namespace math +} // namespace boost +#endif + diff --git a/Utilities/BGL/boost/math/special_functions/ellint_1.hpp b/Utilities/BGL/boost/math/special_functions/ellint_1.hpp new file mode 100644 index 0000000000000000000000000000000000000000..d746f30247aaf100033b4020118fbdaa3d6b8ad8 --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/ellint_1.hpp @@ -0,0 +1,187 @@ +// Copyright (c) 2006 Xiaogang Zhang +// Copyright (c) 2006 John Maddock +// Use, modification and distribution are subject to 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) +// +// History: +// XZ wrote the original of this file as part of the Google +// Summer of Code 2006. JM modified it to fit into the +// Boost.Math conceptual framework better, and to ensure +// that the code continues to work no matter how many digits +// type T has. + +#ifndef BOOST_MATH_ELLINT_1_HPP +#define BOOST_MATH_ELLINT_1_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/math/special_functions/ellint_rf.hpp> +#include <boost/math/constants/constants.hpp> +#include <boost/math/policies/error_handling.hpp> +#include <boost/math/tools/workaround.hpp> + +// Elliptic integrals (complete and incomplete) of the first kind +// Carlson, Numerische Mathematik, vol 33, 1 (1979) + +namespace boost { namespace math { + +template <class T1, class T2, class Policy> +typename tools::promote_args<T1, T2>::type ellint_1(T1 k, T2 phi, const Policy& pol); + +namespace detail{ + +template <typename T, typename Policy> +T ellint_k_imp(T k, const Policy& pol); + +// Elliptic integral (Legendre form) of the first kind +template <typename T, typename Policy> +T ellint_f_imp(T phi, T k, const Policy& pol) +{ + BOOST_MATH_STD_USING + using namespace boost::math::tools; + using namespace boost::math::constants; + + static const char* function = "boost::math::ellint_f<%1%>(%1%,%1%)"; + BOOST_MATH_INSTRUMENT_VARIABLE(phi); + BOOST_MATH_INSTRUMENT_VARIABLE(k); + BOOST_MATH_INSTRUMENT_VARIABLE(function); + + if (abs(k) > 1) + { + return policies::raise_domain_error<T>(function, + "Got k = %1%, function requires |k| <= 1", k, pol); + } + + bool invert = false; + if(phi < 0) + { + BOOST_MATH_INSTRUMENT_VARIABLE(phi); + phi = fabs(phi); + invert = true; + } + + T result; + + if(phi >= tools::max_value<T>()) + { + // Need to handle infinity as a special case: + result = policies::raise_overflow_error<T>(function, 0, pol); + BOOST_MATH_INSTRUMENT_VARIABLE(result); + } + else if(phi > 1 / tools::epsilon<T>()) + { + // Phi is so large that phi%pi is necessarily zero (or garbage), + // just return the second part of the duplication formula: + result = 2 * phi * ellint_k_imp(k, pol) / constants::pi<T>(); + BOOST_MATH_INSTRUMENT_VARIABLE(result); + } + else + { + // Carlson's algorithm works only for |phi| <= pi/2, + // use the integrand's periodicity to normalize phi + // + // Xiaogang's original code used a cast to long long here + // but that fails if T has more digits than a long long, + // so rewritten to use fmod instead: + // + BOOST_MATH_INSTRUMENT_CODE("pi/2 = " << constants::pi<T>() / 2); + T rphi = boost::math::tools::fmod_workaround(phi, T(constants::pi<T>() / 2)); + BOOST_MATH_INSTRUMENT_VARIABLE(rphi); + T m = floor((2 * phi) / constants::pi<T>()); + BOOST_MATH_INSTRUMENT_VARIABLE(m); + int s = 1; + if(boost::math::tools::fmod_workaround(m, T(2)) > 0.5) + { + m += 1; + s = -1; + rphi = constants::pi<T>() / 2 - rphi; + BOOST_MATH_INSTRUMENT_VARIABLE(rphi); + } + T sinp = sin(rphi); + T cosp = cos(rphi); + BOOST_MATH_INSTRUMENT_VARIABLE(sinp); + BOOST_MATH_INSTRUMENT_VARIABLE(cosp); + result = s * sinp * ellint_rf_imp(T(cosp * cosp), T(1 - k * k * sinp * sinp), T(1), pol); + BOOST_MATH_INSTRUMENT_VARIABLE(result); + if(m != 0) + { + result += m * ellint_k_imp(k, pol); + BOOST_MATH_INSTRUMENT_VARIABLE(result); + } + } + return invert ? T(-result) : result; +} + +// Complete elliptic integral (Legendre form) of the first kind +template <typename T, typename Policy> +T ellint_k_imp(T k, const Policy& pol) +{ + BOOST_MATH_STD_USING + using namespace boost::math::tools; + + static const char* function = "boost::math::ellint_k<%1%>(%1%)"; + + if (abs(k) > 1) + { + return policies::raise_domain_error<T>(function, + "Got k = %1%, function requires |k| <= 1", k, pol); + } + if (abs(k) == 1) + { + return policies::raise_overflow_error<T>(function, 0, pol); + } + + T x = 0; + T y = 1 - k * k; + T z = 1; + T value = ellint_rf_imp(x, y, z, pol); + + return value; +} + +template <typename T, typename Policy> +inline typename tools::promote_args<T>::type ellint_1(T k, const Policy& pol, const mpl::true_&) +{ + typedef typename tools::promote_args<T>::type result_type; + typedef typename policies::evaluation<result_type, Policy>::type value_type; + return policies::checked_narrowing_cast<result_type, Policy>(detail::ellint_k_imp(static_cast<value_type>(k), pol), "boost::math::ellint_1<%1%>(%1%)"); +} + +template <class T1, class T2> +inline typename tools::promote_args<T1, T2>::type ellint_1(T1 k, T2 phi, const mpl::false_&) +{ + return boost::math::ellint_1(k, phi, policies::policy<>()); +} + +} + +// Complete elliptic integral (Legendre form) of the first kind +template <typename T> +inline typename tools::promote_args<T>::type ellint_1(T k) +{ + return ellint_1(k, policies::policy<>()); +} + +// Elliptic integral (Legendre form) of the first kind +template <class T1, class T2, class Policy> +inline typename tools::promote_args<T1, T2>::type ellint_1(T1 k, T2 phi, const Policy& pol) +{ + typedef typename tools::promote_args<T1, T2>::type result_type; + typedef typename policies::evaluation<result_type, Policy>::type value_type; + return policies::checked_narrowing_cast<result_type, Policy>(detail::ellint_f_imp(static_cast<value_type>(phi), static_cast<value_type>(k), pol), "boost::math::ellint_1<%1%>(%1%,%1%)"); +} + +template <class T1, class T2> +inline typename tools::promote_args<T1, T2>::type ellint_1(T1 k, T2 phi) +{ + typedef typename policies::is_policy<T2>::type tag_type; + return detail::ellint_1(k, phi, tag_type()); +} + +}} // namespaces + +#endif // BOOST_MATH_ELLINT_1_HPP + diff --git a/Utilities/BGL/boost/math/special_functions/ellint_2.hpp b/Utilities/BGL/boost/math/special_functions/ellint_2.hpp new file mode 100644 index 0000000000000000000000000000000000000000..a9a5a887b3ad199b34346e183cd6b0e2476e24c9 --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/ellint_2.hpp @@ -0,0 +1,168 @@ +// Copyright (c) 2006 Xiaogang Zhang +// Copyright (c) 2006 John Maddock +// Use, modification and distribution are subject to 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) +// +// History: +// XZ wrote the original of this file as part of the Google +// Summer of Code 2006. JM modified it to fit into the +// Boost.Math conceptual framework better, and to ensure +// that the code continues to work no matter how many digits +// type T has. + +#ifndef BOOST_MATH_ELLINT_2_HPP +#define BOOST_MATH_ELLINT_2_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/math/special_functions/ellint_rf.hpp> +#include <boost/math/special_functions/ellint_rd.hpp> +#include <boost/math/constants/constants.hpp> +#include <boost/math/policies/error_handling.hpp> +#include <boost/math/tools/workaround.hpp> + +// Elliptic integrals (complete and incomplete) of the second kind +// Carlson, Numerische Mathematik, vol 33, 1 (1979) + +namespace boost { namespace math { + +template <class T1, class T2, class Policy> +typename tools::promote_args<T1, T2>::type ellint_2(T1 k, T2 phi, const Policy& pol); + +namespace detail{ + +template <typename T, typename Policy> +T ellint_e_imp(T k, const Policy& pol); + +// Elliptic integral (Legendre form) of the second kind +template <typename T, typename Policy> +T ellint_e_imp(T phi, T k, const Policy& pol) +{ + BOOST_MATH_STD_USING + using namespace boost::math::tools; + using namespace boost::math::constants; + + bool invert = false; + if(phi < 0) + { + phi = fabs(phi); + invert = true; + } + + T result; + + if(phi >= tools::max_value<T>()) + { + // Need to handle infinity as a special case: + result = policies::raise_overflow_error<T>("boost::math::ellint_e<%1%>(%1%,%1%)", 0, pol); + } + else if(phi > 1 / tools::epsilon<T>()) + { + // Phi is so large that phi%pi is necessarily zero (or garbage), + // just return the second part of the duplication formula: + result = 2 * phi * ellint_e_imp(k, pol) / constants::pi<T>(); + } + else + { + // Carlson's algorithm works only for |phi| <= pi/2, + // use the integrand's periodicity to normalize phi + // + // Xiaogang's original code used a cast to long long here + // but that fails if T has more digits than a long long, + // so rewritten to use fmod instead: + // + T rphi = boost::math::tools::fmod_workaround(phi, T(constants::pi<T>() / 2)); + T m = floor((2 * phi) / constants::pi<T>()); + int s = 1; + if(boost::math::tools::fmod_workaround(m, T(2)) > 0.5) + { + m += 1; + s = -1; + rphi = constants::pi<T>() / 2 - rphi; + } + T sinp = sin(rphi); + T cosp = cos(rphi); + T x = cosp * cosp; + T t = k * k * sinp * sinp; + T y = 1 - t; + T z = 1; + result = s * sinp * (ellint_rf_imp(x, y, z, pol) - t * ellint_rd_imp(x, y, z, pol) / 3); + if(m != 0) + result += m * ellint_e_imp(k, pol); + } + return invert ? T(-result) : result; +} + +// Complete elliptic integral (Legendre form) of the second kind +template <typename T, typename Policy> +T ellint_e_imp(T k, const Policy& pol) +{ + BOOST_MATH_STD_USING + using namespace boost::math::tools; + + if (abs(k) > 1) + { + return policies::raise_domain_error<T>("boost::math::ellint_e<%1%>(%1%)", + "Got k = %1%, function requires |k| <= 1", k, pol); + } + if (abs(k) == 1) + { + return static_cast<T>(1); + } + + T x = 0; + T t = k * k; + T y = 1 - t; + T z = 1; + T value = ellint_rf_imp(x, y, z, pol) - t * ellint_rd_imp(x, y, z, pol) / 3; + + return value; +} + +template <typename T, typename Policy> +inline typename tools::promote_args<T>::type ellint_2(T k, const Policy& pol, const mpl::true_&) +{ + typedef typename tools::promote_args<T>::type result_type; + typedef typename policies::evaluation<result_type, Policy>::type value_type; + return policies::checked_narrowing_cast<result_type, Policy>(detail::ellint_e_imp(static_cast<value_type>(k), pol), "boost::math::ellint_2<%1%>(%1%)"); +} + +// Elliptic integral (Legendre form) of the second kind +template <class T1, class T2> +inline typename tools::promote_args<T1, T2>::type ellint_2(T1 k, T2 phi, const mpl::false_&) +{ + return boost::math::ellint_2(k, phi, policies::policy<>()); +} + +} // detail + +// Complete elliptic integral (Legendre form) of the second kind +template <typename T> +inline typename tools::promote_args<T>::type ellint_2(T k) +{ + return ellint_2(k, policies::policy<>()); +} + +// Elliptic integral (Legendre form) of the second kind +template <class T1, class T2> +inline typename tools::promote_args<T1, T2>::type ellint_2(T1 k, T2 phi) +{ + typedef typename policies::is_policy<T2>::type tag_type; + return detail::ellint_2(k, phi, tag_type()); +} + +template <class T1, class T2, class Policy> +inline typename tools::promote_args<T1, T2>::type ellint_2(T1 k, T2 phi, const Policy& pol) +{ + typedef typename tools::promote_args<T1, T2>::type result_type; + typedef typename policies::evaluation<result_type, Policy>::type value_type; + return policies::checked_narrowing_cast<result_type, Policy>(detail::ellint_e_imp(static_cast<value_type>(phi), static_cast<value_type>(k), pol), "boost::math::ellint_2<%1%>(%1%,%1%)"); +} + +}} // namespaces + +#endif // BOOST_MATH_ELLINT_2_HPP + diff --git a/Utilities/BGL/boost/math/special_functions/ellint_3.hpp b/Utilities/BGL/boost/math/special_functions/ellint_3.hpp new file mode 100644 index 0000000000000000000000000000000000000000..52ccc2d76524211aee1e45b45ee2ce3850447269 --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/ellint_3.hpp @@ -0,0 +1,333 @@ +// Copyright (c) 2006 Xiaogang Zhang +// Copyright (c) 2006 John Maddock +// Use, modification and distribution are subject to 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) +// +// History: +// XZ wrote the original of this file as part of the Google +// Summer of Code 2006. JM modified it to fit into the +// Boost.Math conceptual framework better, and to correctly +// handle the various corner cases. +// + +#ifndef BOOST_MATH_ELLINT_3_HPP +#define BOOST_MATH_ELLINT_3_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/math/special_functions/ellint_rf.hpp> +#include <boost/math/special_functions/ellint_rj.hpp> +#include <boost/math/special_functions/ellint_1.hpp> +#include <boost/math/special_functions/ellint_2.hpp> +#include <boost/math/special_functions/log1p.hpp> +#include <boost/math/constants/constants.hpp> +#include <boost/math/policies/error_handling.hpp> +#include <boost/math/tools/workaround.hpp> + +// Elliptic integrals (complete and incomplete) of the third kind +// Carlson, Numerische Mathematik, vol 33, 1 (1979) + +namespace boost { namespace math { + +namespace detail{ + +template <typename T, typename Policy> +T ellint_pi_imp(T v, T k, T vc, const Policy& pol); + +// Elliptic integral (Legendre form) of the third kind +template <typename T, typename Policy> +T ellint_pi_imp(T v, T phi, T k, T vc, const Policy& pol) +{ + // Note vc = 1-v presumably without cancellation error. + T value, x, y, z, p, t; + + BOOST_MATH_STD_USING + using namespace boost::math::tools; + using namespace boost::math::constants; + + static const char* function = "boost::math::ellint_3<%1%>(%1%,%1%,%1%)"; + + if (abs(k) > 1) + { + return policies::raise_domain_error<T>(function, + "Got k = %1%, function requires |k| <= 1", k, pol); + } + + T sphi = sin(fabs(phi)); + + if(v > 1 / (sphi * sphi)) + { + // Complex result is a domain error: + return policies::raise_domain_error<T>(function, + "Got v = %1%, but result is complex for v > 1 / sin^2(phi)", v, pol); + } + + // Special cases first: + if(v == 0) + { + // A&S 17.7.18 & 19 + return (k == 0) ? phi : ellint_f_imp(phi, k, pol); + } + if(phi == constants::pi<T>() / 2) + { + // Have to filter this case out before the next + // special case, otherwise we might get an infinity from + // tan(phi). + // Also note that since we can't represent PI/2 exactly + // in a T, this is a bit of a guess as to the users true + // intent... + // + return ellint_pi_imp(v, k, vc, pol); + } + if(k == 0) + { + // A&S 17.7.20: + if(v < 1) + { + T vcr = sqrt(vc); + return atan(vcr * tan(phi)) / vcr; + } + else if(v == 1) + { + return tan(phi); + } + else + { + // v > 1: + T vcr = sqrt(-vc); + T arg = vcr * tan(phi); + return (boost::math::log1p(arg, pol) - boost::math::log1p(-arg, pol)) / (2 * vcr); + } + } + + if(v < 0) + { + // + // If we don't shift to 0 <= v <= 1 we get + // cancellation errors later on. Use + // A&S 17.7.15/16 to shift to v > 0: + // + T k2 = k * k; + T N = (k2 - v) / (1 - v); + T Nm1 = (1 - k2) / (1 - v); + T p2 = sqrt(-v * (k2 - v) / (1 - v)); + T delta = sqrt(1 - k2 * sphi * sphi); + T result = ellint_pi_imp(N, phi, k, Nm1, pol); + + result *= sqrt(Nm1 * (1 - k2 / N)); + result += ellint_f_imp(phi, k, pol) * k2 / p2; + result += atan((p2/2) * sin(2 * phi) / delta); + result /= sqrt((1 - v) * (1 - k2 / v)); + return result; + } +#if 0 // disabled but retained for future reference: see below. + if(v > 1) + { + // + // If v > 1 we can use the identity in A&S 17.7.7/8 + // to shift to 0 <= v <= 1. Unfortunately this + // identity appears only to function correctly when + // 0 <= phi <= pi/2, but it's when phi is outside that + // range that we really need it: That's when + // Carlson's formula fails, and what's more the periodicity + // reduction used below on phi doesn't work when v > 1. + // + // So we're stuck... the code is archived here in case + // some bright spart can figure out the fix. + // + T k2 = k * k; + T N = k2 / v; + T Nm1 = (v - k2) / v; + T p1 = sqrt((-vc) * (1 - k2 / v)); + T delta = sqrt(1 - k2 * sphi * sphi); + // + // These next two terms have a large amount of cancellation + // so it's not clear if this relation is useable even if + // the issues with phi > pi/2 can be fixed: + // + T result = -ellint_pi_imp(N, phi, k, Nm1); + result += ellint_f_imp(phi, k); + // + // This log term gives the complex result when + // n > 1/sin^2(phi) + // However that case is dealt with as an error above, + // so we should always get a real result here: + // + result += log((delta + p1 * tan(phi)) / (delta - p1 * tan(phi))) / (2 * p1); + return result; + } +#endif + + // Carlson's algorithm works only for |phi| <= pi/2, + // use the integrand's periodicity to normalize phi + // + // Xiaogang's original code used a cast to long long here + // but that fails if T has more digits than a long long, + // so rewritten to use fmod instead: + // + if(fabs(phi) > 1 / tools::epsilon<T>()) + { + if(v > 1) + return policies::raise_domain_error<T>( + function, + "Got v = %1%, but this is only supported for 0 <= phi <= pi/2", v, pol); + // + // Phi is so large that phi%pi is necessarily zero (or garbage), + // just return the second part of the duplication formula: + // + value = 2 * fabs(phi) * ellint_pi_imp(v, k, vc, pol) / constants::pi<T>(); + } + else + { + T rphi = boost::math::tools::fmod_workaround(fabs(phi), T(constants::pi<T>() / 2)); + T m = floor((2 * fabs(phi)) / constants::pi<T>()); + int sign = 1; + if(boost::math::tools::fmod_workaround(m, T(2)) > 0.5) + { + m += 1; + sign = -1; + rphi = constants::pi<T>() / 2 - rphi; + } +#if 0 + // + // This wasn't supported but is now... probably! + // + if((m > 0) && (v > 1)) + { + // + // The region with v > 1 and phi outside [0, pi/2] is + // currently unsupported: + // + return policies::raise_domain_error<T>( + function, + "Got v = %1%, but this is only supported for 0 <= phi <= pi/2", v, pol); + } +#endif + T sinp = sin(rphi); + T cosp = cos(rphi); + x = cosp * cosp; + t = sinp * sinp; + y = 1 - k * k * t; + z = 1; + if(v * t < 0.5) + p = 1 - v * t; + else + p = x + vc * t; + value = sign * sinp * (ellint_rf_imp(x, y, z, pol) + v * t * ellint_rj_imp(x, y, z, p, pol) / 3); + if((m > 0) && (vc > 0)) + value += m * ellint_pi_imp(v, k, vc, pol); + } + + if (phi < 0) + { + value = -value; // odd function + } + return value; +} + +// Complete elliptic integral (Legendre form) of the third kind +template <typename T, typename Policy> +T ellint_pi_imp(T v, T k, T vc, const Policy& pol) +{ + // Note arg vc = 1-v, possibly without cancellation errors + BOOST_MATH_STD_USING + using namespace boost::math::tools; + + static const char* function = "boost::math::ellint_pi<%1%>(%1%,%1%)"; + + if (abs(k) >= 1) + { + return policies::raise_domain_error<T>(function, + "Got k = %1%, function requires |k| <= 1", k, pol); + } + if(vc <= 0) + { + // Result is complex: + return policies::raise_domain_error<T>(function, + "Got v = %1%, function requires v < 1", v, pol); + } + + if(v == 0) + { + return (k == 0) ? boost::math::constants::pi<T>() / 2 : ellint_k_imp(k, pol); + } + + if(v < 0) + { + T k2 = k * k; + T N = (k2 - v) / (1 - v); + T Nm1 = (1 - k2) / (1 - v); + T p2 = sqrt(-v * (k2 - v) / (1 - v)); + + T result = boost::math::detail::ellint_pi_imp(N, k, Nm1, pol); + + result *= sqrt(Nm1 * (1 - k2 / N)); + result += ellint_k_imp(k, pol) * k2 / p2; + result /= sqrt((1 - v) * (1 - k2 / v)); + return result; + } + + T x = 0; + T y = 1 - k * k; + T z = 1; + T p = vc; + T value = ellint_rf_imp(x, y, z, pol) + v * ellint_rj_imp(x, y, z, p, pol) / 3; + + return value; +} + +template <class T1, class T2, class T3> +inline typename tools::promote_args<T1, T2, T3>::type ellint_3(T1 k, T2 v, T3 phi, const mpl::false_&) +{ + return boost::math::ellint_3(k, v, phi, policies::policy<>()); +} + +template <class T1, class T2, class Policy> +inline typename tools::promote_args<T1, T2>::type ellint_3(T1 k, T2 v, const Policy& pol, const mpl::true_&) +{ + typedef typename tools::promote_args<T1, T2>::type result_type; + typedef typename policies::evaluation<result_type, Policy>::type value_type; + return policies::checked_narrowing_cast<result_type, Policy>( + detail::ellint_pi_imp( + static_cast<value_type>(v), + static_cast<value_type>(k), + static_cast<value_type>(1-v), + pol), "boost::math::ellint_3<%1%>(%1%,%1%)"); +} + +} // namespace detail + +template <class T1, class T2, class T3, class Policy> +inline typename tools::promote_args<T1, T2, T3>::type ellint_3(T1 k, T2 v, T3 phi, const Policy& pol) +{ + typedef typename tools::promote_args<T1, T2, T3>::type result_type; + typedef typename policies::evaluation<result_type, Policy>::type value_type; + return policies::checked_narrowing_cast<result_type, Policy>( + detail::ellint_pi_imp( + static_cast<value_type>(v), + static_cast<value_type>(phi), + static_cast<value_type>(k), + static_cast<value_type>(1-v), + pol), "boost::math::ellint_3<%1%>(%1%,%1%,%1%)"); +} + +template <class T1, class T2, class T3> +typename detail::ellint_3_result<T1, T2, T3>::type ellint_3(T1 k, T2 v, T3 phi) +{ + typedef typename policies::is_policy<T3>::type tag_type; + return detail::ellint_3(k, v, phi, tag_type()); +} + +template <class T1, class T2> +inline typename tools::promote_args<T1, T2>::type ellint_3(T1 k, T2 v) +{ + return ellint_3(k, v, policies::policy<>()); +} + +}} // namespaces + +#endif // BOOST_MATH_ELLINT_3_HPP + diff --git a/Utilities/BGL/boost/math/special_functions/ellint_rc.hpp b/Utilities/BGL/boost/math/special_functions/ellint_rc.hpp new file mode 100644 index 0000000000000000000000000000000000000000..d1b8f2d86914ab4aff2633baa6a4f9b49ccff361 --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/ellint_rc.hpp @@ -0,0 +1,115 @@ +// Copyright (c) 2006 Xiaogang Zhang +// Use, modification and distribution are subject to 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) +// +// History: +// XZ wrote the original of this file as part of the Google +// Summer of Code 2006. JM modified it to fit into the +// Boost.Math conceptual framework better, and to correctly +// handle the y < 0 case. +// + +#ifndef BOOST_MATH_ELLINT_RC_HPP +#define BOOST_MATH_ELLINT_RC_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/math/policies/error_handling.hpp> +#include <boost/math/tools/config.hpp> +#include <boost/math/special_functions/math_fwd.hpp> + +// Carlson's degenerate elliptic integral +// R_C(x, y) = R_F(x, y, y) = 0.5 * \int_{0}^{\infty} (t+x)^{-1/2} (t+y)^{-1} dt +// Carlson, Numerische Mathematik, vol 33, 1 (1979) + +namespace boost { namespace math { namespace detail{ + +template <typename T, typename Policy> +T ellint_rc_imp(T x, T y, const Policy& pol) +{ + T value, S, u, lambda, tolerance, prefix; + unsigned long k; + + BOOST_MATH_STD_USING + using namespace boost::math::tools; + + static const char* function = "boost::math::ellint_rc<%1%>(%1%,%1%)"; + + if(x < 0) + { + return policies::raise_domain_error<T>(function, + "Argument x must be non-negative but got %1%", x, pol); + } + if(y == 0) + { + return policies::raise_domain_error<T>(function, + "Argument y must not be zero but got %1%", y, pol); + } + + // error scales as the 6th power of tolerance + tolerance = pow(4 * tools::epsilon<T>(), T(1) / 6); + + // for y < 0, the integral is singular, return Cauchy principal value + if (y < 0) + { + prefix = sqrt(x / (x - y)); + x = x - y; + y = -y; + } + else + prefix = 1; + + // duplication: + k = 1; + do + { + u = (x + y + y) / 3; + S = y / u - 1; // 1 - x / u = 2 * S + + if (2 * abs(S) < tolerance) + break; + + T sx = sqrt(x); + T sy = sqrt(y); + lambda = 2 * sx * sy + y; + x = (x + lambda) / 4; + y = (y + lambda) / 4; + ++k; + }while(k < policies::get_max_series_iterations<Policy>()); + // Check to see if we gave up too soon: + policies::check_series_iterations(function, k, pol); + + // Taylor series expansion to the 5th order + value = (1 + S * S * (T(3) / 10 + S * (T(1) / 7 + S * (T(3) / 8 + S * T(9) / 22)))) / sqrt(u); + + return value * prefix; +} + +} // namespace detail + +template <class T1, class T2, class Policy> +inline typename tools::promote_args<T1, T2>::type + ellint_rc(T1 x, T2 y, const Policy& pol) +{ + typedef typename tools::promote_args<T1, T2>::type result_type; + typedef typename policies::evaluation<result_type, Policy>::type value_type; + return policies::checked_narrowing_cast<result_type, Policy>( + detail::ellint_rc_imp( + static_cast<value_type>(x), + static_cast<value_type>(y), pol), "boost::math::ellint_rc<%1%>(%1%,%1%)"); +} + +template <class T1, class T2> +inline typename tools::promote_args<T1, T2>::type + ellint_rc(T1 x, T2 y) +{ + return ellint_rc(x, y, policies::policy<>()); +} + +}} // namespaces + +#endif // BOOST_MATH_ELLINT_RC_HPP + diff --git a/Utilities/BGL/boost/math/special_functions/ellint_rd.hpp b/Utilities/BGL/boost/math/special_functions/ellint_rd.hpp new file mode 100644 index 0000000000000000000000000000000000000000..454e1ed9b1801af073fb2b996e2393a14188243b --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/ellint_rd.hpp @@ -0,0 +1,130 @@ +// Copyright (c) 2006 Xiaogang Zhang +// Use, modification and distribution are subject to 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) +// +// History: +// XZ wrote the original of this file as part of the Google +// Summer of Code 2006. JM modified it slightly to fit into the +// Boost.Math conceptual framework better. + +#ifndef BOOST_MATH_ELLINT_RD_HPP +#define BOOST_MATH_ELLINT_RD_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/math/special_functions/math_fwd.hpp> +#include <boost/math/tools/config.hpp> +#include <boost/math/policies/error_handling.hpp> + +// Carlson's elliptic integral of the second kind +// R_D(x, y, z) = R_J(x, y, z, z) = 1.5 * \int_{0}^{\infty} [(t+x)(t+y)]^{-1/2} (t+z)^{-3/2} dt +// Carlson, Numerische Mathematik, vol 33, 1 (1979) + +namespace boost { namespace math { namespace detail{ + +template <typename T, typename Policy> +T ellint_rd_imp(T x, T y, T z, const Policy& pol) +{ + T value, u, lambda, sigma, factor, tolerance; + T X, Y, Z, EA, EB, EC, ED, EE, S1, S2; + unsigned long k; + + BOOST_MATH_STD_USING + using namespace boost::math::tools; + + static const char* function = "boost::math::ellint_rd<%1%>(%1%,%1%,%1%)"; + + if (x < 0) + { + return policies::raise_domain_error<T>(function, + "Argument x must be >= 0, but got %1%", x, pol); + } + if (y < 0) + { + return policies::raise_domain_error<T>(function, + "Argument y must be >= 0, but got %1%", y, pol); + } + if (z <= 0) + { + return policies::raise_domain_error<T>(function, + "Argument z must be > 0, but got %1%", z, pol); + } + if (x + y == 0) + { + return policies::raise_domain_error<T>(function, + "At most one argument can be zero, but got, x + y = %1%", x+y, pol); + } + + // error scales as the 6th power of tolerance + tolerance = pow(tools::epsilon<T>() / 3, T(1)/6); + + // duplication + sigma = 0; + factor = 1; + k = 1; + do + { + u = (x + y + z + z + z) / 5; + X = (u - x) / u; + Y = (u - y) / u; + Z = (u - z) / u; + if ((tools::max)(abs(X), abs(Y), abs(Z)) < tolerance) + break; + T sx = sqrt(x); + T sy = sqrt(y); + T sz = sqrt(z); + lambda = sy * (sx + sz) + sz * sx; //sqrt(x * y) + sqrt(y * z) + sqrt(z * x); + sigma += factor / (sz * (z + lambda)); + factor /= 4; + x = (x + lambda) / 4; + y = (y + lambda) / 4; + z = (z + lambda) / 4; + ++k; + } + while(k < policies::get_max_series_iterations<Policy>()); + + // Check to see if we gave up too soon: + policies::check_series_iterations(function, k, pol); + + // Taylor series expansion to the 5th order + EA = X * Y; + EB = Z * Z; + EC = EA - EB; + ED = EA - 6 * EB; + EE = ED + EC + EC; + S1 = ED * (ED * T(9) / 88 - Z * EE * T(9) / 52 - T(3) / 14); + S2 = Z * (EE / 6 + Z * (-EC * T(9) / 22 + Z * EA * T(3) / 26)); + value = 3 * sigma + factor * (1 + S1 + S2) / (u * sqrt(u)); + + return value; +} + +} // namespace detail + +template <class T1, class T2, class T3, class Policy> +inline typename tools::promote_args<T1, T2, T3>::type + ellint_rd(T1 x, T2 y, T3 z, const Policy& pol) +{ + typedef typename tools::promote_args<T1, T2, T3>::type result_type; + typedef typename policies::evaluation<result_type, Policy>::type value_type; + return policies::checked_narrowing_cast<result_type, Policy>( + detail::ellint_rd_imp( + static_cast<value_type>(x), + static_cast<value_type>(y), + static_cast<value_type>(z), pol), "boost::math::ellint_rd<%1%>(%1%,%1%,%1%)"); +} + +template <class T1, class T2, class T3> +inline typename tools::promote_args<T1, T2, T3>::type + ellint_rd(T1 x, T2 y, T3 z) +{ + return ellint_rd(x, y, z, policies::policy<>()); +} + +}} // namespaces + +#endif // BOOST_MATH_ELLINT_RD_HPP + diff --git a/Utilities/BGL/boost/math/special_functions/ellint_rf.hpp b/Utilities/BGL/boost/math/special_functions/ellint_rf.hpp new file mode 100644 index 0000000000000000000000000000000000000000..5eb5065e6ca79d6ae1c3302824b80db7809fdb7c --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/ellint_rf.hpp @@ -0,0 +1,132 @@ +// Copyright (c) 2006 Xiaogang Zhang +// Use, modification and distribution are subject to 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) +// +// History: +// XZ wrote the original of this file as part of the Google +// Summer of Code 2006. JM modified it to fit into the +// Boost.Math conceptual framework better, and to handle +// types longer than 80-bit reals. +// +#ifndef BOOST_MATH_ELLINT_RF_HPP +#define BOOST_MATH_ELLINT_RF_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/math/special_functions/math_fwd.hpp> +#include <boost/math/tools/config.hpp> + +#include <boost/math/policies/error_handling.hpp> + +// Carlson's elliptic integral of the first kind +// R_F(x, y, z) = 0.5 * \int_{0}^{\infty} [(t+x)(t+y)(t+z)]^{-1/2} dt +// Carlson, Numerische Mathematik, vol 33, 1 (1979) + +namespace boost { namespace math { namespace detail{ + +template <typename T, typename Policy> +T ellint_rf_imp(T x, T y, T z, const Policy& pol) +{ + T value, X, Y, Z, E2, E3, u, lambda, tolerance; + unsigned long k; + + BOOST_MATH_STD_USING + using namespace boost::math::tools; + + static const char* function = "boost::math::ellint_rf<%1%>(%1%,%1%,%1%)"; + + if (x < 0 || y < 0 || z < 0) + { + return policies::raise_domain_error<T>(function, + "domain error, all arguments must be non-negative, " + "only sensible result is %1%.", + std::numeric_limits<T>::quiet_NaN(), pol); + } + if (x + y == 0 || y + z == 0 || z + x == 0) + { + return policies::raise_domain_error<T>(function, + "domain error, at most one argument can be zero, " + "only sensible result is %1%.", + std::numeric_limits<T>::quiet_NaN(), pol); + } + + // Carlson scales error as the 6th power of tolerance, + // but this seems not to work for types larger than + // 80-bit reals, this heuristic seems to work OK: + if(policies::digits<T, Policy>() > 64) + { + tolerance = pow(tools::epsilon<T>(), T(1)/4.25f); + BOOST_MATH_INSTRUMENT_VARIABLE(tolerance); + } + else + { + tolerance = pow(4*tools::epsilon<T>(), T(1)/6); + BOOST_MATH_INSTRUMENT_VARIABLE(tolerance); + } + + // duplication + k = 1; + do + { + u = (x + y + z) / 3; + X = (u - x) / u; + Y = (u - y) / u; + Z = (u - z) / u; + + // Termination condition: + if ((tools::max)(abs(X), abs(Y), abs(Z)) < tolerance) + break; + + T sx = sqrt(x); + T sy = sqrt(y); + T sz = sqrt(z); + lambda = sy * (sx + sz) + sz * sx; + x = (x + lambda) / 4; + y = (y + lambda) / 4; + z = (z + lambda) / 4; + ++k; + } + while(k < policies::get_max_series_iterations<Policy>()); + + // Check to see if we gave up too soon: + policies::check_series_iterations(function, k, pol); + BOOST_MATH_INSTRUMENT_VARIABLE(k); + + // Taylor series expansion to the 5th order + E2 = X * Y - Z * Z; + E3 = X * Y * Z; + value = (1 + E2*(E2/24 - E3*T(3)/44 - T(0.1)) + E3/14) / sqrt(u); + BOOST_MATH_INSTRUMENT_VARIABLE(value); + + return value; +} + +} // namespace detail + +template <class T1, class T2, class T3, class Policy> +inline typename tools::promote_args<T1, T2, T3>::type + ellint_rf(T1 x, T2 y, T3 z, const Policy& pol) +{ + typedef typename tools::promote_args<T1, T2, T3>::type result_type; + typedef typename policies::evaluation<result_type, Policy>::type value_type; + return policies::checked_narrowing_cast<result_type, Policy>( + detail::ellint_rf_imp( + static_cast<value_type>(x), + static_cast<value_type>(y), + static_cast<value_type>(z), pol), "boost::math::ellint_rf<%1%>(%1%,%1%,%1%)"); +} + +template <class T1, class T2, class T3> +inline typename tools::promote_args<T1, T2, T3>::type + ellint_rf(T1 x, T2 y, T3 z) +{ + return ellint_rf(x, y, z, policies::policy<>()); +} + +}} // namespaces + +#endif // BOOST_MATH_ELLINT_RF_HPP + diff --git a/Utilities/BGL/boost/math/special_functions/ellint_rj.hpp b/Utilities/BGL/boost/math/special_functions/ellint_rj.hpp new file mode 100644 index 0000000000000000000000000000000000000000..2caed3cecfd990bb3f96ea0ed149fae64bc6f15a --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/ellint_rj.hpp @@ -0,0 +1,180 @@ +// Copyright (c) 2006 Xiaogang Zhang +// Use, modification and distribution are subject to 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) +// +// History: +// XZ wrote the original of this file as part of the Google +// Summer of Code 2006. JM modified it to fit into the +// Boost.Math conceptual framework better, and to correctly +// handle the p < 0 case. +// + +#ifndef BOOST_MATH_ELLINT_RJ_HPP +#define BOOST_MATH_ELLINT_RJ_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/math/special_functions/math_fwd.hpp> +#include <boost/math/tools/config.hpp> +#include <boost/math/policies/error_handling.hpp> +#include <boost/math/special_functions/ellint_rc.hpp> +#include <boost/math/special_functions/ellint_rf.hpp> + +// Carlson's elliptic integral of the third kind +// R_J(x, y, z, p) = 1.5 * \int_{0}^{\infty} (t+p)^{-1} [(t+x)(t+y)(t+z)]^{-1/2} dt +// Carlson, Numerische Mathematik, vol 33, 1 (1979) + +namespace boost { namespace math { namespace detail{ + +template <typename T, typename Policy> +T ellint_rj_imp(T x, T y, T z, T p, const Policy& pol) +{ + T value, u, lambda, alpha, beta, sigma, factor, tolerance; + T X, Y, Z, P, EA, EB, EC, E2, E3, S1, S2, S3; + unsigned long k; + + BOOST_MATH_STD_USING + using namespace boost::math::tools; + + static const char* function = "boost::math::ellint_rj<%1%>(%1%,%1%,%1%)"; + + if (x < 0) + { + return policies::raise_domain_error<T>(function, + "Argument x must be non-negative, but got x = %1%", x, pol); + } + if(y < 0) + { + return policies::raise_domain_error<T>(function, + "Argument y must be non-negative, but got y = %1%", y, pol); + } + if(z < 0) + { + return policies::raise_domain_error<T>(function, + "Argument z must be non-negative, but got z = %1%", z, pol); + } + if(p == 0) + { + return policies::raise_domain_error<T>(function, + "Argument p must not be zero, but got p = %1%", p, pol); + } + if (x + y == 0 || y + z == 0 || z + x == 0) + { + return policies::raise_domain_error<T>(function, + "At most one argument can be zero, " + "only possible result is %1%.", std::numeric_limits<T>::quiet_NaN(), pol); + } + + // error scales as the 6th power of tolerance + tolerance = pow(T(1) * tools::epsilon<T>() / 3, T(1) / 6); + + // for p < 0, the integral is singular, return Cauchy principal value + if (p < 0) + { + // + // We must ensure that (z - y) * (y - x) is positive. + // Since the integral is symmetrical in x, y and z + // we can just permute the values: + // + if(x > y) + std::swap(x, y); + if(y > z) + std::swap(y, z); + if(x > y) + std::swap(x, y); + + T q = -p; + T pmy = (z - y) * (y - x) / (y + q); // p - y + + BOOST_ASSERT(pmy >= 0); + + T p = pmy + y; + value = boost::math::ellint_rj(x, y, z, p, pol); + value *= pmy; + value -= 3 * boost::math::ellint_rf(x, y, z, pol); + value += 3 * sqrt((x * y * z) / (x * z + p * q)) * boost::math::ellint_rc(x * z + p * q, p * q, pol); + value /= (y + q); + return value; + } + + // duplication + sigma = 0; + factor = 1; + k = 1; + do + { + u = (x + y + z + p + p) / 5; + X = (u - x) / u; + Y = (u - y) / u; + Z = (u - z) / u; + P = (u - p) / u; + + if ((tools::max)(abs(X), abs(Y), abs(Z), abs(P)) < tolerance) + break; + + T sx = sqrt(x); + T sy = sqrt(y); + T sz = sqrt(z); + + lambda = sy * (sx + sz) + sz * sx; + alpha = p * (sx + sy + sz) + sx * sy * sz; + alpha *= alpha; + beta = p * (p + lambda) * (p + lambda); + sigma += factor * boost::math::ellint_rc(alpha, beta, pol); + factor /= 4; + x = (x + lambda) / 4; + y = (y + lambda) / 4; + z = (z + lambda) / 4; + p = (p + lambda) / 4; + ++k; + } + while(k < policies::get_max_series_iterations<Policy>()); + + // Check to see if we gave up too soon: + policies::check_series_iterations(function, k, pol); + + // Taylor series expansion to the 5th order + EA = X * Y + Y * Z + Z * X; + EB = X * Y * Z; + EC = P * P; + E2 = EA - 3 * EC; + E3 = EB + 2 * P * (EA - EC); + S1 = 1 + E2 * (E2 * T(9) / 88 - E3 * T(9) / 52 - T(3) / 14); + S2 = EB * (T(1) / 6 + P * (T(-6) / 22 + P * T(3) / 26)); + S3 = P * ((EA - EC) / 3 - P * EA * T(3) / 22); + value = 3 * sigma + factor * (S1 + S2 + S3) / (u * sqrt(u)); + + return value; +} + +} // namespace detail + +template <class T1, class T2, class T3, class T4, class Policy> +inline typename tools::promote_args<T1, T2, T3, T4>::type + ellint_rj(T1 x, T2 y, T3 z, T4 p, const Policy& pol) +{ + typedef typename tools::promote_args<T1, T2, T3, T4>::type result_type; + typedef typename policies::evaluation<result_type, Policy>::type value_type; + return policies::checked_narrowing_cast<result_type, Policy>( + detail::ellint_rj_imp( + static_cast<value_type>(x), + static_cast<value_type>(y), + static_cast<value_type>(z), + static_cast<value_type>(p), + pol), "boost::math::ellint_rj<%1%>(%1%,%1%,%1%,%1%)"); +} + +template <class T1, class T2, class T3, class T4> +inline typename tools::promote_args<T1, T2, T3, T4>::type + ellint_rj(T1 x, T2 y, T3 z, T4 p) +{ + return ellint_rj(x, y, z, p, policies::policy<>()); +} + +}} // namespaces + +#endif // BOOST_MATH_ELLINT_RJ_HPP + diff --git a/Utilities/BGL/boost/math/special_functions/erf.hpp b/Utilities/BGL/boost/math/special_functions/erf.hpp new file mode 100644 index 0000000000000000000000000000000000000000..5b3f3b5059795d753bd8a526b7f05191417d8227 --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/erf.hpp @@ -0,0 +1,1088 @@ +// (C) Copyright John Maddock 2006. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_SPECIAL_ERF_HPP +#define BOOST_MATH_SPECIAL_ERF_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/math/special_functions/math_fwd.hpp> +#include <boost/math/tools/config.hpp> +#include <boost/math/special_functions/gamma.hpp> +#include <boost/math/tools/roots.hpp> +#include <boost/math/policies/error_handling.hpp> + +namespace boost{ namespace math{ + +namespace detail +{ + +// +// Asymptotic series for large z: +// +template <class T> +struct erf_asympt_series_t +{ + erf_asympt_series_t(T z) : xx(2 * -z * z), tk(1) + { + BOOST_MATH_STD_USING + result = -exp(-z * z) / sqrt(boost::math::constants::pi<T>()); + result /= z; + } + + typedef T result_type; + + T operator()() + { + BOOST_MATH_STD_USING + T r = result; + result *= tk / xx; + tk += 2; + if( fabs(r) < fabs(result)) + result = 0; + return r; + } +private: + T result; + T xx; + int tk; +}; +// +// How large z has to be in order to ensure that the series converges: +// +template <class T> +inline float erf_asymptotic_limit_N(const T&) +{ + return (std::numeric_limits<float>::max)(); +} +inline float erf_asymptotic_limit_N(const mpl::int_<24>&) +{ + return 2.8F; +} +inline float erf_asymptotic_limit_N(const mpl::int_<53>&) +{ + return 4.3F; +} +inline float erf_asymptotic_limit_N(const mpl::int_<64>&) +{ + return 4.8F; +} +inline float erf_asymptotic_limit_N(const mpl::int_<106>&) +{ + return 6.5F; +} +inline float erf_asymptotic_limit_N(const mpl::int_<113>&) +{ + return 6.8F; +} + +template <class T, class Policy> +inline T erf_asymptotic_limit() +{ + typedef typename policies::precision<T, Policy>::type precision_type; + typedef typename mpl::if_< + mpl::less_equal<precision_type, mpl::int_<24> >, + typename mpl::if_< + mpl::less_equal<precision_type, mpl::int_<0> >, + mpl::int_<0>, + mpl::int_<24> + >::type, + typename mpl::if_< + mpl::less_equal<precision_type, mpl::int_<53> >, + mpl::int_<53>, + typename mpl::if_< + mpl::less_equal<precision_type, mpl::int_<64> >, + mpl::int_<64>, + typename mpl::if_< + mpl::less_equal<precision_type, mpl::int_<106> >, + mpl::int_<106>, + typename mpl::if_< + mpl::less_equal<precision_type, mpl::int_<113> >, + mpl::int_<113>, + mpl::int_<0> + >::type + >::type + >::type + >::type + >::type tag_type; + return erf_asymptotic_limit_N(tag_type()); +} + +template <class T, class Policy, class Tag> +T erf_imp(T z, bool invert, const Policy& pol, const Tag& t) +{ + BOOST_MATH_STD_USING + + BOOST_MATH_INSTRUMENT_CODE("Generic erf_imp called"); + + if(z < 0) + { + if(!invert) + return -erf_imp(T(-z), invert, pol, t); + else + return 1 + erf_imp(T(-z), false, pol, t); + } + + T result; + + if(!invert && (z > detail::erf_asymptotic_limit<T, Policy>())) + { + detail::erf_asympt_series_t<T> s(z); + boost::uintmax_t max_iter = policies::get_max_series_iterations<Policy>(); + result = boost::math::tools::sum_series(s, policies::get_epsilon<T, Policy>(), max_iter, 1); + policies::check_series_iterations("boost::math::erf<%1%>(%1%, %1%)", max_iter, pol); + } + else + { + T x = z * z; + if(x < 0.6) + { + // Compute P: + result = z * exp(-x); + result /= sqrt(boost::math::constants::pi<T>()); + if(result != 0) + result *= 2 * detail::lower_gamma_series(T(0.5f), x, pol); + } + else if(x < 1.1f) + { + // Compute Q: + invert = !invert; + result = tgamma_small_upper_part(T(0.5f), x, pol); + result /= sqrt(boost::math::constants::pi<T>()); + } + else + { + // Compute Q: + invert = !invert; + result = z * exp(-x); + result /= sqrt(boost::math::constants::pi<T>()); + result *= upper_gamma_fraction(T(0.5f), x, policies::get_epsilon<T, Policy>()); + } + } + if(invert) + result = 1 - result; + return result; +} + +template <class T, class Policy> +T erf_imp(T z, bool invert, const Policy& pol, const mpl::int_<53>& t) +{ + BOOST_MATH_STD_USING + + BOOST_MATH_INSTRUMENT_CODE("53-bit precision erf_imp called"); + + if(z < 0) + { + if(!invert) + return -erf_imp(-z, invert, pol, t); + else if(z < -0.5) + return 2 - erf_imp(-z, invert, pol, t); + else + return 1 + erf_imp(-z, false, pol, t); + } + + T result; + + // + // Big bunch of selection statements now to pick + // which implementation to use, + // try to put most likely options first: + // + if(z < 0.5) + { + // + // We're going to calculate erf: + // + if(z < 1e-10) + { + if(z == 0) + { + result = T(0); + } + else + { + result = static_cast<T>(z * 1.125f + z * 0.003379167095512573896158903121545171688L); + } + } + else + { + // Maximum Deviation Found: 1.561e-17 + // Expected Error Term: 1.561e-17 + // Maximum Relative Change in Control Points: 1.155e-04 + // Max Error found at double precision = 2.961182e-17 + + static const T Y = 1.044948577880859375f; + static const T P[] = { + 0.0834305892146531832907L, + -0.338165134459360935041L, + -0.0509990735146777432841L, + -0.00772758345802133288487L, + -0.000322780120964605683831L, + }; + static const T Q[] = { + 1L, + 0.455004033050794024546L, + 0.0875222600142252549554L, + 0.00858571925074406212772L, + 0.000370900071787748000569L, + }; + T zz = z * z; + result = z * (Y + tools::evaluate_polynomial(P, zz) / tools::evaluate_polynomial(Q, zz)); + } + } + else if(invert ? (z < 28) : (z < 5.8f)) + { + // + // We'll be calculating erfc: + // + invert = !invert; + if(z < 1.5f) + { + // Maximum Deviation Found: 3.702e-17 + // Expected Error Term: 3.702e-17 + // Maximum Relative Change in Control Points: 2.845e-04 + // Max Error found at double precision = 4.841816e-17 + static const T Y = 0.405935764312744140625f; + static const T P[] = { + -0.098090592216281240205L, + 0.178114665841120341155L, + 0.191003695796775433986L, + 0.0888900368967884466578L, + 0.0195049001251218801359L, + 0.00180424538297014223957L, + }; + static const T Q[] = { + 1L, + 1.84759070983002217845L, + 1.42628004845511324508L, + 0.578052804889902404909L, + 0.12385097467900864233L, + 0.0113385233577001411017L, + 0.337511472483094676155e-5L, + }; + result = Y + tools::evaluate_polynomial(P, z - 0.5) / tools::evaluate_polynomial(Q, z - 0.5); + result *= exp(-z * z) / z; + } + else if(z < 2.5f) + { + // Max Error found at double precision = 6.599585e-18 + // Maximum Deviation Found: 3.909e-18 + // Expected Error Term: 3.909e-18 + // Maximum Relative Change in Control Points: 9.886e-05 + static const T Y = 0.50672817230224609375f; + static const T P[] = { + -0.0243500476207698441272L, + 0.0386540375035707201728L, + 0.04394818964209516296L, + 0.0175679436311802092299L, + 0.00323962406290842133584L, + 0.000235839115596880717416L, + }; + static const T Q[] = { + 1L, + 1.53991494948552447182L, + 0.982403709157920235114L, + 0.325732924782444448493L, + 0.0563921837420478160373L, + 0.00410369723978904575884L, + }; + result = Y + tools::evaluate_polynomial(P, z - 1.5) / tools::evaluate_polynomial(Q, z - 1.5); + result *= exp(-z * z) / z; + } + else if(z < 4.5f) + { + // Maximum Deviation Found: 1.512e-17 + // Expected Error Term: 1.512e-17 + // Maximum Relative Change in Control Points: 2.222e-04 + // Max Error found at double precision = 2.062515e-17 + static const T Y = 0.5405750274658203125f; + static const T P[] = { + 0.00295276716530971662634L, + 0.0137384425896355332126L, + 0.00840807615555585383007L, + 0.00212825620914618649141L, + 0.000250269961544794627958L, + 0.113212406648847561139e-4L, + }; + static const T Q[] = { + 1L, + 1.04217814166938418171L, + 0.442597659481563127003L, + 0.0958492726301061423444L, + 0.0105982906484876531489L, + 0.000479411269521714493907L, + }; + result = Y + tools::evaluate_polynomial(P, z - 3.5) / tools::evaluate_polynomial(Q, z - 3.5); + result *= exp(-z * z) / z; + } + else + { + // Max Error found at double precision = 2.997958e-17 + // Maximum Deviation Found: 2.860e-17 + // Expected Error Term: 2.859e-17 + // Maximum Relative Change in Control Points: 1.357e-05 + static const T Y = 0.5579090118408203125f; + static const T P[] = { + 0.00628057170626964891937L, + 0.0175389834052493308818L, + -0.212652252872804219852L, + -0.687717681153649930619L, + -2.5518551727311523996L, + -3.22729451764143718517L, + -2.8175401114513378771L, + }; + static const T Q[] = { + 1L, + 2.79257750980575282228L, + 11.0567237927800161565L, + 15.930646027911794143L, + 22.9367376522880577224L, + 13.5064170191802889145L, + 5.48409182238641741584L, + }; + result = Y + tools::evaluate_polynomial(P, 1 / z) / tools::evaluate_polynomial(Q, 1 / z); + result *= exp(-z * z) / z; + } + } + else + { + // + // Any value of z larger than 28 will underflow to zero: + // + result = 0; + invert = !invert; + } + + if(invert) + { + result = 1 - result; + } + + return result; +} // template <class T, class L>T erf_imp(T z, bool invert, const L& l, const mpl::int_<53>& t) + + +template <class T, class Policy> +T erf_imp(T z, bool invert, const Policy& pol, const mpl::int_<64>& t) +{ + BOOST_MATH_STD_USING + + BOOST_MATH_INSTRUMENT_CODE("64-bit precision erf_imp called"); + + if(z < 0) + { + if(!invert) + return -erf_imp(-z, invert, pol, t); + else if(z < -0.5) + return 2 - erf_imp(-z, invert, pol, t); + else + return 1 + erf_imp(-z, false, pol, t); + } + + T result; + + // + // Big bunch of selection statements now to pick which + // implementation to use, try to put most likely options + // first: + // + if(z < 0.5) + { + // + // We're going to calculate erf: + // + if(z == 0) + { + result = 0; + } + else if(z < 1e-10) + { + result = z * 1.125 + z * 0.003379167095512573896158903121545171688L; + } + else + { + // Max Error found at long double precision = 1.623299e-20 + // Maximum Deviation Found: 4.326e-22 + // Expected Error Term: -4.326e-22 + // Maximum Relative Change in Control Points: 1.474e-04 + static const T Y = 1.044948577880859375f; + static const T P[] = { + 0.0834305892146531988966L, + -0.338097283075565413695L, + -0.0509602734406067204596L, + -0.00904906346158537794396L, + -0.000489468651464798669181L, + -0.200305626366151877759e-4L, + }; + static const T Q[] = { + 1L, + 0.455817300515875172439L, + 0.0916537354356241792007L, + 0.0102722652675910031202L, + 0.000650511752687851548735L, + 0.189532519105655496778e-4L, + }; + result = z * (Y + tools::evaluate_polynomial(P, z * z) / tools::evaluate_polynomial(Q, z * z)); + } + } + else if(invert ? (z < 110) : (z < 6.4f)) + { + // + // We'll be calculating erfc: + // + invert = !invert; + if(z < 1.5) + { + // Max Error found at long double precision = 3.239590e-20 + // Maximum Deviation Found: 2.241e-20 + // Expected Error Term: -2.241e-20 + // Maximum Relative Change in Control Points: 5.110e-03 + static const T Y = 0.405935764312744140625f; + static const T P[] = { + -0.0980905922162812031672L, + 0.159989089922969141329L, + 0.222359821619935712378L, + 0.127303921703577362312L, + 0.0384057530342762400273L, + 0.00628431160851156719325L, + 0.000441266654514391746428L, + 0.266689068336295642561e-7L, + }; + static const T Q[] = { + 1L, + 2.03237474985469469291L, + 1.78355454954969405222L, + 0.867940326293760578231L, + 0.248025606990021698392L, + 0.0396649631833002269861L, + 0.00279220237309449026796L, + }; + result = Y + tools::evaluate_polynomial(P, z - 0.5f) / tools::evaluate_polynomial(Q, z - 0.5f); + result *= exp(-z * z) / z; + } + else if(z < 2.5) + { + // Max Error found at long double precision = 3.686211e-21 + // Maximum Deviation Found: 1.495e-21 + // Expected Error Term: -1.494e-21 + // Maximum Relative Change in Control Points: 1.793e-04 + static const T Y = 0.50672817230224609375f; + static const T P[] = { + -0.024350047620769840217L, + 0.0343522687935671451309L, + 0.0505420824305544949541L, + 0.0257479325917757388209L, + 0.00669349844190354356118L, + 0.00090807914416099524444L, + 0.515917266698050027934e-4L, + }; + static const T Q[] = { + 1L, + 1.71657861671930336344L, + 1.26409634824280366218L, + 0.512371437838969015941L, + 0.120902623051120950935L, + 0.0158027197831887485261L, + 0.000897871370778031611439L, + }; + result = Y + tools::evaluate_polynomial(P, z - 1.5f) / tools::evaluate_polynomial(Q, z - 1.5f); + result *= exp(-z * z) / z; + } + else if(z < 4.5) + { + // Maximum Deviation Found: 1.107e-20 + // Expected Error Term: -1.106e-20 + // Maximum Relative Change in Control Points: 1.709e-04 + // Max Error found at long double precision = 1.446908e-20 + static const T Y = 0.5405750274658203125f; + static const T P[] = { + 0.0029527671653097284033L, + 0.0141853245895495604051L, + 0.0104959584626432293901L, + 0.00343963795976100077626L, + 0.00059065441194877637899L, + 0.523435380636174008685e-4L, + 0.189896043050331257262e-5L, + }; + static const T Q[] = { + 1L, + 1.19352160185285642574L, + 0.603256964363454392857L, + 0.165411142458540585835L, + 0.0259729870946203166468L, + 0.00221657568292893699158L, + 0.804149464190309799804e-4L, + }; + result = Y + tools::evaluate_polynomial(P, z - 3.5f) / tools::evaluate_polynomial(Q, z - 3.5f); + result *= exp(-z * z) / z; + } + else + { + // Max Error found at long double precision = 7.961166e-21 + // Maximum Deviation Found: 6.677e-21 + // Expected Error Term: 6.676e-21 + // Maximum Relative Change in Control Points: 2.319e-05 + static const T Y = 0.55825519561767578125f; + static const T P[] = { + 0.00593438793008050214106L, + 0.0280666231009089713937L, + -0.141597835204583050043L, + -0.978088201154300548842L, + -5.47351527796012049443L, + -13.8677304660245326627L, + -27.1274948720539821722L, + -29.2545152747009461519L, + -16.8865774499799676937L, + }; + static const T Q[] = { + 1L, + 4.72948911186645394541L, + 23.6750543147695749212L, + 60.0021517335693186785L, + 131.766251645149522868L, + 178.167924971283482513L, + 182.499390505915222699L, + 104.365251479578577989L, + 30.8365511891224291717L, + }; + result = Y + tools::evaluate_polynomial(P, 1 / z) / tools::evaluate_polynomial(Q, 1 / z); + result *= exp(-z * z) / z; + } + } + else + { + // + // Any value of z larger than 110 will underflow to zero: + // + result = 0; + invert = !invert; + } + + if(invert) + { + result = 1 - result; + } + + return result; +} // template <class T, class L>T erf_imp(T z, bool invert, const L& l, const mpl::int_<64>& t) + + +template <class T, class Policy> +T erf_imp(T z, bool invert, const Policy& pol, const mpl::int_<113>& t) +{ + BOOST_MATH_STD_USING + + BOOST_MATH_INSTRUMENT_CODE("113-bit precision erf_imp called"); + + if(z < 0) + { + if(!invert) + return -erf_imp(-z, invert, pol, t); + else if(z < -0.5) + return 2 - erf_imp(-z, invert, pol, t); + else + return 1 + erf_imp(-z, false, pol, t); + } + + T result; + + // + // Big bunch of selection statements now to pick which + // implementation to use, try to put most likely options + // first: + // + if(z < 0.5) + { + // + // We're going to calculate erf: + // + if(z == 0) + { + result = 0; + } + else if(z < 1e-20) + { + result = z * 1.125 + z * 0.003379167095512573896158903121545171688L; + } + else + { + // Max Error found at long double precision = 2.342380e-35 + // Maximum Deviation Found: 6.124e-36 + // Expected Error Term: -6.124e-36 + // Maximum Relative Change in Control Points: 3.492e-10 + static const T Y = 1.0841522216796875f; + static const T P[] = { + 0.0442269454158250738961589031215451778L, + -0.35549265736002144875335323556961233L, + -0.0582179564566667896225454670863270393L, + -0.0112694696904802304229950538453123925L, + -0.000805730648981801146251825329609079099L, + -0.566304966591936566229702842075966273e-4L, + -0.169655010425186987820201021510002265e-5L, + -0.344448249920445916714548295433198544e-7L, + }; + static const T Q[] = { + 1L, + 0.466542092785657604666906909196052522L, + 0.100005087012526447295176964142107611L, + 0.0128341535890117646540050072234142603L, + 0.00107150448466867929159660677016658186L, + 0.586168368028999183607733369248338474e-4L, + 0.196230608502104324965623171516808796e-5L, + 0.313388521582925207734229967907890146e-7L, + }; + result = z * (Y + tools::evaluate_polynomial(P, z * z) / tools::evaluate_polynomial(Q, z * z)); + } + } + else if(invert ? (z < 110) : (z < 8.65f)) + { + // + // We'll be calculating erfc: + // + invert = !invert; + if(z < 1) + { + // Max Error found at long double precision = 3.246278e-35 + // Maximum Deviation Found: 1.388e-35 + // Expected Error Term: 1.387e-35 + // Maximum Relative Change in Control Points: 6.127e-05 + static const T Y = 0.371877193450927734375f; + static const T P[] = { + -0.0640320213544647969396032886581290455L, + 0.200769874440155895637857443946706731L, + 0.378447199873537170666487408805779826L, + 0.30521399466465939450398642044975127L, + 0.146890026406815277906781824723458196L, + 0.0464837937749539978247589252732769567L, + 0.00987895759019540115099100165904822903L, + 0.00137507575429025512038051025154301132L, + 0.0001144764551085935580772512359680516L, + 0.436544865032836914773944382339900079e-5L, + }; + static const T Q[] = { + 1L, + 2.47651182872457465043733800302427977L, + 2.78706486002517996428836400245547955L, + 1.87295924621659627926365005293130693L, + 0.829375825174365625428280908787261065L, + 0.251334771307848291593780143950311514L, + 0.0522110268876176186719436765734722473L, + 0.00718332151250963182233267040106902368L, + 0.000595279058621482041084986219276392459L, + 0.226988669466501655990637599399326874e-4L, + 0.270666232259029102353426738909226413e-10L, + }; + result = Y + tools::evaluate_polynomial(P, z - 0.5f) / tools::evaluate_polynomial(Q, z - 0.5f); + result *= exp(-z * z) / z; + } + else if(z < 1.5) + { + // Max Error found at long double precision = 2.215785e-35 + // Maximum Deviation Found: 1.539e-35 + // Expected Error Term: 1.538e-35 + // Maximum Relative Change in Control Points: 6.104e-05 + static const T Y = 0.45658016204833984375f; + static const T P[] = { + -0.0289965858925328393392496555094848345L, + 0.0868181194868601184627743162571779226L, + 0.169373435121178901746317404936356745L, + 0.13350446515949251201104889028133486L, + 0.0617447837290183627136837688446313313L, + 0.0185618495228251406703152962489700468L, + 0.00371949406491883508764162050169531013L, + 0.000485121708792921297742105775823900772L, + 0.376494706741453489892108068231400061e-4L, + 0.133166058052466262415271732172490045e-5L, + }; + static const T Q[] = { + 1L, + 2.32970330146503867261275580968135126L, + 2.46325715420422771961250513514928746L, + 1.55307882560757679068505047390857842L, + 0.644274289865972449441174485441409076L, + 0.182609091063258208068606847453955649L, + 0.0354171651271241474946129665801606795L, + 0.00454060370165285246451879969534083997L, + 0.000349871943711566546821198612518656486L, + 0.123749319840299552925421880481085392e-4L, + }; + result = Y + tools::evaluate_polynomial(P, z - 1.0f) / tools::evaluate_polynomial(Q, z - 1.0f); + result *= exp(-z * z) / z; + } + else if(z < 2.25) + { + // Maximum Deviation Found: 1.418e-35 + // Expected Error Term: 1.418e-35 + // Maximum Relative Change in Control Points: 1.316e-04 + // Max Error found at long double precision = 1.998462e-35 + static const T Y = 0.50250148773193359375f; + static const T P[] = { + -0.0201233630504573402185161184151016606L, + 0.0331864357574860196516686996302305002L, + 0.0716562720864787193337475444413405461L, + 0.0545835322082103985114927569724880658L, + 0.0236692635189696678976549720784989593L, + 0.00656970902163248872837262539337601845L, + 0.00120282643299089441390490459256235021L, + 0.000142123229065182650020762792081622986L, + 0.991531438367015135346716277792989347e-5L, + 0.312857043762117596999398067153076051e-6L, + }; + static const T Q[] = { + 1L, + 2.13506082409097783827103424943508554L, + 2.06399257267556230937723190496806215L, + 1.18678481279932541314830499880691109L, + 0.447733186643051752513538142316799562L, + 0.11505680005657879437196953047542148L, + 0.020163993632192726170219663831914034L, + 0.00232708971840141388847728782209730585L, + 0.000160733201627963528519726484608224112L, + 0.507158721790721802724402992033269266e-5L, + 0.18647774409821470950544212696270639e-12L, + }; + result = Y + tools::evaluate_polynomial(P, z - 1.5f) / tools::evaluate_polynomial(Q, z - 1.5f); + result *= exp(-z * z) / z; + } + else if (z < 3) + { + // Maximum Deviation Found: 3.575e-36 + // Expected Error Term: 3.575e-36 + // Maximum Relative Change in Control Points: 7.103e-05 + // Max Error found at long double precision = 5.794737e-36 + static const T Y = 0.52896785736083984375f; + static const T P[] = { + -0.00902152521745813634562524098263360074L, + 0.0145207142776691539346923710537580927L, + 0.0301681239582193983824211995978678571L, + 0.0215548540823305814379020678660434461L, + 0.00864683476267958365678294164340749949L, + 0.00219693096885585491739823283511049902L, + 0.000364961639163319762492184502159894371L, + 0.388174251026723752769264051548703059e-4L, + 0.241918026931789436000532513553594321e-5L, + 0.676586625472423508158937481943649258e-7L, + }; + static const T Q[] = { + 1L, + 1.93669171363907292305550231764920001L, + 1.69468476144051356810672506101377494L, + 0.880023580986436640372794392579985511L, + 0.299099106711315090710836273697708402L, + 0.0690593962363545715997445583603382337L, + 0.0108427016361318921960863149875360222L, + 0.00111747247208044534520499324234317695L, + 0.686843205749767250666787987163701209e-4L, + 0.192093541425429248675532015101904262e-5L, + }; + result = Y + tools::evaluate_polynomial(P, z - 2.25f) / tools::evaluate_polynomial(Q, z - 2.25f); + result *= exp(-z * z) / z; + } + else if(z < 3.5) + { + // Maximum Deviation Found: 8.126e-37 + // Expected Error Term: -8.126e-37 + // Maximum Relative Change in Control Points: 1.363e-04 + // Max Error found at long double precision = 1.747062e-36 + static const T Y = 0.54037380218505859375f; + static const T P[] = { + -0.0033703486408887424921155540591370375L, + 0.0104948043110005245215286678898115811L, + 0.0148530118504000311502310457390417795L, + 0.00816693029245443090102738825536188916L, + 0.00249716579989140882491939681805594585L, + 0.0004655591010047353023978045800916647L, + 0.531129557920045295895085236636025323e-4L, + 0.343526765122727069515775194111741049e-5L, + 0.971120407556888763695313774578711839e-7L, + }; + static const T Q[] = { + 1L, + 1.59911256167540354915906501335919317L, + 1.136006830764025173864831382946934L, + 0.468565867990030871678574840738423023L, + 0.122821824954470343413956476900662236L, + 0.0209670914950115943338996513330141633L, + 0.00227845718243186165620199012883547257L, + 0.000144243326443913171313947613547085553L, + 0.407763415954267700941230249989140046e-5L, + }; + result = Y + tools::evaluate_polynomial(P, z - 3.0f) / tools::evaluate_polynomial(Q, z - 3.0f); + result *= exp(-z * z) / z; + } + else if(z < 5.5) + { + // Maximum Deviation Found: 5.804e-36 + // Expected Error Term: -5.803e-36 + // Maximum Relative Change in Control Points: 2.475e-05 + // Max Error found at long double precision = 1.349545e-35 + static const T Y = 0.55000019073486328125f; + static const T P[] = { + 0.00118142849742309772151454518093813615L, + 0.0072201822885703318172366893469382745L, + 0.0078782276276860110721875733778481505L, + 0.00418229166204362376187593976656261146L, + 0.00134198400587769200074194304298642705L, + 0.000283210387078004063264777611497435572L, + 0.405687064094911866569295610914844928e-4L, + 0.39348283801568113807887364414008292e-5L, + 0.248798540917787001526976889284624449e-6L, + 0.929502490223452372919607105387474751e-8L, + 0.156161469668275442569286723236274457e-9L, + }; + static const T Q[] = { + 1L, + 1.52955245103668419479878456656709381L, + 1.06263944820093830054635017117417064L, + 0.441684612681607364321013134378316463L, + 0.121665258426166960049773715928906382L, + 0.0232134512374747691424978642874321434L, + 0.00310778180686296328582860464875562636L, + 0.000288361770756174705123674838640161693L, + 0.177529187194133944622193191942300132e-4L, + 0.655068544833064069223029299070876623e-6L, + 0.11005507545746069573608988651927452e-7L, + }; + result = Y + tools::evaluate_polynomial(P, z - 4.5f) / tools::evaluate_polynomial(Q, z - 4.5f); + result *= exp(-z * z) / z; + } + else if(z < 7.5) + { + // Maximum Deviation Found: 1.007e-36 + // Expected Error Term: 1.007e-36 + // Maximum Relative Change in Control Points: 1.027e-03 + // Max Error found at long double precision = 2.646420e-36 + static const T Y = 0.5574436187744140625f; + static const T P[] = { + 0.000293236907400849056269309713064107674L, + 0.00225110719535060642692275221961480162L, + 0.00190984458121502831421717207849429799L, + 0.000747757733460111743833929141001680706L, + 0.000170663175280949889583158597373928096L, + 0.246441188958013822253071608197514058e-4L, + 0.229818000860544644974205957895688106e-5L, + 0.134886977703388748488480980637704864e-6L, + 0.454764611880548962757125070106650958e-8L, + 0.673002744115866600294723141176820155e-10L, + }; + static const T Q[] = { + 1L, + 1.12843690320861239631195353379313367L, + 0.569900657061622955362493442186537259L, + 0.169094404206844928112348730277514273L, + 0.0324887449084220415058158657252147063L, + 0.00419252877436825753042680842608219552L, + 0.00036344133176118603523976748563178578L, + 0.204123895931375107397698245752850347e-4L, + 0.674128352521481412232785122943508729e-6L, + 0.997637501418963696542159244436245077e-8L, + }; + result = Y + tools::evaluate_polynomial(P, z - 6.5f) / tools::evaluate_polynomial(Q, z - 6.5f); + result *= exp(-z * z) / z; + } + else if(z < 11.5) + { + // Maximum Deviation Found: 8.380e-36 + // Expected Error Term: 8.380e-36 + // Maximum Relative Change in Control Points: 2.632e-06 + // Max Error found at long double precision = 9.849522e-36 + static const T Y = 0.56083202362060546875f; + static const T P[] = { + 0.000282420728751494363613829834891390121L, + 0.00175387065018002823433704079355125161L, + 0.0021344978564889819420775336322920375L, + 0.00124151356560137532655039683963075661L, + 0.000423600733566948018555157026862139644L, + 0.914030340865175237133613697319509698e-4L, + 0.126999927156823363353809747017945494e-4L, + 0.110610959842869849776179749369376402e-5L, + 0.55075079477173482096725348704634529e-7L, + 0.119735694018906705225870691331543806e-8L, + }; + static const T Q[] = { + 1L, + 1.69889613396167354566098060039549882L, + 1.28824647372749624464956031163282674L, + 0.572297795434934493541628008224078717L, + 0.164157697425571712377043857240773164L, + 0.0315311145224594430281219516531649562L, + 0.00405588922155632380812945849777127458L, + 0.000336929033691445666232029762868642417L, + 0.164033049810404773469413526427932109e-4L, + 0.356615210500531410114914617294694857e-6L, + }; + result = Y + tools::evaluate_polynomial(P, z / 2 - 4.75f) / tools::evaluate_polynomial(Q, z / 2 - 4.75f); + result *= exp(-z * z) / z; + } + else + { + // Maximum Deviation Found: 1.132e-35 + // Expected Error Term: -1.132e-35 + // Maximum Relative Change in Control Points: 4.674e-04 + // Max Error found at long double precision = 1.162590e-35 + static const T Y = 0.5632686614990234375f; + static const T P[] = { + 0.000920922048732849448079451574171836943L, + 0.00321439044532288750501700028748922439L, + -0.250455263029390118657884864261823431L, + -0.906807635364090342031792404764598142L, + -8.92233572835991735876688745989985565L, + -21.7797433494422564811782116907878495L, + -91.1451915251976354349734589601171659L, + -144.1279109655993927069052125017673L, + -313.845076581796338665519022313775589L, + -273.11378811923343424081101235736475L, + -271.651566205951067025696102600443452L, + -60.0530577077238079968843307523245547L, + }; + static const T Q[] = { + 1L, + 3.49040448075464744191022350947892036L, + 34.3563592467165971295915749548313227L, + 84.4993232033879023178285731843850461L, + 376.005865281206894120659401340373818L, + 629.95369438888946233003926191755125L, + 1568.35771983533158591604513304269098L, + 1646.02452040831961063640827116581021L, + 2299.96860633240298708910425594484895L, + 1222.73204392037452750381340219906374L, + 799.359797306084372350264298361110448L, + 72.7415265778588087243442792401576737L, + }; + result = Y + tools::evaluate_polynomial(P, 1 / z) / tools::evaluate_polynomial(Q, 1 / z); + result *= exp(-z * z) / z; + } + } + else + { + // + // Any value of z larger than 110 will underflow to zero: + // + result = 0; + invert = !invert; + } + + if(invert) + { + result = 1 - result; + } + + return result; +} // template <class T, class L>T erf_imp(T z, bool invert, const L& l, const mpl::int_<113>& t) + +} // namespace detail + +template <class T, class Policy> +inline typename tools::promote_args<T>::type erf(T z, const Policy& /* pol */) +{ + typedef typename tools::promote_args<T>::type result_type; + typedef typename policies::evaluation<result_type, Policy>::type value_type; + typedef typename policies::precision<result_type, Policy>::type precision_type; + typedef typename policies::normalise< + Policy, + policies::promote_float<false>, + policies::promote_double<false>, + policies::discrete_quantile<>, + policies::assert_undefined<> >::type forwarding_policy; + + BOOST_MATH_INSTRUMENT_CODE("result_type = " << typeid(result_type).name()); + BOOST_MATH_INSTRUMENT_CODE("value_type = " << typeid(value_type).name()); + BOOST_MATH_INSTRUMENT_CODE("precision_type = " << typeid(precision_type).name()); + + typedef typename mpl::if_< + mpl::less_equal<precision_type, mpl::int_<0> >, + mpl::int_<0>, + typename mpl::if_< + mpl::less_equal<precision_type, mpl::int_<53> >, + mpl::int_<53>, // double + typename mpl::if_< + mpl::less_equal<precision_type, mpl::int_<64> >, + mpl::int_<64>, // 80-bit long double + typename mpl::if_< + mpl::less_equal<precision_type, mpl::int_<113> >, + mpl::int_<113>, // 128-bit long double + mpl::int_<0> // too many bits, use generic version. + >::type + >::type + >::type + >::type tag_type; + + BOOST_MATH_INSTRUMENT_CODE("tag_type = " << typeid(tag_type).name()); + + return policies::checked_narrowing_cast<result_type, forwarding_policy>(detail::erf_imp( + static_cast<value_type>(z), + false, + forwarding_policy(), + tag_type()), "boost::math::erf<%1%>(%1%, %1%)"); +} + +template <class T, class Policy> +inline typename tools::promote_args<T>::type erfc(T z, const Policy& /* pol */) +{ + typedef typename tools::promote_args<T>::type result_type; + typedef typename policies::evaluation<result_type, Policy>::type value_type; + typedef typename policies::precision<result_type, Policy>::type precision_type; + typedef typename policies::normalise< + Policy, + policies::promote_float<false>, + policies::promote_double<false>, + policies::discrete_quantile<>, + policies::assert_undefined<> >::type forwarding_policy; + + BOOST_MATH_INSTRUMENT_CODE("result_type = " << typeid(result_type).name()); + BOOST_MATH_INSTRUMENT_CODE("value_type = " << typeid(value_type).name()); + BOOST_MATH_INSTRUMENT_CODE("precision_type = " << typeid(precision_type).name()); + + typedef typename mpl::if_< + mpl::less_equal<precision_type, mpl::int_<0> >, + mpl::int_<0>, + typename mpl::if_< + mpl::less_equal<precision_type, mpl::int_<53> >, + mpl::int_<53>, // double + typename mpl::if_< + mpl::less_equal<precision_type, mpl::int_<64> >, + mpl::int_<64>, // 80-bit long double + typename mpl::if_< + mpl::less_equal<precision_type, mpl::int_<113> >, + mpl::int_<113>, // 128-bit long double + mpl::int_<0> // too many bits, use generic version. + >::type + >::type + >::type + >::type tag_type; + + BOOST_MATH_INSTRUMENT_CODE("tag_type = " << typeid(tag_type).name()); + + return policies::checked_narrowing_cast<result_type, forwarding_policy>(detail::erf_imp( + static_cast<value_type>(z), + true, + forwarding_policy(), + tag_type()), "boost::math::erfc<%1%>(%1%, %1%)"); +} + +template <class T> +inline typename tools::promote_args<T>::type erf(T z) +{ + return boost::math::erf(z, policies::policy<>()); +} + +template <class T> +inline typename tools::promote_args<T>::type erfc(T z) +{ + return boost::math::erfc(z, policies::policy<>()); +} + +} // namespace math +} // namespace boost + +#include <boost/math/special_functions/detail/erf_inv.hpp> + +#endif // BOOST_MATH_SPECIAL_ERF_HPP + + + + diff --git a/Utilities/BGL/boost/math/special_functions/expint.hpp b/Utilities/BGL/boost/math/special_functions/expint.hpp new file mode 100644 index 0000000000000000000000000000000000000000..acb203d58f16a3c19704879f9c41814fd729665d --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/expint.hpp @@ -0,0 +1,1514 @@ +// Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_EXPINT_HPP +#define BOOST_MATH_EXPINT_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/math/tools/precision.hpp> +#include <boost/math/tools/promotion.hpp> +#include <boost/math/tools/fraction.hpp> +#include <boost/math/tools/series.hpp> +#include <boost/math/policies/error_handling.hpp> +#include <boost/math/special_functions/digamma.hpp> +#include <boost/math/special_functions/log1p.hpp> +#include <boost/math/special_functions/pow.hpp> + +namespace boost{ namespace math{ + +template <class T, class Policy> +inline typename tools::promote_args<T>::type + expint(unsigned n, T z, const Policy& /*pol*/); + +namespace detail{ + +template <class T> +inline T expint_1_rational(const T& z, const mpl::int_<0>&) +{ + // this function is never actually called + BOOST_ASSERT(0); + return z; +} + +template <class T> +T expint_1_rational(const T& z, const mpl::int_<53>&) +{ + BOOST_MATH_STD_USING + T result; + if(z <= 1) + { + // Maximum Deviation Found: 2.006e-18 + // Expected Error Term: 2.006e-18 + // Max error found at double precision: 2.760e-17 + static const T Y = 0.66373538970947265625F; + static const T P[6] = { + 0.0865197248079397976498L, + 0.0320913665303559189999L, + -0.245088216639761496153L, + -0.0368031736257943745142L, + -0.00399167106081113256961L, + -0.000111507792921197858394L + }; + static const T Q[6] = { + 1L, + 0.37091387659397013215L, + 0.056770677104207528384L, + 0.00427347600017103698101L, + 0.000131049900798434683324L, + -0.528611029520217142048e-6L + }; + result = tools::evaluate_polynomial(P, z) + / tools::evaluate_polynomial(Q, z); + result += z - log(z) - Y; + } + else if(z < -boost::math::tools::log_min_value<T>()) + { + // Maximum Deviation Found (interpolated): 1.444e-17 + // Max error found at double precision: 3.119e-17 + static const T P[11] = { + -0.121013190657725568138e-18L, + -0.999999999999998811143L, + -43.3058660811817946037L, + -724.581482791462469795L, + -6046.8250112711035463L, + -27182.6254466733970467L, + -66598.2652345418633509L, + -86273.1567711649528784L, + -54844.4587226402067411L, + -14751.4895786128450662L, + -1185.45720315201027667L + }; + static const T Q[12] = { + 1L, + 45.3058660811801465927L, + 809.193214954550328455L, + 7417.37624454689546708L, + 38129.5594484818471461L, + 113057.05869159631492L, + 192104.047790227984431L, + 180329.498380501819718L, + 86722.3403467334749201L, + 18455.4124737722049515L, + 1229.20784182403048905L, + -0.776491285282330997549L + }; + T recip = 1 / z; + result = 1 + tools::evaluate_polynomial(P, recip) + / tools::evaluate_polynomial(Q, recip); + result *= exp(-z) * recip; + } + else + { + result = 0; + } + return result; +} + +template <class T> +T expint_1_rational(const T& z, const mpl::int_<64>&) +{ + BOOST_MATH_STD_USING + T result; + if(z <= 1) + { + // Maximum Deviation Found: 3.807e-20 + // Expected Error Term: 3.807e-20 + // Max error found at long double precision: 6.249e-20 + + static const T Y = 0.66373538970947265625F; + static const T P[6] = { + 0.0865197248079397956816L, + 0.0275114007037026844633L, + -0.246594388074877139824L, + -0.0237624819878732642231L, + -0.00259113319641673986276L, + 0.30853660894346057053e-4L + }; + static const T Q[7] = { + 1L, + 0.317978365797784100273L, + 0.0393622602554758722511L, + 0.00204062029115966323229L, + 0.732512107100088047854e-5L, + -0.202872781770207871975e-5L, + 0.52779248094603709945e-7L + }; + result = tools::evaluate_polynomial(P, z) + / tools::evaluate_polynomial(Q, z); + result += z - log(z) - Y; + } + else if(z < -boost::math::tools::log_min_value<T>()) + { + // Maximum Deviation Found (interpolated): 2.220e-20 + // Max error found at long double precision: 1.346e-19 + static const T P[14] = { + -0.534401189080684443046e-23L, + -0.999999999999999999905L, + -62.1517806091379402505L, + -1568.45688271895145277L, + -21015.3431990874009619L, + -164333.011755931661949L, + -777917.270775426696103L, + -2244188.56195255112937L, + -3888702.98145335643429L, + -3909822.65621952648353L, + -2149033.9538897398457L, + -584705.537139793925189L, + -65815.2605361889477244L, + -2038.82870680427258038L + }; + static const T Q[14] = { + 1L, + 64.1517806091379399478L, + 1690.76044393722763785L, + 24035.9534033068949426L, + 203679.998633572361706L, + 1074661.58459976978285L, + 3586552.65020899358773L, + 7552186.84989547621411L, + 9853333.79353054111434L, + 7689642.74550683631258L, + 3385553.35146759180739L, + 763218.072732396428725L, + 73930.2995984054930821L, + 2063.86994219629165937L + }; + T recip = 1 / z; + result = 1 + tools::evaluate_polynomial(P, recip) + / tools::evaluate_polynomial(Q, recip); + result *= exp(-z) * recip; + } + else + { + result = 0; + } + return result; +} + +template <class T> +T expint_1_rational(const T& z, const mpl::int_<113>&) +{ + BOOST_MATH_STD_USING + T result; + if(z <= 1) + { + // Maximum Deviation Found: 2.477e-35 + // Expected Error Term: 2.477e-35 + // Max error found at long double precision: 6.810e-35 + + static const T Y = 0.66373538970947265625F; + static const T P[10] = { + 0.0865197248079397956434879099175975937L, + 0.0369066175910795772830865304506087759L, + -0.24272036838415474665971599314725545L, + -0.0502166331248948515282379137550178307L, + -0.00768384138547489410285101483730424919L, + -0.000612574337702109683505224915484717162L, + -0.380207107950635046971492617061708534e-4L, + -0.136528159460768830763009294683628406e-5L, + -0.346839106212658259681029388908658618e-7L, + -0.340500302777838063940402160594523429e-9L + }; + static const T Q[10] = { + 1L, + 0.426568827778942588160423015589537302L, + 0.0841384046470893490592450881447510148L, + 0.0100557215850668029618957359471132995L, + 0.000799334870474627021737357294799839363L, + 0.434452090903862735242423068552687688e-4L, + 0.15829674748799079874182885081231252e-5L, + 0.354406206738023762100882270033082198e-7L, + 0.369373328141051577845488477377890236e-9L, + -0.274149801370933606409282434677600112e-12L + }; + result = tools::evaluate_polynomial(P, z) + / tools::evaluate_polynomial(Q, z); + result += z - log(z) - Y; + } + else if(z <= 4) + { + // Max error in interpolated form: 5.614e-35 + // Max error found at long double precision: 7.979e-35 + + static const T Y = 0.70190334320068359375F; + + static const T P[17] = { + 0.298096656795020369955077350585959794L, + 12.9314045995266142913135497455971247L, + 226.144334921582637462526628217345501L, + 2070.83670924261732722117682067381405L, + 10715.1115684330959908244769731347186L, + 30728.7876355542048019664777316053311L, + 38520.6078609349855436936232610875297L, + -27606.0780981527583168728339620565165L, + -169026.485055785605958655247592604835L, + -254361.919204983608659069868035092282L, + -195765.706874132267953259272028679935L, + -83352.6826013533205474990119962408675L, + -19251.6828496869586415162597993050194L, + -2226.64251774578542836725386936102339L, + -109.009437301400845902228611986479816L, + -1.51492042209561411434644938098833499L + }; + static const T Q[16] = { + 1L, + 46.734521442032505570517810766704587L, + 908.694714348462269000247450058595655L, + 9701.76053033673927362784882748513195L, + 63254.2815292641314236625196594947774L, + 265115.641285880437335106541757711092L, + 732707.841188071900498536533086567735L, + 1348514.02492635723327306628712057794L, + 1649986.81455283047769673308781585991L, + 1326000.828522976970116271208812099L, + 683643.09490612171772350481773951341L, + 217640.505137263607952365685653352229L, + 40288.3467237411710881822569476155485L, + 3932.89353979531632559232883283175754L, + 169.845369689596739824177412096477219L, + 2.17607292280092201170768401876895354L + }; + T recip = 1 / z; + result = Y + tools::evaluate_polynomial(P, recip) + / tools::evaluate_polynomial(Q, recip); + result *= exp(-z) * recip; + } + else if(z < -boost::math::tools::log_min_value<T>()) + { + // Max error in interpolated form: 4.413e-35 + // Max error found at long double precision: 8.928e-35 + + static const T P[19] = { + -0.559148411832951463689610809550083986e-40L, + -0.999999999999999999999999999999999997L, + -166.542326331163836642960118190147367L, + -12204.639128796330005065904675153652L, + -520807.069767086071806275022036146855L, + -14435981.5242137970691490903863125326L, + -274574945.737064301247496460758654196L, + -3691611582.99810039356254671781473079L, + -35622515944.8255047299363690814678763L, + -248040014774.502043161750715548451142L, + -1243190389769.53458416330946622607913L, + -4441730126135.54739052731990368425339L, + -11117043181899.7388524310281751971366L, + -18976497615396.9717776601813519498961L, + -21237496819711.1011661104761906067131L, + -14695899122092.5161620333466757812848L, + -5737221535080.30569711574295785864903L, + -1077042281708.42654526404581272546244L, + -68028222642.1941480871395695677675137L + }; + static const T Q[20] = { + 1L, + 168.542326331163836642960118190147311L, + 12535.7237814586576783518249115343619L, + 544891.263372016404143120911148640627L, + 15454474.7241010258634446523045237762L, + 302495899.896629522673410325891717381L, + 4215565948.38886507646911672693270307L, + 42552409471.7951815668506556705733344L, + 313592377066.753173979584098301610186L, + 1688763640223.4541980740597514904542L, + 6610992294901.59589748057620192145704L, + 18601637235659.6059890851321772682606L, + 36944278231087.2571020964163402941583L, + 50425858518481.7497071917028793820058L, + 45508060902865.0899967797848815980644L, + 25649955002765.3817331501988304758142L, + 8259575619094.6518520988612711292331L, + 1299981487496.12607474362723586264515L, + 70242279152.8241187845178443118302693L, + -37633302.9409263839042721539363416685L + }; + T recip = 1 / z; + result = 1 + tools::evaluate_polynomial(P, recip) + / tools::evaluate_polynomial(Q, recip); + result *= exp(-z) * recip; + } + else + { + result = 0; + } + return result; +} + +template <class T> +struct expint_fraction +{ + typedef std::pair<T,T> result_type; + expint_fraction(unsigned n_, T z_) : b(n_ + z_), i(-1), n(n_){} + std::pair<T,T> operator()() + { + std::pair<T,T> result = std::make_pair(-static_cast<T>((i+1) * (n+i)), b); + b += 2; + ++i; + return result; + } +private: + T b; + int i; + unsigned n; +}; + +template <class T, class Policy> +inline T expint_as_fraction(unsigned n, T z, const Policy& pol) +{ + BOOST_MATH_STD_USING + BOOST_MATH_INSTRUMENT_VARIABLE(z) + boost::uintmax_t max_iter = policies::get_max_series_iterations<Policy>(); + expint_fraction<T> f(n, z); + T result = tools::continued_fraction_b( + f, + boost::math::policies::get_epsilon<T, Policy>(), + max_iter); + policies::check_series_iterations("boost::math::expint_continued_fraction<%1%>(unsigned,%1%)", max_iter, pol); + BOOST_MATH_INSTRUMENT_VARIABLE(result) + BOOST_MATH_INSTRUMENT_VARIABLE(max_iter) + result = exp(-z) / result; + BOOST_MATH_INSTRUMENT_VARIABLE(result) + return result; +} + +template <class T> +struct expint_series +{ + typedef T result_type; + expint_series(unsigned k_, T z_, T x_k_, T denom_, T fact_) + : k(k_), z(z_), x_k(x_k_), denom(denom_), fact(fact_){} + T operator()() + { + x_k *= -z; + denom += 1; + fact *= ++k; + return x_k / (denom * fact); + } +private: + unsigned k; + T z; + T x_k; + T denom; + T fact; +}; + +template <class T, class Policy> +inline T expint_as_series(unsigned n, T z, const Policy& pol) +{ + BOOST_MATH_STD_USING + boost::uintmax_t max_iter = policies::get_max_series_iterations<Policy>(); + + BOOST_MATH_INSTRUMENT_VARIABLE(z) + + T result = 0; + T x_k = -1; + T denom = T(1) - n; + T fact = 1; + unsigned k = 0; + for(; k < n - 1;) + { + result += x_k / (denom * fact); + denom += 1; + x_k *= -z; + fact *= ++k; + } + BOOST_MATH_INSTRUMENT_VARIABLE(result) + result += pow(-z, static_cast<T>(n - 1)) + * (boost::math::digamma(static_cast<T>(n)) - log(z)) / fact; + BOOST_MATH_INSTRUMENT_VARIABLE(result) + + expint_series<T> s(k, z, x_k, denom, fact); + result = tools::sum_series(s, policies::get_epsilon<T, Policy>(), max_iter, result); + policies::check_series_iterations("boost::math::expint_series<%1%>(unsigned,%1%)", max_iter, pol); + BOOST_MATH_INSTRUMENT_VARIABLE(result) + BOOST_MATH_INSTRUMENT_VARIABLE(max_iter) + return result; +} + +template <class T, class Policy, class Tag> +T expint_imp(unsigned n, T z, const Policy& pol, const Tag& tag) +{ + BOOST_MATH_STD_USING + static const char* function = "boost::math::expint<%1%>(unsigned, %1%)"; + if(z < 0) + return policies::raise_domain_error<T>(function, "Function requires z >= 0 but got %1%.", z, pol); + if(z == 0) + return n == 1 ? policies::raise_overflow_error<T>(function, 0, pol) : T(1 / (static_cast<T>(n - 1))); + + T result; + + bool f; + if(n < 3) + { + f = z < 0.5; + } + else + { + f = z < (static_cast<T>(n - 2) / static_cast<T>(n - 1)); + } +#ifdef BOOST_MSVC +# pragma warning(push) +# pragma warning(disable:4127) // conditional expression is constant +#endif + if(n == 0) + result = exp(-z) / z; + else if((n == 1) && (Tag::value)) + { + result = expint_1_rational(z, tag); + } + else if(f) + result = expint_as_series(n, z, pol); + else + result = expint_as_fraction(n, z, pol); +#ifdef BOOST_MSVC +# pragma warning(pop) +#endif + + return result; +} + +template <class T> +struct expint_i_series +{ + typedef T result_type; + expint_i_series(T z_) : k(0), z_k(1), z(z_){} + T operator()() + { + z_k *= z / ++k; + return z_k / k; + } +private: + unsigned k; + T z_k; + T z; +}; + +template <class T, class Policy> +T expint_i_as_series(T z, const Policy& pol) +{ + BOOST_MATH_STD_USING + T result = log(z); // (log(z) - log(1 / z)) / 2; + result += constants::euler<T>(); + expint_i_series<T> s(z); + boost::uintmax_t max_iter = policies::get_max_series_iterations<Policy>(); + result = tools::sum_series(s, policies::get_epsilon<T, Policy>(), max_iter, result); + policies::check_series_iterations("boost::math::expint_i_series<%1%>(%1%)", max_iter, pol); + return result; +} + +template <class T, class Policy, class Tag> +T expint_i_imp(T z, const Policy& pol, const Tag& tag) +{ + static const char* function = "boost::math::expint<%1%>(%1%)"; + if(z < 0) + return -expint_imp(1, T(-z), pol, tag); + if(z == 0) + return -policies::raise_overflow_error<T>(function, 0, pol); + return expint_i_as_series(z, pol); +} + +template <class T, class Policy> +T expint_i_imp(T z, const Policy& pol, const mpl::int_<53>& tag) +{ + BOOST_MATH_STD_USING + static const char* function = "boost::math::expint<%1%>(%1%)"; + if(z < 0) + return -expint_imp(1, -z, pol, tag); + if(z == 0) + return -policies::raise_overflow_error<T>(function, 0, pol); + + T result; + + if(z <= 6) + { + // Maximum Deviation Found: 2.852e-18 + // Expected Error Term: 2.852e-18 + // Max Error found at double precision = Poly: 2.636335e-16 Cheb: 4.187027e-16 + static const T P[10] = { + 2.98677224343598593013L, + 0.356343618769377415068L, + 0.780836076283730801839L, + 0.114670926327032002811L, + 0.0499434773576515260534L, + 0.00726224593341228159561L, + 0.00115478237227804306827L, + 0.000116419523609765200999L, + 0.798296365679269702435e-5L, + 0.2777056254402008721e-6L + }; + static const T Q[8] = { + 1L, + -1.17090412365413911947L, + 0.62215109846016746276L, + -0.195114782069495403315L, + 0.0391523431392967238166L, + -0.00504800158663705747345L, + 0.000389034007436065401822L, + -0.138972589601781706598e-4L + }; + + static const T r1 = static_cast<T>(1677624236387711.0L / 4503599627370496.0L); + static const T r2 = 0.131401834143860282009280387409357165515556574352422001206362e-16L; + static const T r = static_cast<T>(0.372507410781366634461991866580119133535689497771654051555657435242200120636201854384926049951548942392L); + T t = (z / 3) - 1; + result = tools::evaluate_polynomial(P, t) + / tools::evaluate_polynomial(Q, t); + t = (z - r1) - r2; + result *= t; + if(fabs(t) < 0.1) + { + result += boost::math::log1p(t / r); + } + else + { + result += log(z / r); + } + } + else if (z <= 10) + { + // Maximum Deviation Found: 6.546e-17 + // Expected Error Term: 6.546e-17 + // Max Error found at double precision = Poly: 6.890169e-17 Cheb: 6.772128e-17 + static const T Y = 1.158985137939453125F; + static const T P[8] = { + 0.00139324086199402804173L, + -0.0349921221823888744966L, + -0.0264095520754134848538L, + -0.00761224003005476438412L, + -0.00247496209592143627977L, + -0.000374885917942100256775L, + -0.554086272024881826253e-4L, + -0.396487648924804510056e-5L + }; + static const T Q[8] = { + 1L, + 0.744625566823272107711L, + 0.329061095011767059236L, + 0.100128624977313872323L, + 0.0223851099128506347278L, + 0.00365334190742316650106L, + 0.000402453408512476836472L, + 0.263649630720255691787e-4L + }; + T t = z / 2 - 4; + result = Y + tools::evaluate_polynomial(P, t) + / tools::evaluate_polynomial(Q, t); + result *= exp(z) / z; + result += z; + } + else if(z <= 20) + { + // Maximum Deviation Found: 1.843e-17 + // Expected Error Term: -1.842e-17 + // Max Error found at double precision = Poly: 4.375868e-17 Cheb: 5.860967e-17 + + static const T Y = 1.0869731903076171875F; + static const T P[9] = { + -0.00893891094356945667451L, + -0.0484607730127134045806L, + -0.0652810444222236895772L, + -0.0478447572647309671455L, + -0.0226059218923777094596L, + -0.00720603636917482065907L, + -0.00155941947035972031334L, + -0.000209750022660200888349L, + -0.138652200349182596186e-4L + }; + static const T Q[9] = { + 1L, + 1.97017214039061194971L, + 1.86232465043073157508L, + 1.09601437090337519977L, + 0.438873285773088870812L, + 0.122537731979686102756L, + 0.0233458478275769288159L, + 0.00278170769163303669021L, + 0.000159150281166108755531L + }; + T t = z / 5 - 3; + result = Y + tools::evaluate_polynomial(P, t) + / tools::evaluate_polynomial(Q, t); + result *= exp(z) / z; + result += z; + } + else if(z <= 40) + { + // Maximum Deviation Found: 5.102e-18 + // Expected Error Term: 5.101e-18 + // Max Error found at double precision = Poly: 1.441088e-16 Cheb: 1.864792e-16 + + + static const T Y = 1.03937530517578125F; + static const T P[9] = { + -0.00356165148914447597995L, + -0.0229930320357982333406L, + -0.0449814350482277917716L, + -0.0453759383048193402336L, + -0.0272050837209380717069L, + -0.00994403059883350813295L, + -0.00207592267812291726961L, + -0.000192178045857733706044L, + -0.113161784705911400295e-9L + }; + static const T Q[9] = { + 1L, + 2.84354408840148561131L, + 3.6599610090072393012L, + 2.75088464344293083595L, + 1.2985244073998398643L, + 0.383213198510794507409L, + 0.0651165455496281337831L, + 0.00488071077519227853585L + }; + T t = z / 10 - 3; + result = Y + tools::evaluate_polynomial(P, t) + / tools::evaluate_polynomial(Q, t); + result *= exp(z) / z; + result += z; + } + else + { + // Max Error found at double precision = 3.381886e-17 + static const T exp40 = static_cast<T>(2.35385266837019985407899910749034804508871617254555467236651e17L); + static const T Y= 1.013065338134765625F; + static const T P[6] = { + -0.0130653381347656243849L, + 0.19029710559486576682L, + 94.7365094537197236011L, + -2516.35323679844256203L, + 18932.0850014925993025L, + -38703.1431362056714134L + }; + static const T Q[7] = { + 1L, + 61.9733592849439884145L, + -2354.56211323420194283L, + 22329.1459489893079041L, + -70126.245140396567133L, + 54738.2833147775537106L, + 8297.16296356518409347L + }; + T t = 1 / z; + result = Y + tools::evaluate_polynomial(P, t) + / tools::evaluate_polynomial(Q, t); + if(z < 41) + result *= exp(z) / z; + else + { + // Avoid premature overflow if we can: + t = z - 40; + if(t > tools::log_max_value<T>()) + { + result = policies::raise_overflow_error<T>(function, 0, pol); + } + else + { + result *= exp(z - 40) / z; + if(result > tools::max_value<T>() / exp40) + { + result = policies::raise_overflow_error<T>(function, 0, pol); + } + else + { + result *= exp40; + } + } + } + result += z; + } + return result; +} + +template <class T, class Policy> +T expint_i_imp(T z, const Policy& pol, const mpl::int_<64>& tag) +{ + BOOST_MATH_STD_USING + static const char* function = "boost::math::expint<%1%>(%1%)"; + if(z < 0) + return -expint_imp(1, -z, pol, tag); + if(z == 0) + return -policies::raise_overflow_error<T>(function, 0, pol); + + T result; + + if(z <= 6) + { + // Maximum Deviation Found: 3.883e-21 + // Expected Error Term: 3.883e-21 + // Max Error found at long double precision = Poly: 3.344801e-19 Cheb: 4.989937e-19 + + static const T P[11] = { + 2.98677224343598593764L, + 0.25891613550886736592L, + 0.789323584998672832285L, + 0.092432587824602399339L, + 0.0514236978728625906656L, + 0.00658477469745132977921L, + 0.00124914538197086254233L, + 0.000131429679565472408551L, + 0.11293331317982763165e-4L, + 0.629499283139417444244e-6L, + 0.177833045143692498221e-7L + }; + static const T Q[9] = { + 1L, + -1.20352377969742325748L, + 0.66707904942606479811L, + -0.223014531629140771914L, + 0.0493340022262908008636L, + -0.00741934273050807310677L, + 0.00074353567782087939294L, + -0.455861727069603367656e-4L, + 0.131515429329812837701e-5L + }; + + static const T r1 = static_cast<T>(1677624236387711.0L / 4503599627370496.0L); + static const T r2 = 0.131401834143860282009280387409357165515556574352422001206362e-16L; + static const T r = static_cast<T>(0.372507410781366634461991866580119133535689497771654051555657435242200120636201854384926049951548942392L); + T t = (z / 3) - 1; + result = tools::evaluate_polynomial(P, t) + / tools::evaluate_polynomial(Q, t); + t = (z - r1) - r2; + result *= t; + if(fabs(t) < 0.1) + { + result += boost::math::log1p(t / r); + } + else + { + result += log(z / r); + } + } + else if (z <= 10) + { + // Maximum Deviation Found: 2.622e-21 + // Expected Error Term: -2.622e-21 + // Max Error found at long double precision = Poly: 1.208328e-20 Cheb: 1.073723e-20 + + static const T Y = 1.158985137939453125F; + static const T P[9] = { + 0.00139324086199409049399L, + -0.0345238388952337563247L, + -0.0382065278072592940767L, + -0.0156117003070560727392L, + -0.00383276012430495387102L, + -0.000697070540945496497992L, + -0.877310384591205930343e-4L, + -0.623067256376494930067e-5L, + -0.377246883283337141444e-6L + }; + static const T Q[10] = { + 1L, + 1.08073635708902053767L, + 0.553681133533942532909L, + 0.176763647137553797451L, + 0.0387891748253869928121L, + 0.0060603004848394727017L, + 0.000670519492939992806051L, + 0.4947357050100855646e-4L, + 0.204339282037446434827e-5L, + 0.146951181174930425744e-7L + }; + T t = z / 2 - 4; + result = Y + tools::evaluate_polynomial(P, t) + / tools::evaluate_polynomial(Q, t); + result *= exp(z) / z; + result += z; + } + else if(z <= 20) + { + // Maximum Deviation Found: 3.220e-20 + // Expected Error Term: 3.220e-20 + // Max Error found at long double precision = Poly: 7.696841e-20 Cheb: 6.205163e-20 + + + static const T Y = 1.0869731903076171875F; + static const T P[10] = { + -0.00893891094356946995368L, + -0.0487562980088748775943L, + -0.0670568657950041926085L, + -0.0509577352851442932713L, + -0.02551800927409034206L, + -0.00892913759760086687083L, + -0.00224469630207344379888L, + -0.000392477245911296982776L, + -0.44424044184395578775e-4L, + -0.252788029251437017959e-5L + }; + static const T Q[10] = { + 1L, + 2.00323265503572414261L, + 1.94688958187256383178L, + 1.19733638134417472296L, + 0.513137726038353385661L, + 0.159135395578007264547L, + 0.0358233587351620919881L, + 0.0056716655597009417875L, + 0.000577048986213535829925L, + 0.290976943033493216793e-4L + }; + T t = z / 5 - 3; + result = Y + tools::evaluate_polynomial(P, t) + / tools::evaluate_polynomial(Q, t); + result *= exp(z) / z; + result += z; + } + else if(z <= 40) + { + // Maximum Deviation Found: 2.940e-21 + // Expected Error Term: -2.938e-21 + // Max Error found at long double precision = Poly: 3.419893e-19 Cheb: 3.359874e-19 + + static const T Y = 1.03937530517578125F; + static const T P[12] = { + -0.00356165148914447278177L, + -0.0240235006148610849678L, + -0.0516699967278057976119L, + -0.0586603078706856245674L, + -0.0409960120868776180825L, + -0.0185485073689590665153L, + -0.00537842101034123222417L, + -0.000920988084778273760609L, + -0.716742618812210980263e-4L, + -0.504623302166487346677e-9L, + 0.712662196671896837736e-10L, + -0.533769629702262072175e-11L + }; + static const T Q[9] = { + 1L, + 3.13286733695729715455L, + 4.49281223045653491929L, + 3.84900294427622911374L, + 2.15205199043580378211L, + 0.802912186540269232424L, + 0.194793170017818925388L, + 0.0280128013584653182994L, + 0.00182034930799902922549L + }; + T t = z / 10 - 3; + result = Y + tools::evaluate_polynomial(P, t) + / tools::evaluate_polynomial(Q, t); + BOOST_MATH_INSTRUMENT_VARIABLE(result) + result *= exp(z) / z; + BOOST_MATH_INSTRUMENT_VARIABLE(result) + result += z; + BOOST_MATH_INSTRUMENT_VARIABLE(result) + } + else + { + // Maximum Deviation Found: 3.536e-20 + // Max Error found at long double precision = Poly: 1.310671e-19 Cheb: 8.630943e-11 + + static const T exp40 = static_cast<T>(2.35385266837019985407899910749034804508871617254555467236651e17L); + static const T Y= 1.013065338134765625F; + static const T P[9] = { + -0.0130653381347656250004L, + 0.644487780349757303739L, + 143.995670348227433964L, + -13918.9322758014173709L, + 476260.975133624194484L, + -7437102.15135982802122L, + 53732298.8764767916542L, + -160695051.957997452509L, + 137839271.592778020028L + }; + static const T Q[9] = { + 1L, + 27.2103343964943718802L, + -8785.48528692879413676L, + 397530.290000322626766L, + -7356441.34957799368252L, + 63050914.5343400957524L, + -246143779.638307701369L, + 384647824.678554961174L, + -166288297.874583961493L + }; + T t = 1 / z; + result = Y + tools::evaluate_polynomial(P, t) + / tools::evaluate_polynomial(Q, t); + if(z < 41) + result *= exp(z) / z; + else + { + // Avoid premature overflow if we can: + t = z - 40; + if(t > tools::log_max_value<T>()) + { + result = policies::raise_overflow_error<T>(function, 0, pol); + } + else + { + result *= exp(z - 40) / z; + if(result > tools::max_value<T>() / exp40) + { + result = policies::raise_overflow_error<T>(function, 0, pol); + } + else + { + result *= exp40; + } + } + } + result += z; + } + return result; +} + +template <class T, class Policy> +T expint_i_imp(T z, const Policy& pol, const mpl::int_<113>& tag) +{ + BOOST_MATH_STD_USING + static const char* function = "boost::math::expint<%1%>(%1%)"; + if(z < 0) + return -expint_imp(1, -z, pol, tag); + if(z == 0) + return -policies::raise_overflow_error<T>(function, 0, pol); + + T result; + + if(z <= 6) + { + // Maximum Deviation Found: 1.230e-36 + // Expected Error Term: -1.230e-36 + // Max Error found at long double precision = Poly: 4.355299e-34 Cheb: 7.512581e-34 + + + static const T P[15] = { + 2.98677224343598593765287235997328555L, + -0.333256034674702967028780537349334037L, + 0.851831522798101228384971644036708463L, + -0.0657854833494646206186773614110374948L, + 0.0630065662557284456000060708977935073L, + -0.00311759191425309373327784154659649232L, + 0.00176213568201493949664478471656026771L, + -0.491548660404172089488535218163952295e-4L, + 0.207764227621061706075562107748176592e-4L, + -0.225445398156913584846374273379402765e-6L, + 0.996939977231410319761273881672601592e-7L, + 0.212546902052178643330520878928100847e-9L, + 0.154646053060262871360159325115980023e-9L, + 0.143971277122049197323415503594302307e-11L, + 0.306243138978114692252817805327426657e-13L + }; + static const T Q[15] = { + 1L, + -1.40178870313943798705491944989231793L, + 0.943810968269701047641218856758605284L, + -0.405026631534345064600850391026113165L, + 0.123924153524614086482627660399122762L, + -0.0286364505373369439591132549624317707L, + 0.00516148845910606985396596845494015963L, + -0.000738330799456364820380739850924783649L, + 0.843737760991856114061953265870882637e-4L, + -0.767957673431982543213661388914587589e-5L, + 0.549136847313854595809952100614840031e-6L, + -0.299801381513743676764008325949325404e-7L, + 0.118419479055346106118129130945423483e-8L, + -0.30372295663095470359211949045344607e-10L, + 0.382742953753485333207877784720070523e-12L + }; + + static const T r1 = static_cast<T>(1677624236387711.0L / 4503599627370496.0L); + static const T r2 = static_cast<T>(266514582277687.0L / 4503599627370496.0L / 4503599627370496.0L); + static const T r3 = static_cast<T>(0.283806480836357377069325311780969887585024578164571984232357e-31L); + static const T r = static_cast<T>(0.372507410781366634461991866580119133535689497771654051555657435242200120636201854384926049951548942392L); + T t = (z / 3) - 1; + result = tools::evaluate_polynomial(P, t) + / tools::evaluate_polynomial(Q, t); + t = ((z - r1) - r2) - r3; + result *= t; + if(fabs(t) < 0.1) + { + result += boost::math::log1p(t / r); + } + else + { + result += log(z / r); + } + } + else if (z <= 10) + { + // Maximum Deviation Found: 7.779e-36 + // Expected Error Term: -7.779e-36 + // Max Error found at long double precision = Poly: 2.576723e-35 Cheb: 1.236001e-34 + + static const T Y = 1.158985137939453125F; + static const T P[15] = { + 0.00139324086199409049282472239613554817L, + -0.0338173111691991289178779840307998955L, + -0.0555972290794371306259684845277620556L, + -0.0378677976003456171563136909186202177L, + -0.0152221583517528358782902783914356667L, + -0.00428283334203873035104248217403126905L, + -0.000922782631491644846511553601323435286L, + -0.000155513428088853161562660696055496696L, + -0.205756580255359882813545261519317096e-4L, + -0.220327406578552089820753181821115181e-5L, + -0.189483157545587592043421445645377439e-6L, + -0.122426571518570587750898968123803867e-7L, + -0.635187358949437991465353268374523944e-9L, + -0.203015132965870311935118337194860863e-10L, + -0.384276705503357655108096065452950822e-12L + }; + static const T Q[15] = { + 1L, + 1.58784732785354597996617046880946257L, + 1.18550755302279446339364262338114098L, + 0.55598993549661368604527040349702836L, + 0.184290888380564236919107835030984453L, + 0.0459658051803613282360464632326866113L, + 0.0089505064268613225167835599456014705L, + 0.00139042673882987693424772855926289077L, + 0.000174210708041584097450805790176479012L, + 0.176324034009707558089086875136647376e-4L, + 0.142935845999505649273084545313710581e-5L, + 0.907502324487057260675816233312747784e-7L, + 0.431044337808893270797934621235918418e-8L, + 0.139007266881450521776529705677086902e-9L, + 0.234715286125516430792452741830364672e-11L + }; + T t = z / 2 - 4; + result = Y + tools::evaluate_polynomial(P, t) + / tools::evaluate_polynomial(Q, t); + result *= exp(z) / z; + result += z; + } + else if(z <= 18) + { + // Maximum Deviation Found: 1.082e-34 + // Expected Error Term: 1.080e-34 + // Max Error found at long double precision = Poly: 1.958294e-34 Cheb: 2.472261e-34 + + + static const T Y = 1.091579437255859375F; + static const T P[17] = { + -0.00685089599550151282724924894258520532L, + -0.0443313550253580053324487059748497467L, + -0.071538561252424027443296958795814874L, + -0.0622923153354102682285444067843300583L, + -0.0361631270264607478205393775461208794L, + -0.0153192826839624850298106509601033261L, + -0.00496967904961260031539602977748408242L, + -0.00126989079663425780800919171538920589L, + -0.000258933143097125199914724875206326698L, + -0.422110326689204794443002330541441956e-4L, + -0.546004547590412661451073996127115221e-5L, + -0.546775260262202177131068692199272241e-6L, + -0.404157632825805803833379568956559215e-7L, + -0.200612596196561323832327013027419284e-8L, + -0.502538501472133913417609379765434153e-10L, + -0.326283053716799774936661568391296584e-13L, + 0.869226483473172853557775877908693647e-15L + }; + static const T Q[15] = { + 1L, + 2.23227220874479061894038229141871087L, + 2.40221000361027971895657505660959863L, + 1.65476320985936174728238416007084214L, + 0.816828602963895720369875535001248227L, + 0.306337922909446903672123418670921066L, + 0.0902400121654409267774593230720600752L, + 0.0212708882169429206498765100993228086L, + 0.00404442626252467471957713495828165491L, + 0.0006195601618842253612635241404054589L, + 0.755930932686543009521454653994321843e-4L, + 0.716004532773778954193609582677482803e-5L, + 0.500881663076471627699290821742924233e-6L, + 0.233593219218823384508105943657387644e-7L, + 0.554900353169148897444104962034267682e-9L + }; + T t = z / 4 - 3.5; + result = Y + tools::evaluate_polynomial(P, t) + / tools::evaluate_polynomial(Q, t); + result *= exp(z) / z; + result += z; + } + else if(z <= 26) + { + // Maximum Deviation Found: 3.163e-35 + // Expected Error Term: 3.163e-35 + // Max Error found at long double precision = Poly: 4.158110e-35 Cheb: 5.385532e-35 + + static const T Y = 1.051731109619140625F; + static const T P[14] = { + -0.00144552494420652573815404828020593565L, + -0.0126747451594545338365684731262912741L, + -0.01757394877502366717526779263438073L, + -0.0126838952395506921945756139424722588L, + -0.0060045057928894974954756789352443522L, + -0.00205349237147226126653803455793107903L, + -0.000532606040579654887676082220195624207L, + -0.000107344687098019891474772069139014662L, + -0.169536802705805811859089949943435152e-4L, + -0.20863311729206543881826553010120078e-5L, + -0.195670358542116256713560296776654385e-6L, + -0.133291168587253145439184028259772437e-7L, + -0.595500337089495614285777067722823397e-9L, + -0.133141358866324100955927979606981328e-10L + }; + static const T Q[14] = { + 1L, + 1.72490783907582654629537013560044682L, + 1.44524329516800613088375685659759765L, + 0.778241785539308257585068744978050181L, + 0.300520486589206605184097270225725584L, + 0.0879346899691339661394537806057953957L, + 0.0200802415843802892793583043470125006L, + 0.00362842049172586254520256100538273214L, + 0.000519731362862955132062751246769469957L, + 0.584092147914050999895178697392282665e-4L, + 0.501851497707855358002773398333542337e-5L, + 0.313085677467921096644895738538865537e-6L, + 0.127552010539733113371132321521204458e-7L, + 0.25737310826983451144405899970774587e-9L + }; + T t = z / 4 - 5.5; + result = Y + tools::evaluate_polynomial(P, t) + / tools::evaluate_polynomial(Q, t); + BOOST_MATH_INSTRUMENT_VARIABLE(result) + result *= exp(z) / z; + BOOST_MATH_INSTRUMENT_VARIABLE(result) + result += z; + BOOST_MATH_INSTRUMENT_VARIABLE(result) + } + else if(z <= 42) + { + // Maximum Deviation Found: 7.972e-36 + // Expected Error Term: 7.962e-36 + // Max Error found at long double precision = Poly: 1.711721e-34 Cheb: 3.100018e-34 + + static const T Y = 1.032726287841796875F; + static const T P[15] = { + -0.00141056919297307534690895009969373233L, + -0.0123384175302540291339020257071411437L, + -0.0298127270706864057791526083667396115L, + -0.0390686759471630584626293670260768098L, + -0.0338226792912607409822059922949035589L, + -0.0211659736179834946452561197559654582L, + -0.0100428887460879377373158821400070313L, + -0.00370717396015165148484022792801682932L, + -0.0010768667551001624764329000496561659L, + -0.000246127328761027039347584096573123531L, + -0.437318110527818613580613051861991198e-4L, + -0.587532682329299591501065482317771497e-5L, + -0.565697065670893984610852937110819467e-6L, + -0.350233957364028523971768887437839573e-7L, + -0.105428907085424234504608142258423505e-8L + }; + static const T Q[16] = { + 1L, + 3.17261315255467581204685605414005525L, + 4.85267952971640525245338392887217426L, + 4.74341914912439861451492872946725151L, + 3.31108463283559911602405970817931801L, + 1.74657006336994649386607925179848899L, + 0.718255607416072737965933040353653244L, + 0.234037553177354542791975767960643864L, + 0.0607470145906491602476833515412605389L, + 0.0125048143774226921434854172947548724L, + 0.00201034366420433762935768458656609163L, + 0.000244823338417452367656368849303165721L, + 0.213511655166983177960471085462540807e-4L, + 0.119323998465870686327170541547982932e-5L, + 0.322153582559488797803027773591727565e-7L, + -0.161635525318683508633792845159942312e-16L + }; + T t = z / 8 - 4.25; + result = Y + tools::evaluate_polynomial(P, t) + / tools::evaluate_polynomial(Q, t); + BOOST_MATH_INSTRUMENT_VARIABLE(result) + result *= exp(z) / z; + BOOST_MATH_INSTRUMENT_VARIABLE(result) + result += z; + BOOST_MATH_INSTRUMENT_VARIABLE(result) + } + else if(z <= 56) + { + // Maximum Deviation Found: 4.469e-36 + // Expected Error Term: 4.468e-36 + // Max Error found at long double precision = Poly: 1.288958e-35 Cheb: 2.304586e-35 + + static const T Y = 1.0216197967529296875F; + static const T P[12] = { + -0.000322999116096627043476023926572650045L, + -0.00385606067447365187909164609294113346L, + -0.00686514524727568176735949971985244415L, + -0.00606260649593050194602676772589601799L, + -0.00334382362017147544335054575436194357L, + -0.00126108534260253075708625583630318043L, + -0.000337881489347846058951220431209276776L, + -0.648480902304640018785370650254018022e-4L, + -0.87652644082970492211455290209092766e-5L, + -0.794712243338068631557849449519994144e-6L, + -0.434084023639508143975983454830954835e-7L, + -0.107839681938752337160494412638656696e-8L + }; + static const T Q[12] = { + 1L, + 2.09913805456661084097134805151524958L, + 2.07041755535439919593503171320431849L, + 1.26406517226052371320416108604874734L, + 0.529689923703770353961553223973435569L, + 0.159578150879536711042269658656115746L, + 0.0351720877642000691155202082629857131L, + 0.00565313621289648752407123620997063122L, + 0.000646920278540515480093843570291218295L, + 0.499904084850091676776993523323213591e-4L, + 0.233740058688179614344680531486267142e-5L, + 0.498800627828842754845418576305379469e-7L + }; + T t = z / 7 - 7; + result = Y + tools::evaluate_polynomial(P, t) + / tools::evaluate_polynomial(Q, t); + BOOST_MATH_INSTRUMENT_VARIABLE(result) + result *= exp(z) / z; + BOOST_MATH_INSTRUMENT_VARIABLE(result) + result += z; + BOOST_MATH_INSTRUMENT_VARIABLE(result) + } + else if(z <= 84) + { + // Maximum Deviation Found: 5.588e-35 + // Expected Error Term: -5.566e-35 + // Max Error found at long double precision = Poly: 9.976345e-35 Cheb: 8.358865e-35 + + static const T Y = 1.015148162841796875F; + static const T P[11] = { + -0.000435714784725086961464589957142615216L, + -0.00432114324353830636009453048419094314L, + -0.0100740363285526177522819204820582424L, + -0.0116744115827059174392383504427640362L, + -0.00816145387784261141360062395898644652L, + -0.00371380272673500791322744465394211508L, + -0.00112958263488611536502153195005736563L, + -0.000228316462389404645183269923754256664L, + -0.29462181955852860250359064291292577e-4L, + -0.21972450610957417963227028788460299e-5L, + -0.720558173805289167524715527536874694e-7L + }; + static const T Q[11] = { + 1L, + 2.95918362458402597039366979529287095L, + 3.96472247520659077944638411856748924L, + 3.15563251550528513747923714884142131L, + 1.64674612007093983894215359287448334L, + 0.58695020129846594405856226787156424L, + 0.144358385319329396231755457772362793L, + 0.024146911506411684815134916238348063L, + 0.0026257132337460784266874572001650153L, + 0.000167479843750859222348869769094711093L, + 0.475673638665358075556452220192497036e-5L + }; + T t = z / 14 - 5; + result = Y + tools::evaluate_polynomial(P, t) + / tools::evaluate_polynomial(Q, t); + BOOST_MATH_INSTRUMENT_VARIABLE(result) + result *= exp(z) / z; + BOOST_MATH_INSTRUMENT_VARIABLE(result) + result += z; + BOOST_MATH_INSTRUMENT_VARIABLE(result) + } + else if(z <= 210) + { + // Maximum Deviation Found: 4.448e-36 + // Expected Error Term: 4.445e-36 + // Max Error found at long double precision = Poly: 2.058532e-35 Cheb: 2.165465e-27 + + static const T Y= 1.00849151611328125F; + static const T P[9] = { + -0.0084915161132812500000001440233607358L, + 1.84479378737716028341394223076147872L, + -130.431146923726715674081563022115568L, + 4336.26945491571504885214176203512015L, + -76279.0031974974730095170437591004177L, + 729577.956271997673695191455111727774L, + -3661928.69330208734947103004900349266L, + 8570600.041606912735872059184527855L, + -6758379.93672362080947905580906028645L + }; + static const T Q[10] = { + 1L, + -99.4868026047611434569541483506091713L, + 3879.67753690517114249705089803055473L, + -76495.82413252517165830203774900806L, + 820773.726408311894342553758526282667L, + -4803087.64956923577571031564909646579L, + 14521246.227703545012713173740895477L, + -19762752.0196769712258527849159393044L, + 8354144.67882768405803322344185185517L, + 355076.853106511136734454134915432571L + }; + T t = 1 / z; + result = Y + tools::evaluate_polynomial(P, t) + / tools::evaluate_polynomial(Q, t); + result *= exp(z) / z; + result += z; + } + else // z > 210 + { + // Maximum Deviation Found: 3.963e-37 + // Expected Error Term: 3.963e-37 + // Max Error found at long double precision = Poly: 1.248049e-36 Cheb: 2.843486e-29 + + static const T exp40 = static_cast<T>(2.35385266837019985407899910749034804508871617254555467236651e17L); + static const T Y= 1.00252532958984375F; + static const T P[8] = { + -0.00252532958984375000000000000000000085L, + 1.16591386866059087390621952073890359L, + -67.8483431314018462417456828499277579L, + 1567.68688154683822956359536287575892L, + -17335.4683325819116482498725687644986L, + 93632.6567462673524739954389166550069L, + -225025.189335919133214440347510936787L, + 175864.614717440010942804684741336853L + }; + static const T Q[9] = { + 1L, + -65.6998869881600212224652719706425129L, + 1642.73850032324014781607859416890077L, + -19937.2610222467322481947237312818575L, + 124136.267326632742667972126625064538L, + -384614.251466704550678760562965502293L, + 523355.035910385688578278384032026998L, + -217809.552260834025885677791936351294L, + -8555.81719551123640677261226549550872L + }; + T t = 1 / z; + result = Y + tools::evaluate_polynomial(P, t) + / tools::evaluate_polynomial(Q, t); + if(z < 41) + result *= exp(z) / z; + else + { + // Avoid premature overflow if we can: + t = z - 40; + if(t > tools::log_max_value<T>()) + { + result = policies::raise_overflow_error<T>(function, 0, pol); + } + else + { + result *= exp(z - 40) / z; + if(result > tools::max_value<T>() / exp40) + { + result = policies::raise_overflow_error<T>(function, 0, pol); + } + else + { + result *= exp40; + } + } + } + result += z; + } + return result; +} + +template <class T, class Policy> +inline typename tools::promote_args<T>::type + expint_forwarder(T z, const Policy& /*pol*/, mpl::true_ const&) +{ + typedef typename tools::promote_args<T>::type result_type; + typedef typename policies::evaluation<result_type, Policy>::type value_type; + typedef typename policies::precision<result_type, Policy>::type precision_type; + typedef typename policies::normalise< + Policy, + policies::promote_float<false>, + policies::promote_double<false>, + policies::discrete_quantile<>, + policies::assert_undefined<> >::type forwarding_policy; + typedef typename mpl::if_< + mpl::less_equal<precision_type, mpl::int_<0> >, + mpl::int_<0>, + typename mpl::if_< + mpl::less_equal<precision_type, mpl::int_<53> >, + mpl::int_<53>, // double + typename mpl::if_< + mpl::less_equal<precision_type, mpl::int_<64> >, + mpl::int_<64>, // 80-bit long double + typename mpl::if_< + mpl::less_equal<precision_type, mpl::int_<113> >, + mpl::int_<113>, // 128-bit long double + mpl::int_<0> // too many bits, use generic version. + >::type + >::type + >::type + >::type tag_type; + + return policies::checked_narrowing_cast<result_type, forwarding_policy>(detail::expint_i_imp( + static_cast<value_type>(z), + forwarding_policy(), + tag_type()), "boost::math::expint<%1%>(%1%)"); +} + +template <class T> +inline typename tools::promote_args<T>::type +expint_forwarder(unsigned n, T z, const mpl::false_&) +{ + return boost::math::expint(n, z, policies::policy<>()); +} + +} // namespace detail + +template <class T, class Policy> +inline typename tools::promote_args<T>::type + expint(unsigned n, T z, const Policy& /*pol*/) +{ + typedef typename tools::promote_args<T>::type result_type; + typedef typename policies::evaluation<result_type, Policy>::type value_type; + typedef typename policies::precision<result_type, Policy>::type precision_type; + typedef typename policies::normalise< + Policy, + policies::promote_float<false>, + policies::promote_double<false>, + policies::discrete_quantile<>, + policies::assert_undefined<> >::type forwarding_policy; + typedef typename mpl::if_< + mpl::less_equal<precision_type, mpl::int_<0> >, + mpl::int_<0>, + typename mpl::if_< + mpl::less_equal<precision_type, mpl::int_<53> >, + mpl::int_<53>, // double + typename mpl::if_< + mpl::less_equal<precision_type, mpl::int_<64> >, + mpl::int_<64>, // 80-bit long double + typename mpl::if_< + mpl::less_equal<precision_type, mpl::int_<113> >, + mpl::int_<113>, // 128-bit long double + mpl::int_<0> // too many bits, use generic version. + >::type + >::type + >::type + >::type tag_type; + + return policies::checked_narrowing_cast<result_type, forwarding_policy>(detail::expint_imp( + n, + static_cast<value_type>(z), + forwarding_policy(), + tag_type()), "boost::math::expint<%1%>(unsigned, %1%)"); +} + +template <class T, class U> +inline typename detail::expint_result<T, U>::type + expint(T const z, U const u) +{ + typedef typename policies::is_policy<U>::type tag_type; + return detail::expint_forwarder(z, u, tag_type()); +} + +template <class T> +inline typename tools::promote_args<T>::type + expint(T z) +{ + return expint(z, policies::policy<>()); +} + +}} // namespaces + +#endif // BOOST_MATH_EXPINT_HPP + + diff --git a/Utilities/BGL/boost/math/special_functions/expm1.hpp b/Utilities/BGL/boost/math/special_functions/expm1.hpp new file mode 100644 index 0000000000000000000000000000000000000000..faaf59b6d120a4af97bacb536a1f5ce65b656431 --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/expm1.hpp @@ -0,0 +1,309 @@ +// (C) Copyright John Maddock 2006. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_EXPM1_INCLUDED +#define BOOST_MATH_EXPM1_INCLUDED + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/config/no_tr1/cmath.hpp> +#include <math.h> // platform's ::expm1 +#include <boost/limits.hpp> +#include <boost/math/tools/config.hpp> +#include <boost/math/tools/series.hpp> +#include <boost/math/tools/precision.hpp> +#include <boost/math/policies/error_handling.hpp> +#include <boost/math/tools/rational.hpp> +#include <boost/math/special_functions/math_fwd.hpp> +#include <boost/mpl/less_equal.hpp> + +#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS +# include <boost/static_assert.hpp> +#else +# include <boost/assert.hpp> +#endif + +namespace boost{ namespace math{ + +namespace detail +{ + // Functor expm1_series returns the next term in the Taylor series + // x^k / k! + // each time that operator() is invoked. + // + template <class T> + struct expm1_series + { + typedef T result_type; + + expm1_series(T x) + : k(0), m_x(x), m_term(1) {} + + T operator()() + { + ++k; + m_term *= m_x; + m_term /= k; + return m_term; + } + + int count()const + { + return k; + } + + private: + int k; + const T m_x; + T m_term; + expm1_series(const expm1_series&); + expm1_series& operator=(const expm1_series&); + }; + +// +// Algorithm expm1 is part of C99, but is not yet provided by many compilers. +// +// This version uses a Taylor series expansion for 0.5 > |x| > epsilon. +// +template <class T, class Policy> +T expm1_imp(T x, const mpl::int_<0>&, const Policy& pol) +{ + BOOST_MATH_STD_USING + + T a = fabs(x); + if(a > T(0.5f)) + { + if(a >= tools::log_max_value<T>()) + { + if(x > 0) + return policies::raise_overflow_error<T>("boost::math::expm1<%1%>(%1%)", 0, pol); + return -1; + } + return exp(x) - T(1); + } + if(a < tools::epsilon<T>()) + return x; + detail::expm1_series<T> s(x); + boost::uintmax_t max_iter = policies::get_max_series_iterations<Policy>(); +#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582)) && !BOOST_WORKAROUND(__EDG_VERSION__, <= 245) + T result = tools::sum_series(s, policies::get_epsilon<T, Policy>(), max_iter); +#else + T zero = 0; + T result = tools::sum_series(s, policies::get_epsilon<T, Policy>(), max_iter, zero); +#endif + policies::check_series_iterations("boost::math::expm1<%1%>(%1%)", max_iter, pol); + return result; +} + +template <class T, class P> +T expm1_imp(T x, const mpl::int_<53>&, const P& pol) +{ + BOOST_MATH_STD_USING + + T a = fabs(x); + if(a > T(0.5L)) + { + if(a >= tools::log_max_value<T>()) + { + if(x > 0) + return policies::raise_overflow_error<T>("boost::math::expm1<%1%>(%1%)", 0, pol); + return -1; + } + return exp(x) - T(1); + } + if(a < tools::epsilon<T>()) + return x; + + static const float Y = 0.10281276702880859e1f; + static const T n[] = { -0.28127670288085937e-1, 0.51278186299064534e0, -0.6310029069350198e-1, 0.11638457975729296e-1, -0.52143390687521003e-3, 0.21491399776965688e-4 }; + static const T d[] = { 1, -0.45442309511354755e0, 0.90850389570911714e-1, -0.10088963629815502e-1, 0.63003407478692265e-3, -0.17976570003654402e-4 }; + + T result = x * Y + x * tools::evaluate_polynomial(n, x) / tools::evaluate_polynomial(d, x); + return result; +} + +template <class T, class P> +T expm1_imp(T x, const mpl::int_<64>&, const P& pol) +{ + BOOST_MATH_STD_USING + + T a = fabs(x); + if(a > T(0.5L)) + { + if(a >= tools::log_max_value<T>()) + { + if(x > 0) + return policies::raise_overflow_error<T>("boost::math::expm1<%1%>(%1%)", 0, pol); + return -1; + } + return exp(x) - T(1); + } + if(a < tools::epsilon<T>()) + return x; + + static const float Y = 0.10281276702880859375e1f; + static const T n[] = { + -0.281276702880859375e-1L, + 0.512980290285154286358e0L, + -0.667758794592881019644e-1L, + 0.131432469658444745835e-1L, + -0.72303795326880286965e-3L, + 0.447441185192951335042e-4L, + -0.714539134024984593011e-6L + }; + static const T d[] = { + 1, + -0.461477618025562520389e0L, + 0.961237488025708540713e-1L, + -0.116483957658204450739e-1L, + 0.873308008461557544458e-3L, + -0.387922804997682392562e-4L, + 0.807473180049193557294e-6L + }; + + T result = x * Y + x * tools::evaluate_polynomial(n, x) / tools::evaluate_polynomial(d, x); + return result; +} + +template <class T, class P> +T expm1_imp(T x, const mpl::int_<113>&, const P& pol) +{ + BOOST_MATH_STD_USING + + T a = fabs(x); + if(a > T(0.5L)) + { + if(a >= tools::log_max_value<T>()) + { + if(x > 0) + return policies::raise_overflow_error<T>("boost::math::expm1<%1%>(%1%)", 0, pol); + return -1; + } + return exp(x) - T(1); + } + if(a < tools::epsilon<T>()) + return x; + + static const float Y = 0.10281276702880859375e1f; + static const T n[] = { + -0.28127670288085937499999999999999999854e-1L, + 0.51278156911210477556524452177540792214e0L, + -0.63263178520747096729500254678819588223e-1L, + 0.14703285606874250425508446801230572252e-1L, + -0.8675686051689527802425310407898459386e-3L, + 0.88126359618291165384647080266133492399e-4L, + -0.25963087867706310844432390015463138953e-5L, + 0.14226691087800461778631773363204081194e-6L, + -0.15995603306536496772374181066765665596e-8L, + 0.45261820069007790520447958280473183582e-10L + }; + static const T d[] = { + 1, + -0.45441264709074310514348137469214538853e0L, + 0.96827131936192217313133611655555298106e-1L, + -0.12745248725908178612540554584374876219e-1L, + 0.11473613871583259821612766907781095472e-2L, + -0.73704168477258911962046591907690764416e-4L, + 0.34087499397791555759285503797256103259e-5L, + -0.11114024704296196166272091230695179724e-6L, + 0.23987051614110848595909588343223896577e-8L, + -0.29477341859111589208776402638429026517e-10L, + 0.13222065991022301420255904060628100924e-12L + }; + + T result = x * Y + x * tools::evaluate_polynomial(n, x) / tools::evaluate_polynomial(d, x); + return result; +} + +} // namespace detail + +template <class T, class Policy> +inline typename tools::promote_args<T>::type expm1(T x, const Policy& /* pol */) +{ + typedef typename tools::promote_args<T>::type result_type; + typedef typename policies::evaluation<result_type, Policy>::type value_type; + typedef typename policies::precision<result_type, Policy>::type precision_type; + typedef typename policies::normalise< + Policy, + policies::promote_float<false>, + policies::promote_double<false>, + policies::discrete_quantile<>, + policies::assert_undefined<> >::type forwarding_policy; + + typedef typename mpl::if_c< + ::std::numeric_limits<result_type>::is_specialized == 0, + mpl::int_<0>, // no numeric_limits, use generic solution + typename mpl::if_< + typename mpl::less_equal<precision_type, mpl::int_<53> >::type, + mpl::int_<53>, // double + typename mpl::if_< + typename mpl::less_equal<precision_type, mpl::int_<64> >::type, + mpl::int_<64>, // 80-bit long double + typename mpl::if_< + typename mpl::less_equal<precision_type, mpl::int_<113> >::type, + mpl::int_<113>, // 128-bit long double + mpl::int_<0> // too many bits, use generic version. + >::type + >::type + >::type + >::type tag_type; + + return policies::checked_narrowing_cast<result_type, forwarding_policy>(detail::expm1_imp( + static_cast<value_type>(x), + tag_type(), forwarding_policy()), "boost::math::expm1<%1%>(%1%)"); +} + +#ifdef expm1 +# ifndef BOOST_HAS_expm1 +# define BOOST_HAS_expm1 +# endif +# undef expm1 +#endif + +#if defined(BOOST_HAS_EXPM1) && !(defined(__osf__) && defined(__DECCXX_VER)) +# ifdef BOOST_MATH_USE_C99 +inline float expm1(float x, const policies::policy<>&){ return ::expm1f(x); } +# ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS +inline long double expm1(long double x, const policies::policy<>&){ return ::expm1l(x); } +# endif +# else +inline float expm1(float x, const policies::policy<>&){ return ::expm1(x); } +# endif +inline double expm1(double x, const policies::policy<>&){ return ::expm1(x); } +#endif + +template <class T> +inline typename tools::promote_args<T>::type expm1(T x) +{ + return expm1(x, policies::policy<>()); +} + +#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) +inline float expm1(float z) +{ + return expm1<float>(z); +} +inline double expm1(double z) +{ + return expm1<double>(z); +} +#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS +inline long double expm1(long double z) +{ + return expm1<long double>(z); +} +#endif +#endif + +} // namespace math +} // namespace boost + +#endif // BOOST_MATH_HYPOT_INCLUDED + + + + diff --git a/Utilities/BGL/boost/math/special_functions/factorials.hpp b/Utilities/BGL/boost/math/special_functions/factorials.hpp new file mode 100644 index 0000000000000000000000000000000000000000..c81493d75efc5a95d8d9374a11d983388b693531 --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/factorials.hpp @@ -0,0 +1,233 @@ +// Copyright John Maddock 2006. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_SP_FACTORIALS_HPP +#define BOOST_MATH_SP_FACTORIALS_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/math/special_functions/gamma.hpp> +#include <boost/math/special_functions/math_fwd.hpp> +#include <boost/math/special_functions/detail/unchecked_factorial.hpp> +#include <boost/array.hpp> +#ifdef BOOST_MSVC +#pragma warning(push) // Temporary until lexical cast fixed. +#pragma warning(disable: 4127 4701) +#endif +#include <boost/lexical_cast.hpp> +#ifdef BOOST_MSVC +#pragma warning(pop) +#endif +#include <boost/config/no_tr1/cmath.hpp> + +namespace boost { namespace math +{ + +template <class T, class Policy> +inline T factorial(unsigned i, const Policy& pol) +{ + BOOST_STATIC_ASSERT(!boost::is_integral<T>::value); + BOOST_MATH_STD_USING // Aid ADL for floor. + + if(i <= max_factorial<T>::value) + return unchecked_factorial<T>(i); + T result = boost::math::tgamma(static_cast<T>(i+1), pol); + if(result > tools::max_value<T>()) + return result; // Overflowed value! (But tgamma will have signalled the error already). + return floor(result + 0.5f); +} + +template <class T> +inline T factorial(unsigned i) +{ + return factorial<T>(i, policies::policy<>()); +} +/* +// Can't have these in a policy enabled world? +template<> +inline float factorial<float>(unsigned i) +{ + if(i <= max_factorial<float>::value) + return unchecked_factorial<float>(i); + return tools::overflow_error<float>(BOOST_CURRENT_FUNCTION); +} + +template<> +inline double factorial<double>(unsigned i) +{ + if(i <= max_factorial<double>::value) + return unchecked_factorial<double>(i); + return tools::overflow_error<double>(BOOST_CURRENT_FUNCTION); +} +*/ +template <class T, class Policy> +T double_factorial(unsigned i, const Policy& pol) +{ + BOOST_STATIC_ASSERT(!boost::is_integral<T>::value); + BOOST_MATH_STD_USING // ADL lookup of std names + if(i & 1) + { + // odd i: + if(i < max_factorial<T>::value) + { + unsigned n = (i - 1) / 2; + return ceil(unchecked_factorial<T>(i) / (ldexp(T(1), (int)n) * unchecked_factorial<T>(n)) - 0.5f); + } + // + // Fallthrough: i is too large to use table lookup, try the + // gamma function instead. + // + T result = boost::math::tgamma(static_cast<T>(i) / 2 + 1, pol) / sqrt(constants::pi<T>()); + if(ldexp(tools::max_value<T>(), -static_cast<int>(i+1) / 2) > result) + return ceil(result * ldexp(T(1), (i+1) / 2) - 0.5f); + } + else + { + // even i: + unsigned n = i / 2; + T result = factorial<T>(n, pol); + if(ldexp(tools::max_value<T>(), -(int)n) > result) + return result * ldexp(T(1), (int)n); + } + // + // If we fall through to here then the result is infinite: + // + return policies::raise_overflow_error<T>("boost::math::double_factorial<%1%>(unsigned)", 0, pol); +} + +template <class T> +inline T double_factorial(unsigned i) +{ + return double_factorial<T>(i, policies::policy<>()); +} + +namespace detail{ + +template <class T, class Policy> +T rising_factorial_imp(T x, int n, const Policy& pol) +{ + BOOST_STATIC_ASSERT(!boost::is_integral<T>::value); + if(x < 0) + { + // + // For x less than zero, we really have a falling + // factorial, modulo a possible change of sign. + // + // Note that the falling factorial isn't defined + // for negative n, so we'll get rid of that case + // first: + // + bool inv = false; + if(n < 0) + { + x += n; + n = -n; + inv = true; + } + T result = ((n&1) ? -1 : 1) * falling_factorial(-x, n, pol); + if(inv) + result = 1 / result; + return result; + } + if(n == 0) + return 1; + // + // We don't optimise this for small n, because + // tgamma_delta_ratio is alreay optimised for that + // use case: + // + return 1 / boost::math::tgamma_delta_ratio(x, static_cast<T>(n), pol); +} + +template <class T, class Policy> +inline T falling_factorial_imp(T x, unsigned n, const Policy& pol) +{ + BOOST_STATIC_ASSERT(!boost::is_integral<T>::value); + BOOST_MATH_STD_USING // ADL of std names + if(x == 0) + return 0; + if(x < 0) + { + // + // For x < 0 we really have a rising factorial + // modulo a possible change of sign: + // + return (n&1 ? -1 : 1) * rising_factorial(-x, n, pol); + } + if(n == 0) + return 1; + if(x < n-1) + { + // + // x+1-n will be negative and tgamma_delta_ratio won't + // handle it, split the product up into three parts: + // + T xp1 = x + 1; + unsigned n2 = itrunc((T)floor(xp1), pol); + if(n2 == xp1) + return 0; + T result = boost::math::tgamma_delta_ratio(xp1, -static_cast<T>(n2), pol); + x -= n2; + result *= x; + ++n2; + if(n2 < n) + result *= falling_factorial(x - 1, n - n2, pol); + return result; + } + // + // Simple case: just the ratio of two + // (positive argument) gamma functions. + // Note that we don't optimise this for small n, + // because tgamma_delta_ratio is alreay optimised + // for that use case: + // + return boost::math::tgamma_delta_ratio(x + 1, -static_cast<T>(n), pol); +} + +} // namespace detail + +template <class RT> +inline typename tools::promote_args<RT>::type + falling_factorial(RT x, unsigned n) +{ + typedef typename tools::promote_args<RT>::type result_type; + return detail::falling_factorial_imp( + static_cast<result_type>(x), n, policies::policy<>()); +} + +template <class RT, class Policy> +inline typename tools::promote_args<RT>::type + falling_factorial(RT x, unsigned n, const Policy& pol) +{ + typedef typename tools::promote_args<RT>::type result_type; + return detail::falling_factorial_imp( + static_cast<result_type>(x), n, pol); +} + +template <class RT> +inline typename tools::promote_args<RT>::type + rising_factorial(RT x, int n) +{ + typedef typename tools::promote_args<RT>::type result_type; + return detail::rising_factorial_imp( + static_cast<result_type>(x), n, policies::policy<>()); +} + +template <class RT, class Policy> +inline typename tools::promote_args<RT>::type + rising_factorial(RT x, int n, const Policy& pol) +{ + typedef typename tools::promote_args<RT>::type result_type; + return detail::rising_factorial_imp( + static_cast<result_type>(x), n, pol); +} + +} // namespace math +} // namespace boost + +#endif // BOOST_MATH_SP_FACTORIALS_HPP + diff --git a/Utilities/BGL/boost/math/special_functions/fpclassify.hpp b/Utilities/BGL/boost/math/special_functions/fpclassify.hpp new file mode 100644 index 0000000000000000000000000000000000000000..ae8c086c77912f989e6c499faa2f1ec2a633475b --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/fpclassify.hpp @@ -0,0 +1,533 @@ +// Copyright John Maddock 2005-2008. +// Copyright (c) 2006-2008 Johan Rade +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_FPCLASSIFY_HPP +#define BOOST_MATH_FPCLASSIFY_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <math.h> +#include <boost/config/no_tr1/cmath.hpp> +#include <boost/limits.hpp> +#include <boost/math/tools/real_cast.hpp> +#include <boost/type_traits/is_floating_point.hpp> +#include <boost/math/special_functions/math_fwd.hpp> +#include <boost/math/special_functions/detail/fp_traits.hpp> +/*! + \file fpclassify.hpp + \brief Classify floating-point value as normal, subnormal, zero, infinite, or NaN. + \version 1.0 + \author John Maddock + */ + +/* + +1. If the platform is C99 compliant, then the native floating point +classification functions are used. However, note that we must only +define the functions which call std::fpclassify etc if that function +really does exist: otherwise a compiler may reject the code even though +the template is never instantiated. + +2. If the platform is not C99 compliant, and the binary format for +a floating point type (float, double or long double) can be determined +at compile time, then the following algorithm is used: + + If all exponent bits, the flag bit (if there is one), + and all significand bits are 0, then the number is zero. + + If all exponent bits and the flag bit (if there is one) are 0, + and at least one significand bit is 1, then the number is subnormal. + + If all exponent bits are 1 and all significand bits are 0, + then the number is infinity. + + If all exponent bits are 1 and at least one significand bit is 1, + then the number is a not-a-number. + + Otherwise the number is normal. + + This algorithm works for the IEEE 754 representation, + and also for several non IEEE 754 formats. + + Most formats have the structure + sign bit + exponent bits + significand bits. + + A few have the structure + sign bit + exponent bits + flag bit + significand bits. + The flag bit is 0 for zero and subnormal numbers, + and 1 for normal numbers and NaN. + It is 0 (Motorola 68K) or 1 (Intel) for infinity. + + To get the bits, the four or eight most significant bytes are copied + into an uint32_t or uint64_t and bit masks are applied. + This covers all the exponent bits and the flag bit (if there is one), + but not always all the significand bits. + Some of the functions below have two implementations, + depending on whether all the significand bits are copied or not. + +3. If the platform is not C99 compliant, and the binary format for +a floating point type (float, double or long double) can not be determined +at compile time, then comparison with std::numeric_limits values +is used. + +*/ + +#if defined(_MSC_VER) || defined(__BORLANDC__) +#include <float.h> +#endif + +#ifdef BOOST_NO_STDC_NAMESPACE + namespace std{ using ::abs; using ::fabs; } +#endif + +namespace boost{ + +#if defined(BOOST_HAS_FPCLASSIFY) || defined(isnan) +// +// This must not be located in any namespace under boost::math +// otherwise we can get into an infinite loop if isnan is +// a #define for "isnan" ! +// +namespace math_detail{ + +template <class T> +inline bool is_nan_helper(T t, const boost::true_type&) +{ +#ifdef isnan + return isnan(t); +#else // BOOST_HAS_FPCLASSIFY + return (BOOST_FPCLASSIFY_PREFIX fpclassify(t) == (int)FP_NAN); +#endif +} + +template <class T> +inline bool is_nan_helper(T t, const boost::false_type&) +{ + return false; +} + +} + +#endif // defined(BOOST_HAS_FPCLASSIFY) || defined(isnan) + +namespace math{ + +namespace detail{ + +#ifdef BOOST_MATH_USE_STD_FPCLASSIFY +template <class T> +inline int fpclassify_imp BOOST_NO_MACRO_EXPAND(T t, const native_tag&) +{ + return (std::fpclassify)(t); +} +#endif + +template <class T> +inline int fpclassify_imp BOOST_NO_MACRO_EXPAND(T t, const generic_tag<true>&) +{ + BOOST_MATH_INSTRUMENT_VARIABLE(t); + + // whenever possible check for Nan's first: +#ifdef BOOST_HAS_FPCLASSIFY + if(::boost::math_detail::is_nan_helper(t, ::boost::is_floating_point<T>())) + return FP_NAN; +#elif defined(isnan) + if(boost::math_detail::is_nan_helper(t, ::boost::is_floating_point<T>())) + return FP_NAN; +#elif defined(_MSC_VER) || defined(__BORLANDC__) + if(::_isnan(boost::math::tools::real_cast<double>(t))) + return FP_NAN; +#endif + // std::fabs broken on a few systems especially for long long!!!! + T at = (t < T(0)) ? -t : t; + + // Use a process of exclusion to figure out + // what kind of type we have, this relies on + // IEEE conforming reals that will treat + // Nan's as unordered. Some compilers + // don't do this once optimisations are + // turned on, hence the check for nan's above. + if(at <= (std::numeric_limits<T>::max)()) + { + if(at >= (std::numeric_limits<T>::min)()) + return FP_NORMAL; + return (at != 0) ? FP_SUBNORMAL : FP_ZERO; + } + else if(at > (std::numeric_limits<T>::max)()) + return FP_INFINITE; + return FP_NAN; +} + +template <class T> +inline int fpclassify_imp BOOST_NO_MACRO_EXPAND(T t, const generic_tag<false>&) +{ +#ifdef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS + if(std::numeric_limits<T>::is_specialized) + return fp_classify_imp(t, mpl::true_()); +#endif + // + // An unknown type with no numeric_limits support, + // so what are we supposed to do we do here? + // + BOOST_MATH_INSTRUMENT_VARIABLE(t); + + return t == 0 ? FP_ZERO : FP_NORMAL; +} + +template<class T> +int fpclassify_imp BOOST_NO_MACRO_EXPAND(T x, ieee_copy_all_bits_tag) +{ + typedef BOOST_DEDUCED_TYPENAME fp_traits<T>::type traits; + + BOOST_MATH_INSTRUMENT_VARIABLE(x); + + BOOST_DEDUCED_TYPENAME traits::bits a; + traits::get_bits(x,a); + BOOST_MATH_INSTRUMENT_VARIABLE(a); + a &= traits::exponent | traits::flag | traits::significand; + BOOST_MATH_INSTRUMENT_VARIABLE((traits::exponent | traits::flag | traits::significand)); + BOOST_MATH_INSTRUMENT_VARIABLE(a); + + if(a <= traits::significand) { + if(a == 0) + return FP_ZERO; + else + return FP_SUBNORMAL; + } + + if(a < traits::exponent) return FP_NORMAL; + + a &= traits::significand; + if(a == 0) return FP_INFINITE; + + return FP_NAN; +} + +template<class T> +int fpclassify_imp BOOST_NO_MACRO_EXPAND(T x, ieee_copy_leading_bits_tag) +{ + typedef BOOST_DEDUCED_TYPENAME fp_traits<T>::type traits; + + BOOST_MATH_INSTRUMENT_VARIABLE(x); + + BOOST_DEDUCED_TYPENAME traits::bits a; + traits::get_bits(x,a); + a &= traits::exponent | traits::flag | traits::significand; + + if(a <= traits::significand) { + if(x == 0) + return FP_ZERO; + else + return FP_SUBNORMAL; + } + + if(a < traits::exponent) return FP_NORMAL; + + a &= traits::significand; + traits::set_bits(x,a); + if(x == 0) return FP_INFINITE; + + return FP_NAN; +} + +#if defined(BOOST_MATH_USE_STD_FPCLASSIFY) && defined(BOOST_MATH_NO_NATIVE_LONG_DOUBLE_FP_CLASSIFY) +template <> +inline int fpclassify_imp<long double> BOOST_NO_MACRO_EXPAND(long double t, const native_tag&) +{ + return boost::math::detail::fpclassify_imp(t, generic_tag<true>()); +} +#endif + +} // namespace detail + +template <class T> +inline int fpclassify BOOST_NO_MACRO_EXPAND(T t) +{ + typedef typename detail::fp_traits<T>::type traits; + typedef typename traits::method method; +#ifdef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS + if(std::numeric_limits<T>::is_specialized && detail::is_generic_tag_false(method())) + return detail::fpclassify_imp(t, detail::generic_tag<true>()); + return detail::fpclassify_imp(t, method()); +#else + return detail::fpclassify_imp(t, method()); +#endif +} + +namespace detail { + +#ifdef BOOST_MATH_USE_STD_FPCLASSIFY + template<class T> + inline bool isfinite_impl(T x, native_tag const&) + { + return (std::isfinite)(x); + } +#endif + + template<class T> + inline bool isfinite_impl(T x, generic_tag<true> const&) + { + return x >= -(std::numeric_limits<T>::max)() + && x <= (std::numeric_limits<T>::max)(); + } + + template<class T> + inline bool isfinite_impl(T x, generic_tag<false> const&) + { +#ifdef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS + if(std::numeric_limits<T>::is_specialized) + return isfinite_impl(x, mpl::true_()); +#endif + (void)x; // warning supression. + return true; + } + + template<class T> + inline bool isfinite_impl(T x, ieee_tag const&) + { + typedef BOOST_DEDUCED_TYPENAME detail::fp_traits<T>::type traits; + BOOST_DEDUCED_TYPENAME traits::bits a; + traits::get_bits(x,a); + a &= traits::exponent; + return a != traits::exponent; + } + +#if defined(BOOST_MATH_USE_STD_FPCLASSIFY) && defined(BOOST_MATH_NO_NATIVE_LONG_DOUBLE_FP_CLASSIFY) +template <> +inline bool isfinite_impl<long double> BOOST_NO_MACRO_EXPAND(long double t, const native_tag&) +{ + return boost::math::detail::isfinite_impl(t, generic_tag<true>()); +} +#endif + +} + +template<class T> +inline bool (isfinite)(T x) +{ //!< \brief return true if floating-point type t is finite. + typedef typename detail::fp_traits<T>::type traits; + typedef typename traits::method method; + typedef typename boost::is_floating_point<T>::type fp_tag; + return detail::isfinite_impl(x, method()); +} + +//------------------------------------------------------------------------------ + +namespace detail { + +#ifdef BOOST_MATH_USE_STD_FPCLASSIFY + template<class T> + inline bool isnormal_impl(T x, native_tag const&) + { + return (std::isnormal)(x); + } +#endif + + template<class T> + inline bool isnormal_impl(T x, generic_tag<true> const&) + { + if(x < 0) x = -x; + return x >= (std::numeric_limits<T>::min)() + && x <= (std::numeric_limits<T>::max)(); + } + + template<class T> + inline bool isnormal_impl(T x, generic_tag<false> const&) + { +#ifdef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS + if(std::numeric_limits<T>::is_specialized) + return isnormal_impl(x, mpl::true_()); +#endif + return !(x == 0); + } + + template<class T> + inline bool isnormal_impl(T x, ieee_tag const&) + { + typedef BOOST_DEDUCED_TYPENAME detail::fp_traits<T>::type traits; + BOOST_DEDUCED_TYPENAME traits::bits a; + traits::get_bits(x,a); + a &= traits::exponent | traits::flag; + return (a != 0) && (a < traits::exponent); + } + +#if defined(BOOST_MATH_USE_STD_FPCLASSIFY) && defined(BOOST_MATH_NO_NATIVE_LONG_DOUBLE_FP_CLASSIFY) +template <> +inline bool isnormal_impl<long double> BOOST_NO_MACRO_EXPAND(long double t, const native_tag&) +{ + return boost::math::detail::isnormal_impl(t, generic_tag<true>()); +} +#endif + +} + +template<class T> +inline bool (isnormal)(T x) +{ + typedef typename detail::fp_traits<T>::type traits; + typedef typename traits::method method; + typedef typename boost::is_floating_point<T>::type fp_tag; + return detail::isnormal_impl(x, method()); +} + +//------------------------------------------------------------------------------ + +namespace detail { + +#ifdef BOOST_MATH_USE_STD_FPCLASSIFY + template<class T> + inline bool isinf_impl(T x, native_tag const&) + { + return (std::isinf)(x); + } +#endif + + template<class T> + inline bool isinf_impl(T x, generic_tag<true> const&) + { + return std::numeric_limits<T>::has_infinity + && ( x == std::numeric_limits<T>::infinity() + || x == -std::numeric_limits<T>::infinity()); + } + + template<class T> + inline bool isinf_impl(T x, generic_tag<false> const&) + { +#ifdef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS + if(std::numeric_limits<T>::is_specialized) + return isinf_impl(x, mpl::true_()); +#endif + (void)x; // warning supression. + return false; + } + + template<class T> + inline bool isinf_impl(T x, ieee_copy_all_bits_tag const&) + { + typedef BOOST_DEDUCED_TYPENAME fp_traits<T>::type traits; + + BOOST_DEDUCED_TYPENAME traits::bits a; + traits::get_bits(x,a); + a &= traits::exponent | traits::significand; + return a == traits::exponent; + } + + template<class T> + inline bool isinf_impl(T x, ieee_copy_leading_bits_tag const&) + { + typedef BOOST_DEDUCED_TYPENAME fp_traits<T>::type traits; + + BOOST_DEDUCED_TYPENAME traits::bits a; + traits::get_bits(x,a); + a &= traits::exponent | traits::significand; + if(a != traits::exponent) + return false; + + traits::set_bits(x,0); + return x == 0; + } + +#if defined(BOOST_MATH_USE_STD_FPCLASSIFY) && defined(BOOST_MATH_NO_NATIVE_LONG_DOUBLE_FP_CLASSIFY) +template <> +inline bool isinf_impl<long double> BOOST_NO_MACRO_EXPAND(long double t, const native_tag&) +{ + return boost::math::detail::isinf_impl(t, generic_tag<true>()); +} +#endif + +} // namespace detail + +template<class T> +inline bool (isinf)(T x) +{ + typedef typename detail::fp_traits<T>::type traits; + typedef typename traits::method method; + typedef typename boost::is_floating_point<T>::type fp_tag; + return detail::isinf_impl(x, method()); +} + +//------------------------------------------------------------------------------ + +namespace detail { + +#ifdef BOOST_MATH_USE_STD_FPCLASSIFY + template<class T> + inline bool isnan_impl(T x, native_tag const&) + { + return (std::isnan)(x); + } +#endif + + template<class T> + inline bool isnan_impl(T x, generic_tag<true> const&) + { + return std::numeric_limits<T>::has_infinity + ? !(x <= std::numeric_limits<T>::infinity()) + : x != x; + } + + template<class T> + inline bool isnan_impl(T x, generic_tag<false> const&) + { +#ifdef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS + if(std::numeric_limits<T>::is_specialized) + return isnan_impl(x, mpl::true_()); +#endif + (void)x; // warning supression + return false; + } + + template<class T> + inline bool isnan_impl(T x, ieee_copy_all_bits_tag const&) + { + typedef BOOST_DEDUCED_TYPENAME fp_traits<T>::type traits; + + BOOST_DEDUCED_TYPENAME traits::bits a; + traits::get_bits(x,a); + a &= traits::exponent | traits::significand; + return a > traits::exponent; + } + + template<class T> + inline bool isnan_impl(T x, ieee_copy_leading_bits_tag const&) + { + typedef BOOST_DEDUCED_TYPENAME fp_traits<T>::type traits; + + BOOST_DEDUCED_TYPENAME traits::bits a; + traits::get_bits(x,a); + + a &= traits::exponent | traits::significand; + if(a < traits::exponent) + return false; + + a &= traits::significand; + traits::set_bits(x,a); + return x != 0; + } + +} // namespace detail + +template<class T> bool (isnan)(T x) +{ //!< \brief return true if floating-point type t is NaN (Not A Number). + typedef typename detail::fp_traits<T>::type traits; + typedef typename traits::method method; + typedef typename boost::is_floating_point<T>::type fp_tag; + return detail::isnan_impl(x, method()); +} + +#ifdef isnan +template <> inline bool isnan BOOST_NO_MACRO_EXPAND<float>(float t){ return ::boost::math_detail::is_nan_helper(t, boost::true_type()); } +template <> inline bool isnan BOOST_NO_MACRO_EXPAND<double>(double t){ return ::boost::math_detail::is_nan_helper(t, boost::true_type()); } +template <> inline bool isnan BOOST_NO_MACRO_EXPAND<long double>(long double t){ return ::boost::math_detail::is_nan_helper(t, boost::true_type()); } +#endif + +} // namespace math +} // namespace boost + +#endif // BOOST_MATH_FPCLASSIFY_HPP + diff --git a/Utilities/BGL/boost/math/special_functions/gamma.hpp b/Utilities/BGL/boost/math/special_functions/gamma.hpp new file mode 100644 index 0000000000000000000000000000000000000000..15b35abc39c284978edbc42bab097d4e61f660fb --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/gamma.hpp @@ -0,0 +1,1536 @@ +// Copyright John Maddock 2006-7. +// Copyright Paul A. Bristow 2007. + +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_SF_GAMMA_HPP +#define BOOST_MATH_SF_GAMMA_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/config.hpp> +#ifdef BOOST_MSVC +# pragma warning(push) +# pragma warning(disable: 4127 4701) +// // For lexical_cast, until fixed in 1.35? +// // conditional expression is constant & +// // Potentially uninitialized local variable 'name' used +#endif +#include <boost/lexical_cast.hpp> +#ifdef BOOST_MSVC +# pragma warning(pop) +#endif +#include <boost/math/tools/series.hpp> +#include <boost/math/tools/fraction.hpp> +#include <boost/math/tools/precision.hpp> +#include <boost/math/tools/promotion.hpp> +#include <boost/math/policies/error_handling.hpp> +#include <boost/math/constants/constants.hpp> +#include <boost/math/special_functions/math_fwd.hpp> +#include <boost/math/special_functions/log1p.hpp> +#include <boost/math/special_functions/trunc.hpp> +#include <boost/math/special_functions/powm1.hpp> +#include <boost/math/special_functions/sqrt1pm1.hpp> +#include <boost/math/special_functions/lanczos.hpp> +#include <boost/math/special_functions/fpclassify.hpp> +#include <boost/math/special_functions/detail/igamma_large.hpp> +#include <boost/math/special_functions/detail/unchecked_factorial.hpp> +#include <boost/math/special_functions/detail/lgamma_small.hpp> +#include <boost/type_traits/is_convertible.hpp> +#include <boost/assert.hpp> +#include <boost/mpl/greater.hpp> +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/greater.hpp> + +#include <boost/config/no_tr1/cmath.hpp> +#include <algorithm> + +#ifdef BOOST_MATH_INSTRUMENT +#include <iostream> +#include <iomanip> +#include <typeinfo> +#endif + +#ifdef BOOST_MSVC +# pragma warning(push) +# pragma warning(disable: 4702) // unreachable code (return after domain_error throw). +# pragma warning(disable: 4127) // conditional expression is constant. +# pragma warning(disable: 4100) // unreferenced formal parameter. +// Several variables made comments, +// but some difficulty as whether referenced on not may depend on macro values. +// So to be safe, 4100 warnings suppressed. +// TODO - revisit this? +#endif + +namespace boost{ namespace math{ + +namespace detail{ + +template <class T> +inline bool is_odd(T v, const boost::true_type&) +{ + int i = static_cast<int>(v); + return i&1; +} +template <class T> +inline bool is_odd(T v, const boost::false_type&) +{ + // Oh dear can't cast T to int! + BOOST_MATH_STD_USING + T modulus = v - 2 * floor(v/2); + return static_cast<bool>(modulus != 0); +} +template <class T> +inline bool is_odd(T v) +{ + return is_odd(v, ::boost::is_convertible<T, int>()); +} + +template <class T> +T sinpx(T z) +{ + // Ad hoc function calculates x * sin(pi * x), + // taking extra care near when x is near a whole number. + BOOST_MATH_STD_USING + int sign = 1; + if(z < 0) + { + z = -z; + } + else + { + sign = -sign; + } + T fl = floor(z); + T dist; + if(is_odd(fl)) + { + fl += 1; + dist = fl - z; + sign = -sign; + } + else + { + dist = z - fl; + } + BOOST_ASSERT(fl >= 0); + if(dist > 0.5) + dist = 1 - dist; + T result = sin(dist*boost::math::constants::pi<T>()); + return sign*z*result; +} // template <class T> T sinpx(T z) +// +// tgamma(z), with Lanczos support: +// +template <class T, class Policy, class L> +T gamma_imp(T z, const Policy& pol, const L& l) +{ + BOOST_MATH_STD_USING + + T result = 1; + +#ifdef BOOST_MATH_INSTRUMENT + static bool b = false; + if(!b) + { + std::cout << "tgamma_imp called with " << typeid(z).name() << " " << typeid(l).name() << std::endl; + b = true; + } +#endif + static const char* function = "boost::math::tgamma<%1%>(%1%)"; + + if(z <= 0) + { + if(floor(z) == z) + return policies::raise_pole_error<T>(function, "Evaluation of tgamma at a negative integer %1%.", z, pol); + if(z <= -20) + { + result = gamma_imp(T(-z), pol, l) * sinpx(z); + if((fabs(result) < 1) && (tools::max_value<T>() * fabs(result) < boost::math::constants::pi<T>())) + return policies::raise_overflow_error<T>(function, "Result of tgamma is too large to represent.", pol); + result = -boost::math::constants::pi<T>() / result; + if(result == 0) + return policies::raise_underflow_error<T>(function, "Result of tgamma is too small to represent.", pol); + if((boost::math::fpclassify)(result) == (int)FP_SUBNORMAL) + return policies::raise_denorm_error<T>(function, "Result of tgamma is denormalized.", result, pol); + return result; + } + + // shift z to > 1: + while(z < 0) + { + result /= z; + z += 1; + } + } + if((floor(z) == z) && (z < max_factorial<T>::value)) + { + result *= unchecked_factorial<T>(itrunc(z, pol) - 1); + } + else + { + result *= L::lanczos_sum(z); + if(z * log(z) > tools::log_max_value<T>()) + { + // we're going to overflow unless this is done with care: + T zgh = (z + static_cast<T>(L::g()) - boost::math::constants::half<T>()); + if(log(zgh) * z / 2 > tools::log_max_value<T>()) + return policies::raise_overflow_error<T>(function, "Result of tgamma is too large to represent.", pol); + T hp = pow(zgh, (z / 2) - T(0.25)); + result *= hp / exp(zgh); + if(tools::max_value<T>() / hp < result) + return policies::raise_overflow_error<T>(function, "Result of tgamma is too large to represent.", pol); + result *= hp; + } + else + { + T zgh = (z + static_cast<T>(L::g()) - boost::math::constants::half<T>()); + result *= pow(zgh, z - boost::math::constants::half<T>()) / exp(zgh); + } + } + return result; +} +// +// lgamma(z) with Lanczos support: +// +template <class T, class Policy, class L> +T lgamma_imp(T z, const Policy& pol, const L& l, int* sign = 0) +{ +#ifdef BOOST_MATH_INSTRUMENT + static bool b = false; + if(!b) + { + std::cout << "lgamma_imp called with " << typeid(z).name() << " " << typeid(l).name() << std::endl; + b = true; + } +#endif + + BOOST_MATH_STD_USING + + static const char* function = "boost::math::lgamma<%1%>(%1%)"; + + T result = 0; + int sresult = 1; + if(z <= 0) + { + // reflection formula: + if(floor(z) == z) + return policies::raise_pole_error<T>(function, "Evaluation of lgamma at a negative integer %1%.", z, pol); + + T t = sinpx(z); + z = -z; + if(t < 0) + { + t = -t; + } + else + { + sresult = -sresult; + } + result = log(boost::math::constants::pi<T>()) - lgamma_imp(z, pol, l) - log(t); + } + else if(z < 15) + { + typedef typename policies::precision<T, Policy>::type precision_type; + typedef typename mpl::if_< + mpl::and_< + mpl::less_equal<precision_type, mpl::int_<64> >, + mpl::greater<precision_type, mpl::int_<0> > + >, + mpl::int_<64>, + typename mpl::if_< + mpl::and_< + mpl::less_equal<precision_type, mpl::int_<113> >, + mpl::greater<precision_type, mpl::int_<0> > + >, + mpl::int_<113>, mpl::int_<0> >::type + >::type tag_type; + result = lgamma_small_imp<T>(z, z - 1, z - 2, tag_type(), pol, l); + } + else if((z >= 3) && (z < 100)) + { + // taking the log of tgamma reduces the error, no danger of overflow here: + result = log(gamma_imp(z, pol, l)); + } + else + { + // regular evaluation: + T zgh = static_cast<T>(z + L::g() - boost::math::constants::half<T>()); + result = log(zgh) - 1; + result *= z - 0.5f; + result += log(L::lanczos_sum_expG_scaled(z)); + } + + if(sign) + *sign = sresult; + return result; +} + +// +// Incomplete gamma functions follow: +// +template <class T> +struct upper_incomplete_gamma_fract +{ +private: + T z, a; + int k; +public: + typedef std::pair<T,T> result_type; + + upper_incomplete_gamma_fract(T a1, T z1) + : z(z1-a1+1), a(a1), k(0) + { + } + + result_type operator()() + { + ++k; + z += 2; + return result_type(k * (a - k), z); + } +}; + +template <class T> +inline T upper_gamma_fraction(T a, T z, T eps) +{ + // Multiply result by z^a * e^-z to get the full + // upper incomplete integral. Divide by tgamma(z) + // to normalise. + upper_incomplete_gamma_fract<T> f(a, z); + return 1 / (z - a + 1 + boost::math::tools::continued_fraction_a(f, eps)); +} + +template <class T> +struct lower_incomplete_gamma_series +{ +private: + T a, z, result; +public: + typedef T result_type; + lower_incomplete_gamma_series(T a1, T z1) : a(a1), z(z1), result(1){} + + T operator()() + { + T r = result; + a += 1; + result *= z/a; + return r; + } +}; + +template <class T, class Policy> +inline T lower_gamma_series(T a, T z, const Policy& pol, T init_value = 0) +{ + // Multiply result by ((z^a) * (e^-z) / a) to get the full + // lower incomplete integral. Then divide by tgamma(a) + // to get the normalised value. + lower_incomplete_gamma_series<T> s(a, z); + boost::uintmax_t max_iter = policies::get_max_series_iterations<Policy>(); + T factor = policies::get_epsilon<T, Policy>(); + T result = boost::math::tools::sum_series(s, factor, max_iter, init_value); + policies::check_series_iterations("boost::math::detail::lower_gamma_series<%1%>(%1%)", max_iter, pol); + return result; +} + +// +// Fully generic tgamma and lgamma use the incomplete partial +// sums added together: +// +template <class T, class Policy> +T gamma_imp(T z, const Policy& pol, const lanczos::undefined_lanczos& l) +{ + static const char* function = "boost::math::tgamma<%1%>(%1%)"; + BOOST_MATH_STD_USING + if((z <= 0) && (floor(z) == z)) + return policies::raise_pole_error<T>(function, "Evaluation of tgamma at a negative integer %1%.", z, pol); + if(z <= -20) + { + T result = gamma_imp(-z, pol, l) * sinpx(z); + if((fabs(result) < 1) && (tools::max_value<T>() * fabs(result) < boost::math::constants::pi<T>())) + return policies::raise_overflow_error<T>(function, "Result of tgamma is too large to represent.", pol); + result = -boost::math::constants::pi<T>() / result; + if(result == 0) + return policies::raise_underflow_error<T>(function, "Result of tgamma is too small to represent.", pol); + if((boost::math::fpclassify)(result) == (int)FP_SUBNORMAL) + return policies::raise_denorm_error<T>(function, "Result of tgamma is denormalized.", result, pol); + return result; + } + // + // The upper gamma fraction is *very* slow for z < 6, actually it's very + // slow to converge everywhere but recursing until z > 6 gets rid of the + // worst of it's behaviour. + // + T prefix = 1; + while(z < 6) + { + prefix /= z; + z += 1; + } + BOOST_MATH_INSTRUMENT_CODE(prefix); + if((floor(z) == z) && (z < max_factorial<T>::value)) + { + prefix *= unchecked_factorial<T>(itrunc(z, pol) - 1); + } + else + { + prefix = prefix * pow(z / boost::math::constants::e<T>(), z); + BOOST_MATH_INSTRUMENT_CODE(prefix); + T sum = detail::lower_gamma_series(z, z, pol) / z; + BOOST_MATH_INSTRUMENT_CODE(sum); + sum += detail::upper_gamma_fraction(z, z, ::boost::math::policies::get_epsilon<T, Policy>()); + BOOST_MATH_INSTRUMENT_CODE(sum); + if(fabs(tools::max_value<T>() / prefix) < fabs(sum)) + return policies::raise_overflow_error<T>(function, "Result of tgamma is too large to represent.", pol); + BOOST_MATH_INSTRUMENT_CODE((sum * prefix)); + return sum * prefix; + } + return prefix; +} + +template <class T, class Policy> +T lgamma_imp(T z, const Policy& pol, const lanczos::undefined_lanczos& l, int*sign) +{ + BOOST_MATH_STD_USING + + static const char* function = "boost::math::lgamma<%1%>(%1%)"; + T result = 0; + int sresult = 1; + if(z <= 0) + { + if(floor(z) == z) + return policies::raise_pole_error<T>(function, "Evaluation of tgamma at a negative integer %1%.", z, pol); + T t = detail::sinpx(z); + z = -z; + if(t < 0) + { + t = -t; + } + else + { + sresult = -sresult; + } + result = log(boost::math::constants::pi<T>()) - lgamma_imp(z, pol, l, 0) - log(t); + } + else if((z != 1) && (z != 2)) + { + T limit = (std::max)(z+1, T(10)); + T prefix = z * log(limit) - limit; + T sum = detail::lower_gamma_series(z, limit, pol) / z; + sum += detail::upper_gamma_fraction(z, limit, ::boost::math::policies::get_epsilon<T, Policy>()); + result = log(sum) + prefix; + } + if(sign) + *sign = sresult; + return result; +} +// +// This helper calculates tgamma(dz+1)-1 without cancellation errors, +// used by the upper incomplete gamma with z < 1: +// +template <class T, class Policy, class L> +T tgammap1m1_imp(T dz, Policy const& pol, const L& l) +{ + BOOST_MATH_STD_USING + + typedef typename policies::precision<T,Policy>::type precision_type; + + typedef typename mpl::if_< + mpl::or_< + mpl::less_equal<precision_type, mpl::int_<0> >, + mpl::greater<precision_type, mpl::int_<113> > + >, + typename mpl::if_< + is_same<L, lanczos::lanczos24m113>, + mpl::int_<113>, + mpl::int_<0> + >::type, + typename mpl::if_< + mpl::less_equal<precision_type, mpl::int_<64> >, + mpl::int_<64>, mpl::int_<113> >::type + >::type tag_type; + + T result; + if(dz < 0) + { + if(dz < -0.5) + { + // Best method is simply to subtract 1 from tgamma: + result = boost::math::tgamma(1+dz, pol) - 1; + BOOST_MATH_INSTRUMENT_CODE(result); + } + else + { + // Use expm1 on lgamma: + result = boost::math::expm1(-boost::math::log1p(dz, pol) + + lgamma_small_imp<T>(dz+2, dz + 1, dz, tag_type(), pol, l)); + BOOST_MATH_INSTRUMENT_CODE(result); + } + } + else + { + if(dz < 2) + { + // Use expm1 on lgamma: + result = boost::math::expm1(lgamma_small_imp<T>(dz+1, dz, dz-1, tag_type(), pol, l), pol); + BOOST_MATH_INSTRUMENT_CODE(result); + } + else + { + // Best method is simply to subtract 1 from tgamma: + result = boost::math::tgamma(1+dz, pol) - 1; + BOOST_MATH_INSTRUMENT_CODE(result); + } + } + + return result; +} + +template <class T, class Policy> +inline T tgammap1m1_imp(T dz, Policy const& pol, + const ::boost::math::lanczos::undefined_lanczos& l) +{ + BOOST_MATH_STD_USING // ADL of std names + // + // There should be a better solution than this, but the + // algebra isn't easy for the general case.... + // Start by subracting 1 from tgamma: + // + T result = gamma_imp(1 + dz, pol, l) - 1; + BOOST_MATH_INSTRUMENT_CODE(result); + // + // Test the level of cancellation error observed: we loose one bit + // for each power of 2 the result is less than 1. If we would get + // more bits from our most precise lgamma rational approximation, + // then use that instead: + // + BOOST_MATH_INSTRUMENT_CODE((dz > -0.5)); + BOOST_MATH_INSTRUMENT_CODE((dz < 2)); + BOOST_MATH_INSTRUMENT_CODE((ldexp(1.0, boost::math::policies::digits<T, Policy>()) * fabs(result) < 1e34)); + if((dz > -0.5) && (dz < 2) && (ldexp(1.0, boost::math::policies::digits<T, Policy>()) * fabs(result) < 1e34)) + { + result = tgammap1m1_imp(dz, pol, boost::math::lanczos::lanczos24m113()); + BOOST_MATH_INSTRUMENT_CODE(result); + } + return result; +} + +// +// Series representation for upper fraction when z is small: +// +template <class T> +struct small_gamma2_series +{ + typedef T result_type; + + small_gamma2_series(T a_, T x_) : result(-x_), x(-x_), apn(a_+1), n(1){} + + T operator()() + { + T r = result / (apn); + result *= x; + result /= ++n; + apn += 1; + return r; + } + +private: + T result, x, apn; + int n; +}; +// +// calculate power term prefix (z^a)(e^-z) used in the non-normalised +// incomplete gammas: +// +template <class T, class Policy> +T full_igamma_prefix(T a, T z, const Policy& pol) +{ + BOOST_MATH_STD_USING + + T prefix; + T alz = a * log(z); + + if(z >= 1) + { + if((alz < tools::log_max_value<T>()) && (-z > tools::log_min_value<T>())) + { + prefix = pow(z, a) * exp(-z); + } + else if(a >= 1) + { + prefix = pow(z / exp(z/a), a); + } + else + { + prefix = exp(alz - z); + } + } + else + { + if(alz > tools::log_min_value<T>()) + { + prefix = pow(z, a) * exp(-z); + } + else if(z/a < tools::log_max_value<T>()) + { + prefix = pow(z / exp(z/a), a); + } + else + { + prefix = exp(alz - z); + } + } + // + // This error handling isn't very good: it happens after the fact + // rather than before it... + // + if((boost::math::fpclassify)(prefix) == (int)FP_INFINITE) + policies::raise_overflow_error<T>("boost::math::detail::full_igamma_prefix<%1%>(%1%, %1%)", "Result of incomplete gamma function is too large to represent.", pol); + + return prefix; +} +// +// Compute (z^a)(e^-z)/tgamma(a) +// most if the error occurs in this function: +// +template <class T, class Policy, class L> +T regularised_gamma_prefix(T a, T z, const Policy& pol, const L& l) +{ + BOOST_MATH_STD_USING + T agh = a + static_cast<T>(L::g()) - T(0.5); + T prefix; + T d = ((z - a) - static_cast<T>(L::g()) + T(0.5)) / agh; + + if(a < 1) + { + // + // We have to treat a < 1 as a special case because our Lanczos + // approximations are optimised against the factorials with a > 1, + // and for high precision types especially (128-bit reals for example) + // very small values of a can give rather eroneous results for gamma + // unless we do this: + // + // TODO: is this still required? Lanczos approx should be better now? + // + if(z <= tools::log_min_value<T>()) + { + // Oh dear, have to use logs, should be free of cancellation errors though: + return exp(a * log(z) - z - lgamma_imp(a, pol, l)); + } + else + { + // direct calculation, no danger of overflow as gamma(a) < 1/a + // for small a. + return pow(z, a) * exp(-z) / gamma_imp(a, pol, l); + } + } + else if((fabs(d*d*a) <= 100) && (a > 150)) + { + // special case for large a and a ~ z. + prefix = a * boost::math::log1pmx(d, pol) + z * static_cast<T>(0.5 - L::g()) / agh; + prefix = exp(prefix); + } + else + { + // + // general case. + // direct computation is most accurate, but use various fallbacks + // for different parts of the problem domain: + // + T alz = a * log(z / agh); + T amz = a - z; + if(((std::min)(alz, amz) <= tools::log_min_value<T>()) || ((std::max)(alz, amz) >= tools::log_max_value<T>())) + { + T amza = amz / a; + if(((std::min)(alz, amz)/2 > tools::log_min_value<T>()) && ((std::max)(alz, amz)/2 < tools::log_max_value<T>())) + { + // compute square root of the result and then square it: + T sq = pow(z / agh, a / 2) * exp(amz / 2); + prefix = sq * sq; + } + else if(((std::min)(alz, amz)/4 > tools::log_min_value<T>()) && ((std::max)(alz, amz)/4 < tools::log_max_value<T>()) && (z > a)) + { + // compute the 4th root of the result then square it twice: + T sq = pow(z / agh, a / 4) * exp(amz / 4); + prefix = sq * sq; + prefix *= prefix; + } + else if((amza > tools::log_min_value<T>()) && (amza < tools::log_max_value<T>())) + { + prefix = pow((z * exp(amza)) / agh, a); + } + else + { + prefix = exp(alz + amz); + } + } + else + { + prefix = pow(z / agh, a) * exp(amz); + } + } + prefix *= sqrt(agh / boost::math::constants::e<T>()) / L::lanczos_sum_expG_scaled(a); + return prefix; +} +// +// And again, without Lanczos support: +// +template <class T, class Policy> +T regularised_gamma_prefix(T a, T z, const Policy& pol, const lanczos::undefined_lanczos&) +{ + BOOST_MATH_STD_USING + + T limit = (std::max)(T(10), a); + T sum = detail::lower_gamma_series(a, limit, pol) / a; + sum += detail::upper_gamma_fraction(a, limit, ::boost::math::policies::get_epsilon<T, Policy>()); + + if(a < 10) + { + // special case for small a: + T prefix = pow(z / 10, a); + prefix *= exp(10-z); + if(0 == prefix) + { + prefix = pow((z * exp((10-z)/a)) / 10, a); + } + prefix /= sum; + return prefix; + } + + T zoa = z / a; + T amz = a - z; + T alzoa = a * log(zoa); + T prefix; + if(((std::min)(alzoa, amz) <= tools::log_min_value<T>()) || ((std::max)(alzoa, amz) >= tools::log_max_value<T>())) + { + T amza = amz / a; + if((amza <= tools::log_min_value<T>()) || (amza >= tools::log_max_value<T>())) + { + prefix = exp(alzoa + amz); + } + else + { + prefix = pow(zoa * exp(amza), a); + } + } + else + { + prefix = pow(zoa, a) * exp(amz); + } + prefix /= sum; + return prefix; +} +// +// Upper gamma fraction for very small a: +// +template <class T, class Policy> +inline T tgamma_small_upper_part(T a, T x, const Policy& pol, T* pgam = 0, bool invert = false, T* pderivative = 0) +{ + BOOST_MATH_STD_USING // ADL of std functions. + // + // Compute the full upper fraction (Q) when a is very small: + // + T result; + result = boost::math::tgamma1pm1(a, pol); + if(pgam) + *pgam = (result + 1) / a; + T p = boost::math::powm1(x, a, pol); + result -= p; + result /= a; + detail::small_gamma2_series<T> s(a, x); + boost::uintmax_t max_iter = policies::get_max_series_iterations<Policy>() - 10; + p += 1; + if(pderivative) + *pderivative = p / (*pgam * exp(x)); + T init_value = invert ? *pgam : 0; + result = -p * tools::sum_series(s, boost::math::policies::get_epsilon<T, Policy>(), max_iter, (init_value - result) / p); + policies::check_series_iterations("boost::math::tgamma_small_upper_part<%1%>(%1%, %1%)", max_iter, pol); + if(invert) + result = -result; + return result; +} +// +// Upper gamma fraction for integer a: +// +template <class T, class Policy> +inline T finite_gamma_q(T a, T x, Policy const& pol, T* pderivative = 0) +{ + // + // Calculates normalised Q when a is an integer: + // + BOOST_MATH_STD_USING + T e = exp(-x); + T sum = e; + if(sum != 0) + { + T term = sum; + for(unsigned n = 1; n < a; ++n) + { + term /= n; + term *= x; + sum += term; + } + } + if(pderivative) + { + *pderivative = e * pow(x, a) / boost::math::unchecked_factorial<T>(itrunc(T(a - 1), pol)); + } + return sum; +} +// +// Upper gamma fraction for half integer a: +// +template <class T, class Policy> +T finite_half_gamma_q(T a, T x, T* p_derivative, const Policy& pol) +{ + // + // Calculates normalised Q when a is a half-integer: + // + BOOST_MATH_STD_USING + T e = boost::math::erfc(sqrt(x), pol); + if((e != 0) && (a > 1)) + { + T term = exp(-x) / sqrt(constants::pi<T>() * x); + term *= x; + static const T half = T(1) / 2; + term /= half; + T sum = term; + for(unsigned n = 2; n < a; ++n) + { + term /= n - half; + term *= x; + sum += term; + } + e += sum; + if(p_derivative) + { + *p_derivative = 0; + } + } + else if(p_derivative) + { + // We'll be dividing by x later, so calculate derivative * x: + *p_derivative = sqrt(x) * exp(-x) / constants::root_pi<T>(); + } + return e; +} +// +// Main incomplete gamma entry point, handles all four incomplete gamma's: +// +template <class T, class Policy> +T gamma_incomplete_imp(T a, T x, bool normalised, bool invert, + const Policy& pol, T* p_derivative) +{ + static const char* function = "boost::math::gamma_p<%1%>(%1%, %1%)"; + if(a <= 0) + policies::raise_domain_error<T>(function, "Argument a to the incomplete gamma function must be greater than zero (got a=%1%).", a, pol); + if(x < 0) + policies::raise_domain_error<T>(function, "Argument x to the incomplete gamma function must be >= 0 (got x=%1%).", x, pol); + + BOOST_MATH_STD_USING + + typedef typename lanczos::lanczos<T, Policy>::type lanczos_type; + + T result; + + BOOST_ASSERT((p_derivative == 0) || (normalised == true)); + + bool is_int, is_half_int; + bool is_small_a = (a < 30) && (a <= x + 1); + if(is_small_a) + { + T fa = floor(a); + is_int = (fa == a); + is_half_int = is_int ? false : (fabs(fa - a) == 0.5f); + } + else + { + is_int = is_half_int = false; + } + + int eval_method; + + if(is_int && (x > 0.6)) + { + // calculate Q via finite sum: + invert = !invert; + eval_method = 0; + } + else if(is_half_int && (x > 0.2)) + { + // calculate Q via finite sum for half integer a: + invert = !invert; + eval_method = 1; + } + else if(x < 0.5) + { + // + // Changeover criterion chosen to give a changeover at Q ~ 0.33 + // + if(-0.4 / log(x) < a) + { + eval_method = 2; + } + else + { + eval_method = 3; + } + } + else if(x < 1.1) + { + // + // Changover here occurs when P ~ 0.75 or Q ~ 0.25: + // + if(x * 0.75f < a) + { + eval_method = 2; + } + else + { + eval_method = 3; + } + } + else + { + // + // Begin by testing whether we're in the "bad" zone + // where the result will be near 0.5 and the usual + // series and continued fractions are slow to converge: + // + bool use_temme = false; + if(normalised && std::numeric_limits<T>::is_specialized && (a > 20)) + { + T sigma = fabs((x-a)/a); + if((a > 200) && (policies::digits<T, Policy>() <= 113)) + { + // + // This limit is chosen so that we use Temme's expansion + // only if the result would be larger than about 10^-6. + // Below that the regular series and continued fractions + // converge OK, and if we use Temme's method we get increasing + // errors from the dominant erfc term as it's (inexact) argument + // increases in magnitude. + // + if(20 / a > sigma * sigma) + use_temme = true; + } + else if(policies::digits<T, Policy>() <= 64) + { + // Note in this zone we can't use Temme's expansion for + // types longer than an 80-bit real: + // it would require too many terms in the polynomials. + if(sigma < 0.4) + use_temme = true; + } + } + if(use_temme) + { + eval_method = 5; + } + else + { + // + // Regular case where the result will not be too close to 0.5. + // + // Changeover here occurs at P ~ Q ~ 0.5 + // Note that series computation of P is about x2 faster than continued fraction + // calculation of Q, so try and use the CF only when really necessary, especially + // for small x. + // + if(x - (1 / (3 * x)) < a) + { + eval_method = 2; + } + else + { + eval_method = 4; + invert = !invert; + } + } + } + + switch(eval_method) + { + case 0: + { + result = finite_gamma_q(a, x, pol, p_derivative); + if(normalised == false) + result *= boost::math::tgamma(a, pol); + break; + } + case 1: + { + result = finite_half_gamma_q(a, x, p_derivative, pol); + if(normalised == false) + result *= boost::math::tgamma(a, pol); + if(p_derivative && (*p_derivative == 0)) + *p_derivative = regularised_gamma_prefix(a, x, pol, lanczos_type()); + break; + } + case 2: + { + // Compute P: + result = normalised ? regularised_gamma_prefix(a, x, pol, lanczos_type()) : full_igamma_prefix(a, x, pol); + if(p_derivative) + *p_derivative = result; + if(result != 0) + { + T init_value = 0; + if(invert) + { + init_value = -a * (normalised ? 1 : boost::math::tgamma(a, pol)) / result; + } + result *= detail::lower_gamma_series(a, x, pol, init_value) / a; + if(invert) + { + invert = false; + result = -result; + } + } + break; + } + case 3: + { + // Compute Q: + invert = !invert; + T g; + result = tgamma_small_upper_part(a, x, pol, &g, invert, p_derivative); + invert = false; + if(normalised) + result /= g; + break; + } + case 4: + { + // Compute Q: + result = normalised ? regularised_gamma_prefix(a, x, pol, lanczos_type()) : full_igamma_prefix(a, x, pol); + if(p_derivative) + *p_derivative = result; + if(result != 0) + result *= upper_gamma_fraction(a, x, policies::get_epsilon<T, Policy>()); + break; + } + case 5: + { + // + // Use compile time dispatch to the appropriate + // Temme asymptotic expansion. This may be dead code + // if T does not have numeric limits support, or has + // too many digits for the most precise version of + // these expansions, in that case we'll be calling + // an empty function. + // + typedef typename policies::precision<T, Policy>::type precision_type; + + typedef typename mpl::if_< + mpl::or_<mpl::equal_to<precision_type, mpl::int_<0> >, + mpl::greater<precision_type, mpl::int_<113> > >, + mpl::int_<0>, + typename mpl::if_< + mpl::less_equal<precision_type, mpl::int_<53> >, + mpl::int_<53>, + typename mpl::if_< + mpl::less_equal<precision_type, mpl::int_<64> >, + mpl::int_<64>, + mpl::int_<113> + >::type + >::type + >::type tag_type; + + result = igamma_temme_large(a, x, pol, static_cast<tag_type const*>(0)); + if(x >= a) + invert = !invert; + if(p_derivative) + *p_derivative = regularised_gamma_prefix(a, x, pol, lanczos_type()); + break; + } + } + + if(normalised && (result > 1)) + result = 1; + if(invert) + { + T gam = normalised ? 1 : boost::math::tgamma(a, pol); + result = gam - result; + } + if(p_derivative) + { + // + // Need to convert prefix term to derivative: + // + if((x < 1) && (tools::max_value<T>() * x < *p_derivative)) + { + // overflow, just return an arbitrarily large value: + *p_derivative = tools::max_value<T>() / 2; + } + + *p_derivative /= x; + } + + return result; +} + +// +// Ratios of two gamma functions: +// +template <class T, class Policy, class L> +T tgamma_delta_ratio_imp_lanczos(T z, T delta, const Policy& pol, const L&) +{ + BOOST_MATH_STD_USING + T zgh = z + L::g() - constants::half<T>(); + T result; + if(fabs(delta) < 10) + { + result = exp((constants::half<T>() - z) * boost::math::log1p(delta / zgh, pol)); + } + else + { + result = pow(zgh / (zgh + delta), z - constants::half<T>()); + } + result *= pow(constants::e<T>() / (zgh + delta), delta); + result *= L::lanczos_sum(z) / L::lanczos_sum(z + delta); + return result; +} +// +// And again without Lanczos support this time: +// +template <class T, class Policy> +T tgamma_delta_ratio_imp_lanczos(T z, T delta, const Policy& pol, const lanczos::undefined_lanczos&) +{ + BOOST_MATH_STD_USING + // + // The upper gamma fraction is *very* slow for z < 6, actually it's very + // slow to converge everywhere but recursing until z > 6 gets rid of the + // worst of it's behaviour. + // + T prefix = 1; + T zd = z + delta; + while((zd < 6) && (z < 6)) + { + prefix /= z; + prefix *= zd; + z += 1; + zd += 1; + } + if(delta < 10) + { + prefix *= exp(-z * boost::math::log1p(delta / z, pol)); + } + else + { + prefix *= pow(z / zd, z); + } + prefix *= pow(constants::e<T>() / zd, delta); + T sum = detail::lower_gamma_series(z, z, pol) / z; + sum += detail::upper_gamma_fraction(z, z, ::boost::math::policies::get_epsilon<T, Policy>()); + T sumd = detail::lower_gamma_series(zd, zd, pol) / zd; + sumd += detail::upper_gamma_fraction(zd, zd, ::boost::math::policies::get_epsilon<T, Policy>()); + sum /= sumd; + if(fabs(tools::max_value<T>() / prefix) < fabs(sum)) + return policies::raise_overflow_error<T>("boost::math::tgamma_delta_ratio<%1%>(%1%, %1%)", "Result of tgamma is too large to represent.", pol); + return sum * prefix; +} + +template <class T, class Policy> +T tgamma_delta_ratio_imp(T z, T delta, const Policy& pol) +{ + BOOST_MATH_STD_USING + + if(z <= 0) + policies::raise_domain_error<T>("boost::math::tgamma_delta_ratio<%1%>(%1%, %1%)", "Gamma function ratios only implemented for positive arguments (got a=%1%).", z, pol); + if(z+delta <= 0) + policies::raise_domain_error<T>("boost::math::tgamma_delta_ratio<%1%>(%1%, %1%)", "Gamma function ratios only implemented for positive arguments (got b=%1%).", z+delta, pol); + + if(floor(delta) == delta) + { + if(floor(z) == z) + { + // + // Both z and delta are integers, see if we can just use table lookup + // of the factorials to get the result: + // + if((z <= max_factorial<T>::value) && (z + delta <= max_factorial<T>::value)) + { + return unchecked_factorial<T>((unsigned)itrunc(z, pol) - 1) / unchecked_factorial<T>((unsigned)itrunc(T(z + delta), pol) - 1); + } + } + if(fabs(delta) < 20) + { + // + // delta is a small integer, we can use a finite product: + // + if(delta == 0) + return 1; + if(delta < 0) + { + z -= 1; + T result = z; + while(0 != (delta += 1)) + { + z -= 1; + result *= z; + } + return result; + } + else + { + T result = 1 / z; + while(0 != (delta -= 1)) + { + z += 1; + result /= z; + } + return result; + } + } + } + typedef typename lanczos::lanczos<T, Policy>::type lanczos_type; + return tgamma_delta_ratio_imp_lanczos(z, delta, pol, lanczos_type()); +} + +template <class T, class Policy> +T gamma_p_derivative_imp(T a, T x, const Policy& pol) +{ + // + // Usual error checks first: + // + if(a <= 0) + policies::raise_domain_error<T>("boost::math::gamma_p_derivative<%1%>(%1%, %1%)", "Argument a to the incomplete gamma function must be greater than zero (got a=%1%).", a, pol); + if(x < 0) + policies::raise_domain_error<T>("boost::math::gamma_p_derivative<%1%>(%1%, %1%)", "Argument x to the incomplete gamma function must be >= 0 (got x=%1%).", x, pol); + // + // Now special cases: + // + if(x == 0) + { + return (a > 1) ? 0 : + (a == 1) ? 1 : policies::raise_overflow_error<T>("boost::math::gamma_p_derivative<%1%>(%1%, %1%)", 0, pol); + } + // + // Normal case: + // + typedef typename lanczos::lanczos<T, Policy>::type lanczos_type; + T f1 = detail::regularised_gamma_prefix(a, x, pol, lanczos_type()); + if((x < 1) && (tools::max_value<T>() * x < f1)) + { + // overflow: + return policies::raise_overflow_error<T>("boost::math::gamma_p_derivative<%1%>(%1%, %1%)", 0, pol); + } + + f1 /= x; + + return f1; +} + +template <class T, class Policy> +inline typename tools::promote_args<T>::type + tgamma(T z, const Policy& /* pol */, const mpl::true_) +{ + BOOST_FPU_EXCEPTION_GUARD + typedef typename tools::promote_args<T>::type result_type; + typedef typename policies::evaluation<result_type, Policy>::type value_type; + typedef typename lanczos::lanczos<value_type, Policy>::type evaluation_type; + typedef typename policies::normalise< + Policy, + policies::promote_float<false>, + policies::promote_double<false>, + policies::discrete_quantile<>, + policies::assert_undefined<> >::type forwarding_policy; + return policies::checked_narrowing_cast<result_type, forwarding_policy>(detail::gamma_imp(static_cast<value_type>(z), forwarding_policy(), evaluation_type()), "boost::math::tgamma<%1%>(%1%)"); +} + +template <class T1, class T2, class Policy> +inline typename tools::promote_args<T1, T2>::type + tgamma(T1 a, T2 z, const Policy&, const mpl::false_) +{ + BOOST_FPU_EXCEPTION_GUARD + typedef typename tools::promote_args<T1, T2>::type result_type; + typedef typename policies::evaluation<result_type, Policy>::type value_type; + typedef typename lanczos::lanczos<value_type, Policy>::type evaluation_type; + typedef typename policies::normalise< + Policy, + policies::promote_float<false>, + policies::promote_double<false>, + policies::discrete_quantile<>, + policies::assert_undefined<> >::type forwarding_policy; + return policies::checked_narrowing_cast<result_type, forwarding_policy>( + detail::gamma_incomplete_imp(static_cast<value_type>(a), + static_cast<value_type>(z), false, true, + forwarding_policy(), static_cast<value_type*>(0)), "boost::math::tgamma<%1%>(%1%, %1%)"); +} + +template <class T1, class T2> +inline typename tools::promote_args<T1, T2>::type + tgamma(T1 a, T2 z, const mpl::false_ tag) +{ + return tgamma(a, z, policies::policy<>(), tag); +} + +} // namespace detail + +template <class T> +inline typename tools::promote_args<T>::type + tgamma(T z) +{ + return tgamma(z, policies::policy<>()); +} + +template <class T, class Policy> +inline typename tools::promote_args<T>::type + lgamma(T z, int* sign, const Policy&) +{ + BOOST_FPU_EXCEPTION_GUARD + typedef typename tools::promote_args<T>::type result_type; + typedef typename policies::evaluation<result_type, Policy>::type value_type; + typedef typename lanczos::lanczos<value_type, Policy>::type evaluation_type; + typedef typename policies::normalise< + Policy, + policies::promote_float<false>, + policies::promote_double<false>, + policies::discrete_quantile<>, + policies::assert_undefined<> >::type forwarding_policy; + return policies::checked_narrowing_cast<result_type, forwarding_policy>(detail::lgamma_imp(static_cast<value_type>(z), forwarding_policy(), evaluation_type(), sign), "boost::math::lgamma<%1%>(%1%)"); +} + +template <class T> +inline typename tools::promote_args<T>::type + lgamma(T z, int* sign) +{ + return lgamma(z, sign, policies::policy<>()); +} + +template <class T, class Policy> +inline typename tools::promote_args<T>::type + lgamma(T x, const Policy& pol) +{ + return ::boost::math::lgamma(x, 0, pol); +} + +template <class T> +inline typename tools::promote_args<T>::type + lgamma(T x) +{ + return ::boost::math::lgamma(x, 0, policies::policy<>()); +} + +template <class T, class Policy> +inline typename tools::promote_args<T>::type + tgamma1pm1(T z, const Policy& /* pol */) +{ + BOOST_FPU_EXCEPTION_GUARD + typedef typename tools::promote_args<T>::type result_type; + typedef typename policies::evaluation<result_type, Policy>::type value_type; + typedef typename lanczos::lanczos<value_type, Policy>::type evaluation_type; + typedef typename policies::normalise< + Policy, + policies::promote_float<false>, + policies::promote_double<false>, + policies::discrete_quantile<>, + policies::assert_undefined<> >::type forwarding_policy; + + return policies::checked_narrowing_cast<typename remove_cv<result_type>::type, forwarding_policy>(detail::tgammap1m1_imp(static_cast<value_type>(z), forwarding_policy(), evaluation_type()), "boost::math::tgamma1pm1<%!%>(%1%)"); +} + +template <class T> +inline typename tools::promote_args<T>::type + tgamma1pm1(T z) +{ + return tgamma1pm1(z, policies::policy<>()); +} + +// +// Full upper incomplete gamma: +// +template <class T1, class T2> +inline typename tools::promote_args<T1, T2>::type + tgamma(T1 a, T2 z) +{ + // + // Type T2 could be a policy object, or a value, select the + // right overload based on T2: + // + typedef typename policies::is_policy<T2>::type maybe_policy; + return detail::tgamma(a, z, maybe_policy()); +} +template <class T1, class T2, class Policy> +inline typename tools::promote_args<T1, T2>::type + tgamma(T1 a, T2 z, const Policy& pol) +{ + return detail::tgamma(a, z, pol, mpl::false_()); +} +// +// Full lower incomplete gamma: +// +template <class T1, class T2, class Policy> +inline typename tools::promote_args<T1, T2>::type + tgamma_lower(T1 a, T2 z, const Policy&) +{ + BOOST_FPU_EXCEPTION_GUARD + typedef typename tools::promote_args<T1, T2>::type result_type; + typedef typename policies::evaluation<result_type, Policy>::type value_type; + typedef typename lanczos::lanczos<value_type, Policy>::type evaluation_type; + typedef typename policies::normalise< + Policy, + policies::promote_float<false>, + policies::promote_double<false>, + policies::discrete_quantile<>, + policies::assert_undefined<> >::type forwarding_policy; + + return policies::checked_narrowing_cast<result_type, forwarding_policy>( + detail::gamma_incomplete_imp(static_cast<value_type>(a), + static_cast<value_type>(z), false, false, + forwarding_policy(), static_cast<value_type*>(0)), "tgamma_lower<%1%>(%1%, %1%)"); +} +template <class T1, class T2> +inline typename tools::promote_args<T1, T2>::type + tgamma_lower(T1 a, T2 z) +{ + return tgamma_lower(a, z, policies::policy<>()); +} +// +// Regularised upper incomplete gamma: +// +template <class T1, class T2, class Policy> +inline typename tools::promote_args<T1, T2>::type + gamma_q(T1 a, T2 z, const Policy& /* pol */) +{ + BOOST_FPU_EXCEPTION_GUARD + typedef typename tools::promote_args<T1, T2>::type result_type; + typedef typename policies::evaluation<result_type, Policy>::type value_type; + typedef typename lanczos::lanczos<value_type, Policy>::type evaluation_type; + typedef typename policies::normalise< + Policy, + policies::promote_float<false>, + policies::promote_double<false>, + policies::discrete_quantile<>, + policies::assert_undefined<> >::type forwarding_policy; + + return policies::checked_narrowing_cast<result_type, forwarding_policy>( + detail::gamma_incomplete_imp(static_cast<value_type>(a), + static_cast<value_type>(z), true, true, + forwarding_policy(), static_cast<value_type*>(0)), "gamma_q<%1%>(%1%, %1%)"); +} +template <class T1, class T2> +inline typename tools::promote_args<T1, T2>::type + gamma_q(T1 a, T2 z) +{ + return gamma_q(a, z, policies::policy<>()); +} +// +// Regularised lower incomplete gamma: +// +template <class T1, class T2, class Policy> +inline typename tools::promote_args<T1, T2>::type + gamma_p(T1 a, T2 z, const Policy&) +{ + BOOST_FPU_EXCEPTION_GUARD + typedef typename tools::promote_args<T1, T2>::type result_type; + typedef typename policies::evaluation<result_type, Policy>::type value_type; + typedef typename lanczos::lanczos<value_type, Policy>::type evaluation_type; + typedef typename policies::normalise< + Policy, + policies::promote_float<false>, + policies::promote_double<false>, + policies::discrete_quantile<>, + policies::assert_undefined<> >::type forwarding_policy; + + return policies::checked_narrowing_cast<result_type, forwarding_policy>( + detail::gamma_incomplete_imp(static_cast<value_type>(a), + static_cast<value_type>(z), true, false, + forwarding_policy(), static_cast<value_type*>(0)), "gamma_p<%1%>(%1%, %1%)"); +} +template <class T1, class T2> +inline typename tools::promote_args<T1, T2>::type + gamma_p(T1 a, T2 z) +{ + return gamma_p(a, z, policies::policy<>()); +} + +// ratios of gamma functions: +template <class T1, class T2, class Policy> +inline typename tools::promote_args<T1, T2>::type + tgamma_delta_ratio(T1 z, T2 delta, const Policy& /* pol */) +{ + BOOST_FPU_EXCEPTION_GUARD + typedef typename tools::promote_args<T1, T2>::type result_type; + typedef typename policies::evaluation<result_type, Policy>::type value_type; + typedef typename policies::normalise< + Policy, + policies::promote_float<false>, + policies::promote_double<false>, + policies::discrete_quantile<>, + policies::assert_undefined<> >::type forwarding_policy; + + return policies::checked_narrowing_cast<result_type, forwarding_policy>(detail::tgamma_delta_ratio_imp(static_cast<value_type>(z), static_cast<value_type>(delta), forwarding_policy()), "boost::math::tgamma_delta_ratio<%1%>(%1%, %1%)"); +} +template <class T1, class T2> +inline typename tools::promote_args<T1, T2>::type + tgamma_delta_ratio(T1 z, T2 delta) +{ + return tgamma_delta_ratio(z, delta, policies::policy<>()); +} +template <class T1, class T2, class Policy> +inline typename tools::promote_args<T1, T2>::type + tgamma_ratio(T1 a, T2 b, const Policy&) +{ + typedef typename tools::promote_args<T1, T2>::type result_type; + typedef typename policies::evaluation<result_type, Policy>::type value_type; + typedef typename policies::normalise< + Policy, + policies::promote_float<false>, + policies::promote_double<false>, + policies::discrete_quantile<>, + policies::assert_undefined<> >::type forwarding_policy; + + return policies::checked_narrowing_cast<result_type, forwarding_policy>(detail::tgamma_delta_ratio_imp(static_cast<value_type>(a), static_cast<value_type>(static_cast<value_type>(b) - static_cast<value_type>(a)), forwarding_policy()), "boost::math::tgamma_delta_ratio<%1%>(%1%, %1%)"); +} +template <class T1, class T2> +inline typename tools::promote_args<T1, T2>::type + tgamma_ratio(T1 a, T2 b) +{ + return tgamma_ratio(a, b, policies::policy<>()); +} + +template <class T1, class T2, class Policy> +inline typename tools::promote_args<T1, T2>::type + gamma_p_derivative(T1 a, T2 x, const Policy&) +{ + BOOST_FPU_EXCEPTION_GUARD + typedef typename tools::promote_args<T1, T2>::type result_type; + typedef typename policies::evaluation<result_type, Policy>::type value_type; + typedef typename policies::normalise< + Policy, + policies::promote_float<false>, + policies::promote_double<false>, + policies::discrete_quantile<>, + policies::assert_undefined<> >::type forwarding_policy; + + return policies::checked_narrowing_cast<result_type, forwarding_policy>(detail::gamma_p_derivative_imp(static_cast<value_type>(a), static_cast<value_type>(x), forwarding_policy()), "boost::math::gamma_p_derivative<%1%>(%1%, %1%)"); +} +template <class T1, class T2> +inline typename tools::promote_args<T1, T2>::type + gamma_p_derivative(T1 a, T2 x) +{ + return gamma_p_derivative(a, x, policies::policy<>()); +} + +} // namespace math +} // namespace boost + +#ifdef BOOST_MSVC +# pragma warning(pop) +#endif + +#include <boost/math/special_functions/detail/igamma_inverse.hpp> +#include <boost/math/special_functions/detail/gamma_inva.hpp> +#include <boost/math/special_functions/erf.hpp> + +#endif // BOOST_MATH_SF_GAMMA_HPP + + + + diff --git a/Utilities/BGL/boost/math/special_functions/hermite.hpp b/Utilities/BGL/boost/math/special_functions/hermite.hpp new file mode 100644 index 0000000000000000000000000000000000000000..1bdc133b3b1e668e2b4d4429e42b9ef50b26a971 --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/hermite.hpp @@ -0,0 +1,76 @@ + +// (C) Copyright John Maddock 2006. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_SPECIAL_HERMITE_HPP +#define BOOST_MATH_SPECIAL_HERMITE_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/math/special_functions/math_fwd.hpp> +#include <boost/math/tools/config.hpp> +#include <boost/math/policies/error_handling.hpp> + +namespace boost{ +namespace math{ + +// Recurrance relation for Hermite polynomials: +template <class T1, class T2, class T3> +inline typename tools::promote_args<T1, T2, T3>::type + hermite_next(unsigned n, T1 x, T2 Hn, T3 Hnm1) +{ + return (2 * x * Hn - 2 * n * Hnm1); +} + +namespace detail{ + +// Implement Hermite polynomials via recurrance: +template <class T> +T hermite_imp(unsigned n, T x) +{ + T p0 = 1; + T p1 = 2 * x; + + if(n == 0) + return p0; + + unsigned c = 1; + + while(c < n) + { + std::swap(p0, p1); + p1 = hermite_next(c, x, p0, p1); + ++c; + } + return p1; +} + +} // namespace detail + +template <class T, class Policy> +inline typename tools::promote_args<T>::type + hermite(unsigned n, T x, const Policy&) +{ + typedef typename tools::promote_args<T>::type result_type; + typedef typename policies::evaluation<result_type, Policy>::type value_type; + return policies::checked_narrowing_cast<result_type, Policy>(detail::hermite_imp(n, static_cast<value_type>(x)), "boost::math::hermite<%1%>(unsigned, %1%)"); +} + +template <class T> +inline typename tools::promote_args<T>::type + hermite(unsigned n, T x) +{ + return boost::math::hermite(n, x, policies::policy<>()); +} + +} // namespace math +} // namespace boost + +#endif // BOOST_MATH_SPECIAL_HERMITE_HPP + + + diff --git a/Utilities/BGL/boost/math/special_functions/hypot.hpp b/Utilities/BGL/boost/math/special_functions/hypot.hpp new file mode 100644 index 0000000000000000000000000000000000000000..30a8bd4e26ab7a43b42d28ed32629bc1cb4f3669 --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/hypot.hpp @@ -0,0 +1,86 @@ +// (C) Copyright John Maddock 2005-2006. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_HYPOT_INCLUDED +#define BOOST_MATH_HYPOT_INCLUDED + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/math/tools/config.hpp> +#include <boost/math/tools/precision.hpp> +#include <boost/math/policies/error_handling.hpp> +#include <boost/math/special_functions/math_fwd.hpp> +#include <boost/config/no_tr1/cmath.hpp> +#include <algorithm> // for swap + +#ifdef BOOST_NO_STDC_NAMESPACE +namespace std{ using ::sqrt; using ::fabs; } +#endif + +namespace boost{ namespace math{ namespace detail{ + +template <class T, class Policy> +T hypot_imp(T x, T y, const Policy& pol) +{ + // + // Normalize x and y, so that both are positive and x >= y: + // + using std::fabs; using std::sqrt; // ADL of std names + + x = fabs(x); + y = fabs(y); + +#ifdef BOOST_MSVC +#pragma warning(push) +#pragma warning(disable: 4127) +#endif + // special case, see C99 Annex F: + if(std::numeric_limits<T>::has_infinity + && ((x == std::numeric_limits<T>::infinity()) + || (y == std::numeric_limits<T>::infinity()))) + return policies::raise_overflow_error<T>("boost::math::hypot<%1%>(%1%,%1%)", 0, pol); +#ifdef BOOST_MSVC +#pragma warning(pop) +#endif + + if(y > x) + (std::swap)(x, y); + + if(x * tools::epsilon<T>() >= y) + return x; + + T rat = y / x; + return x * sqrt(1 + rat*rat); +} // template <class T> T hypot(T x, T y) + +} + +template <class T1, class T2> +inline typename tools::promote_args<T1, T2>::type + hypot(T1 x, T2 y) +{ + typedef typename tools::promote_args<T1, T2>::type result_type; + return detail::hypot_imp( + static_cast<result_type>(x), static_cast<result_type>(y), policies::policy<>()); +} + +template <class T1, class T2, class Policy> +inline typename tools::promote_args<T1, T2>::type + hypot(T1 x, T2 y, const Policy& pol) +{ + typedef typename tools::promote_args<T1, T2>::type result_type; + return detail::hypot_imp( + static_cast<result_type>(x), static_cast<result_type>(y), pol); +} + +} // namespace math +} // namespace boost + +#endif // BOOST_MATH_HYPOT_INCLUDED + + + diff --git a/Utilities/BGL/boost/math/special_functions/laguerre.hpp b/Utilities/BGL/boost/math/special_functions/laguerre.hpp new file mode 100644 index 0000000000000000000000000000000000000000..509fff782f5db359a5d57747f033e6e3493851f1 --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/laguerre.hpp @@ -0,0 +1,139 @@ + +// (C) Copyright John Maddock 2006. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_SPECIAL_LAGUERRE_HPP +#define BOOST_MATH_SPECIAL_LAGUERRE_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/math/special_functions/math_fwd.hpp> +#include <boost/math/tools/config.hpp> +#include <boost/math/policies/error_handling.hpp> + +namespace boost{ +namespace math{ + +// Recurrance relation for Laguerre polynomials: +template <class T1, class T2, class T3> +inline typename tools::promote_args<T1, T2, T3>::type + laguerre_next(unsigned n, T1 x, T2 Ln, T3 Lnm1) +{ + typedef typename tools::promote_args<T1, T2, T3>::type result_type; + return ((2 * n + 1 - result_type(x)) * result_type(Ln) - n * result_type(Lnm1)) / (n + 1); +} + +namespace detail{ + +// Implement Laguerre polynomials via recurrance: +template <class T> +T laguerre_imp(unsigned n, T x) +{ + T p0 = 1; + T p1 = 1 - x; + + if(n == 0) + return p0; + + unsigned c = 1; + + while(c < n) + { + std::swap(p0, p1); + p1 = laguerre_next(c, x, p0, p1); + ++c; + } + return p1; +} + +template <class T, class Policy> +inline typename tools::promote_args<T>::type +laguerre(unsigned n, T x, const Policy&, const mpl::true_&) +{ + typedef typename tools::promote_args<T>::type result_type; + typedef typename policies::evaluation<result_type, Policy>::type value_type; + return policies::checked_narrowing_cast<result_type, Policy>(detail::laguerre_imp(n, static_cast<value_type>(x)), "boost::math::laguerre<%1%>(unsigned, %1%)"); +} + +template <class T> +inline typename tools::promote_args<T>::type + laguerre(unsigned n, unsigned m, T x, const mpl::false_&) +{ + return boost::math::laguerre(n, m, x, policies::policy<>()); +} + +} // namespace detail + +template <class T> +inline typename tools::promote_args<T>::type + laguerre(unsigned n, T x) +{ + return laguerre(n, x, policies::policy<>()); +} + +// Recurrence for associated polynomials: +template <class T1, class T2, class T3> +inline typename tools::promote_args<T1, T2, T3>::type + laguerre_next(unsigned n, unsigned l, T1 x, T2 Pl, T3 Plm1) +{ + typedef typename tools::promote_args<T1, T2, T3>::type result_type; + return ((2 * n + l + 1 - result_type(x)) * result_type(Pl) - (n + l) * result_type(Plm1)) / (n+1); +} + +namespace detail{ +// Laguerre Associated Polynomial: +template <class T, class Policy> +T laguerre_imp(unsigned n, unsigned m, T x, const Policy& pol) +{ + // Special cases: + if(m == 0) + return boost::math::laguerre(n, x, pol); + + T p0 = 1; + + if(n == 0) + return p0; + + T p1 = m + 1 - x; + + unsigned c = 1; + + while(c < n) + { + std::swap(p0, p1); + p1 = laguerre_next(c, m, x, p0, p1); + ++c; + } + return p1; +} + +} + +template <class T, class Policy> +inline typename tools::promote_args<T>::type + laguerre(unsigned n, unsigned m, T x, const Policy& pol) +{ + typedef typename tools::promote_args<T>::type result_type; + typedef typename policies::evaluation<result_type, Policy>::type value_type; + return policies::checked_narrowing_cast<result_type, Policy>(detail::laguerre_imp(n, m, static_cast<value_type>(x), pol), "boost::math::laguerre<%1%>(unsigned, unsigned, %1%)"); +} + +template <class T1, class T2> +inline typename laguerre_result<T1, T2>::type + laguerre(unsigned n, T1 m, T2 x) +{ + typedef typename policies::is_policy<T2>::type tag_type; + return detail::laguerre(n, m, x, tag_type()); +} + +} // namespace math +} // namespace boost + +#endif // BOOST_MATH_SPECIAL_LAGUERRE_HPP + + + diff --git a/Utilities/BGL/boost/math/special_functions/lanczos.hpp b/Utilities/BGL/boost/math/special_functions/lanczos.hpp new file mode 100644 index 0000000000000000000000000000000000000000..bafac6894dd6617297318c341cc48fe9a21cc06f --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/lanczos.hpp @@ -0,0 +1,1240 @@ +// (C) Copyright John Maddock 2006. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_SPECIAL_FUNCTIONS_LANCZOS +#define BOOST_MATH_SPECIAL_FUNCTIONS_LANCZOS + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/config.hpp> +#include <boost/mpl/if.hpp> +#include <boost/limits.hpp> +#include <boost/cstdint.hpp> +#include <boost/math/tools/rational.hpp> +#include <boost/math/policies/policy.hpp> +#include <boost/mpl/less_equal.hpp> + +#include <limits.h> + +namespace boost{ namespace math{ namespace lanczos{ + +// +// Individual lanczos approximations start here. +// +// Optimal values for G for each N are taken from +// http://web.mala.bc.ca/pughg/phdThesis/phdThesis.pdf, +// as are the theoretical error bounds. +// +// Constants calculated using the method described by Godfrey +// http://my.fit.edu/~gabdo/gamma.txt and elaborated by Toth at +// http://www.rskey.org/gamma.htm using NTL::RR at 1000 bit precision. +// +// Lanczos Coefficients for N=6 G=5.581 +// Max experimental error (with arbitary precision arithmetic) 9.516e-12 +// Generated with compiler: Microsoft Visual C++ version 8.0 on Win32 at Mar 23 2006 +// +struct lanczos6 : public mpl::int_<35> +{ + // + // Produces slightly better than float precision when evaluated at + // double precision: + // + template <class T> + static T lanczos_sum(const T& z) + { + static const T num[6] = { + static_cast<T>(8706.349592549009182288174442774377925882L), + static_cast<T>(8523.650341121874633477483696775067709735L), + static_cast<T>(3338.029219476423550899999750161289306564L), + static_cast<T>(653.6424994294008795995653541449610986791L), + static_cast<T>(63.99951844938187085666201263218840287667L), + static_cast<T>(2.506628274631006311133031631822390264407L) + }; + static const BOOST_MATH_INT_TABLE_TYPE(T, boost::uint16_t) denom[6] = { + static_cast<boost::uint16_t>(0u), + static_cast<boost::uint16_t>(24u), + static_cast<boost::uint16_t>(50u), + static_cast<boost::uint16_t>(35u), + static_cast<boost::uint16_t>(10u), + static_cast<boost::uint16_t>(1u) + }; + return boost::math::tools::evaluate_rational(num, denom, z); + } + + template <class T> + static T lanczos_sum_expG_scaled(const T& z) + { + static const T num[6] = { + static_cast<T>(32.81244541029783471623665933780748627823L), + static_cast<T>(32.12388941444332003446077108933558534361L), + static_cast<T>(12.58034729455216106950851080138931470954L), + static_cast<T>(2.463444478353241423633780693218408889251L), + static_cast<T>(0.2412010548258800231126240760264822486599L), + static_cast<T>(0.009446967704539249494420221613134244048319L) + }; + static const BOOST_MATH_INT_TABLE_TYPE(T, boost::uint16_t) denom[6] = { + static_cast<boost::uint16_t>(0u), + static_cast<boost::uint16_t>(24u), + static_cast<boost::uint16_t>(50u), + static_cast<boost::uint16_t>(35u), + static_cast<boost::uint16_t>(10u), + static_cast<boost::uint16_t>(1u) + }; + return boost::math::tools::evaluate_rational(num, denom, z); + } + + + template<class T> + static T lanczos_sum_near_1(const T& dz) + { + static const T d[5] = { + static_cast<T>(2.044879010930422922760429926121241330235L), + static_cast<T>(-2.751366405578505366591317846728753993668L), + static_cast<T>(1.02282965224225004296750609604264824677L), + static_cast<T>(-0.09786124911582813985028889636665335893627L), + static_cast<T>(0.0009829742267506615183144364420540766510112L), + }; + T result = 0; + for(unsigned k = 1; k <= sizeof(d)/sizeof(d[0]); ++k) + { + result += (-d[k-1]*dz)/(k*dz + k*k); + } + return result; + } + + template<class T> + static T lanczos_sum_near_2(const T& dz) + { + static const T d[5] = { + static_cast<T>(5.748142489536043490764289256167080091892L), + static_cast<T>(-7.734074268282457156081021756682138251825L), + static_cast<T>(2.875167944990511006997713242805893543947L), + static_cast<T>(-0.2750873773533504542306766137703788781776L), + static_cast<T>(0.002763134585812698552178368447708846850353L), + }; + T result = 0; + T z = dz + 2; + for(unsigned k = 1; k <= sizeof(d)/sizeof(d[0]); ++k) + { + result += (-d[k-1]*dz)/(z + k*z + k*k - 1); + } + return result; + } + + static double g(){ return 5.581000000000000405009359383257105946541; } +}; + +// +// Lanczos Coefficients for N=11 G=10.900511 +// Max experimental error (with arbitary precision arithmetic) 2.16676e-19 +// Generated with compiler: Microsoft Visual C++ version 8.0 on Win32 at Mar 23 2006 +// +struct lanczos11 : public mpl::int_<60> +{ + // + // Produces slightly better than double precision when evaluated at + // extended-double precision: + // + template <class T> + static T lanczos_sum(const T& z) + { + static const T num[11] = { + static_cast<T>(38474670393.31776828316099004518914832218L), + static_cast<T>(36857665043.51950660081971227404959150474L), + static_cast<T>(15889202453.72942008945006665994637853242L), + static_cast<T>(4059208354.298834770194507810788393801607L), + static_cast<T>(680547661.1834733286087695557084801366446L), + static_cast<T>(78239755.00312005289816041245285376206263L), + static_cast<T>(6246580.776401795264013335510453568106366L), + static_cast<T>(341986.3488721347032223777872763188768288L), + static_cast<T>(12287.19451182455120096222044424100527629L), + static_cast<T>(261.6140441641668190791708576058805625502L), + static_cast<T>(2.506628274631000502415573855452633787834L) + }; + static const BOOST_MATH_INT_TABLE_TYPE(T, boost::uint32_t) denom[11] = { + static_cast<boost::uint32_t>(0u), + static_cast<boost::uint32_t>(362880u), + static_cast<boost::uint32_t>(1026576u), + static_cast<boost::uint32_t>(1172700u), + static_cast<boost::uint32_t>(723680u), + static_cast<boost::uint32_t>(269325u), + static_cast<boost::uint32_t>(63273u), + static_cast<boost::uint32_t>(9450u), + static_cast<boost::uint32_t>(870u), + static_cast<boost::uint32_t>(45u), + static_cast<boost::uint32_t>(1u) + }; + return boost::math::tools::evaluate_rational(num, denom, z); + } + + template <class T> + static T lanczos_sum_expG_scaled(const T& z) + { + static const T num[11] = { + static_cast<T>(709811.662581657956893540610814842699825L), + static_cast<T>(679979.847415722640161734319823103390728L), + static_cast<T>(293136.785721159725251629480984140341656L), + static_cast<T>(74887.5403291467179935942448101441897121L), + static_cast<T>(12555.29058241386295096255111537516768137L), + static_cast<T>(1443.42992444170669746078056942194198252L), + static_cast<T>(115.2419459613734722083208906727972935065L), + static_cast<T>(6.30923920573262762719523981992008976989L), + static_cast<T>(0.2266840463022436475495508977579735223818L), + static_cast<T>(0.004826466289237661857584712046231435101741L), + static_cast<T>(0.4624429436045378766270459638520555557321e-4L) + }; + static const BOOST_MATH_INT_TABLE_TYPE(T, boost::uint32_t) denom[11] = { + static_cast<boost::uint32_t>(0u), + static_cast<boost::uint32_t>(362880u), + static_cast<boost::uint32_t>(1026576u), + static_cast<boost::uint32_t>(1172700u), + static_cast<boost::uint32_t>(723680u), + static_cast<boost::uint32_t>(269325u), + static_cast<boost::uint32_t>(63273u), + static_cast<boost::uint32_t>(9450u), + static_cast<boost::uint32_t>(870u), + static_cast<boost::uint32_t>(45u), + static_cast<boost::uint32_t>(1u) + }; + return boost::math::tools::evaluate_rational(num, denom, z); + } + + + template<class T> + static T lanczos_sum_near_1(const T& dz) + { + static const T d[10] = { + static_cast<T>(4.005853070677940377969080796551266387954L), + static_cast<T>(-13.17044315127646469834125159673527183164L), + static_cast<T>(17.19146865350790353683895137079288129318L), + static_cast<T>(-11.36446409067666626185701599196274701126L), + static_cast<T>(4.024801119349323770107694133829772634737L), + static_cast<T>(-0.7445703262078094128346501724255463005006L), + static_cast<T>(0.06513861351917497265045550019547857713172L), + static_cast<T>(-0.00217899958561830354633560009312512312758L), + static_cast<T>(0.17655204574495137651670832229571934738e-4L), + static_cast<T>(-0.1036282091079938047775645941885460820853e-7L), + }; + T result = 0; + for(unsigned k = 1; k <= sizeof(d)/sizeof(d[0]); ++k) + { + result += (-d[k-1]*dz)/(k*dz + k*k); + } + return result; + } + + template<class T> + static T lanczos_sum_near_2(const T& dz) + { + static const T d[10] = { + static_cast<T>(19.05889633808148715159575716844556056056L), + static_cast<T>(-62.66183664701721716960978577959655644762L), + static_cast<T>(81.7929198065004751699057192860287512027L), + static_cast<T>(-54.06941772964234828416072865069196553015L), + static_cast<T>(19.14904664790693019642068229478769661515L), + static_cast<T>(-3.542488556926667589704590409095331790317L), + static_cast<T>(0.3099140334815639910894627700232804503017L), + static_cast<T>(-0.01036716187296241640634252431913030440825L), + static_cast<T>(0.8399926504443119927673843789048514017761e-4L), + static_cast<T>(-0.493038376656195010308610694048822561263e-7L), + }; + T result = 0; + T z = dz + 2; + for(unsigned k = 1; k <= sizeof(d)/sizeof(d[0]); ++k) + { + result += (-d[k-1]*dz)/(z + k*z + k*k - 1); + } + return result; + } + + static double g(){ return 10.90051099999999983936049829935654997826; } +}; + +// +// Lanczos Coefficients for N=13 G=13.144565 +// Max experimental error (with arbitary precision arithmetic) 9.2213e-23 +// Generated with compiler: Microsoft Visual C++ version 8.0 on Win32 at Mar 23 2006 +// +struct lanczos13 : public mpl::int_<72> +{ + // + // Produces slightly better than extended-double precision when evaluated at + // higher precision: + // + template <class T> + static T lanczos_sum(const T& z) + { + static const T num[13] = { + static_cast<T>(44012138428004.60895436261759919070125699L), + static_cast<T>(41590453358593.20051581730723108131357995L), + static_cast<T>(18013842787117.99677796276038389462742949L), + static_cast<T>(4728736263475.388896889723995205703970787L), + static_cast<T>(837910083628.4046470415724300225777912264L), + static_cast<T>(105583707273.4299344907359855510105321192L), + static_cast<T>(9701363618.494999493386608345339104922694L), + static_cast<T>(654914397.5482052641016767125048538245644L), + static_cast<T>(32238322.94213356530668889463945849409184L), + static_cast<T>(1128514.219497091438040721811544858643121L), + static_cast<T>(26665.79378459858944762533958798805525125L), + static_cast<T>(381.8801248632926870394389468349331394196L), + static_cast<T>(2.506628274631000502415763426076722427007L) + }; + static const BOOST_MATH_INT_TABLE_TYPE(T, boost::uint32_t) denom[13] = { + static_cast<boost::uint32_t>(0u), + static_cast<boost::uint32_t>(39916800u), + static_cast<boost::uint32_t>(120543840u), + static_cast<boost::uint32_t>(150917976u), + static_cast<boost::uint32_t>(105258076u), + static_cast<boost::uint32_t>(45995730u), + static_cast<boost::uint32_t>(13339535u), + static_cast<boost::uint32_t>(2637558u), + static_cast<boost::uint32_t>(357423u), + static_cast<boost::uint32_t>(32670u), + static_cast<boost::uint32_t>(1925u), + static_cast<boost::uint32_t>(66u), + static_cast<boost::uint32_t>(1u) + }; + return boost::math::tools::evaluate_rational(num, denom, z); + } + + template <class T> + static T lanczos_sum_expG_scaled(const T& z) + { + static const T num[13] = { + static_cast<T>(86091529.53418537217994842267760536134841L), + static_cast<T>(81354505.17858011242874285785316135398567L), + static_cast<T>(35236626.38815461910817650960734605416521L), + static_cast<T>(9249814.988024471294683815872977672237195L), + static_cast<T>(1639024.216687146960253839656643518985826L), + static_cast<T>(206530.8157641225032631778026076868855623L), + static_cast<T>(18976.70193530288915698282139308582105936L), + static_cast<T>(1281.068909912559479885759622791374106059L), + static_cast<T>(63.06093343420234536146194868906771599354L), + static_cast<T>(2.207470909792527638222674678171050209691L), + static_cast<T>(0.05216058694613505427476207805814960742102L), + static_cast<T>(0.0007469903808915448316510079585999893674101L), + static_cast<T>(0.4903180573459871862552197089738373164184e-5L) + }; + static const BOOST_MATH_INT_TABLE_TYPE(T, boost::uint32_t) denom[13] = { + static_cast<boost::uint32_t>(0u), + static_cast<boost::uint32_t>(39916800u), + static_cast<boost::uint32_t>(120543840u), + static_cast<boost::uint32_t>(150917976u), + static_cast<boost::uint32_t>(105258076u), + static_cast<boost::uint32_t>(45995730u), + static_cast<boost::uint32_t>(13339535u), + static_cast<boost::uint32_t>(2637558u), + static_cast<boost::uint32_t>(357423u), + static_cast<boost::uint32_t>(32670u), + static_cast<boost::uint32_t>(1925u), + static_cast<boost::uint32_t>(66u), + static_cast<boost::uint32_t>(1u) + }; + return boost::math::tools::evaluate_rational(num, denom, z); + } + + + template<class T> + static T lanczos_sum_near_1(const T& dz) + { + static const T d[12] = { + static_cast<T>(4.832115561461656947793029596285626840312L), + static_cast<T>(-19.86441536140337740383120735104359034688L), + static_cast<T>(33.9927422807443239927197864963170585331L), + static_cast<T>(-31.41520692249765980987427413991250886138L), + static_cast<T>(17.0270866009599345679868972409543597821L), + static_cast<T>(-5.5077216950865501362506920516723682167L), + static_cast<T>(1.037811741948214855286817963800439373362L), + static_cast<T>(-0.106640468537356182313660880481398642811L), + static_cast<T>(0.005276450526660653288757565778182586742831L), + static_cast<T>(-0.0001000935625597121545867453746252064770029L), + static_cast<T>(0.462590910138598083940803704521211569234e-6L), + static_cast<T>(-0.1735307814426389420248044907765671743012e-9L), + }; + T result = 0; + for(unsigned k = 1; k <= sizeof(d)/sizeof(d[0]); ++k) + { + result += (-d[k-1]*dz)/(k*dz + k*k); + } + return result; + } + + template<class T> + static T lanczos_sum_near_2(const T& dz) + { + static const T d[12] = { + static_cast<T>(26.96979819614830698367887026728396466395L), + static_cast<T>(-110.8705424709385114023884328797900204863L), + static_cast<T>(189.7258846119231466417015694690434770085L), + static_cast<T>(-175.3397202971107486383321670769397356553L), + static_cast<T>(95.03437648691551457087250340903980824948L), + static_cast<T>(-30.7406022781665264273675797983497141978L), + static_cast<T>(5.792405601630517993355102578874590410552L), + static_cast<T>(-0.5951993240669148697377539518639997795831L), + static_cast<T>(0.02944979359164017509944724739946255067671L), + static_cast<T>(-0.0005586586555377030921194246330399163602684L), + static_cast<T>(0.2581888478270733025288922038673392636029e-5L), + static_cast<T>(-0.9685385411006641478305219367315965391289e-9L), + }; + T result = 0; + T z = z = 2; + for(unsigned k = 1; k <= sizeof(d)/sizeof(d[0]); ++k) + { + result += (-d[k-1]*dz)/(z + k*z + k*k - 1); + } + return result; + } + + static double g(){ return 13.1445650000000000545696821063756942749; } +}; + +// +// Lanczos Coefficients for N=22 G=22.61891 +// Max experimental error (with arbitary precision arithmetic) 2.9524e-38 +// Generated with compiler: Microsoft Visual C++ version 8.0 on Win32 at Mar 23 2006 +// +struct lanczos22 : public mpl::int_<120> +{ + // + // Produces slightly better than 128-bit long-double precision when + // evaluated at higher precision: + // + template <class T> + static T lanczos_sum(const T& z) + { + static const T num[22] = { + static_cast<T>(46198410803245094237463011094.12173081986L), + static_cast<T>(43735859291852324413622037436.321513777L), + static_cast<T>(19716607234435171720534556386.97481377748L), + static_cast<T>(5629401471315018442177955161.245623932129L), + static_cast<T>(1142024910634417138386281569.245580222392L), + static_cast<T>(175048529315951173131586747.695329230778L), + static_cast<T>(21044290245653709191654675.41581372963167L), + static_cast<T>(2033001410561031998451380.335553678782601L), + static_cast<T>(160394318862140953773928.8736211601848891L), + static_cast<T>(10444944438396359705707.48957290388740896L), + static_cast<T>(565075825801617290121.1466393747967538948L), + static_cast<T>(25475874292116227538.99448534450411942597L), + static_cast<T>(957135055846602154.6720835535232270205725L), + static_cast<T>(29874506304047462.23662392445173880821515L), + static_cast<T>(769651310384737.2749087590725764959689181L), + static_cast<T>(16193289100889.15989633624378404096011797L), + static_cast<T>(273781151680.6807433264462376754578933261L), + static_cast<T>(3630485900.32917021712188739762161583295L), + static_cast<T>(36374352.05577334277856865691538582936484L), + static_cast<T>(258945.7742115532455441786924971194951043L), + static_cast<T>(1167.501919472435718934219997431551246996L), + static_cast<T>(2.50662827463100050241576528481104525333L) + }; + static const BOOST_MATH_INT_TABLE_TYPE(T, boost::uint64_t) denom[22] = { + BOOST_MATH_INT_VALUE_SUFFIX(0, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(2432902008176640000, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(8752948036761600000, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(13803759753640704000, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(12870931245150988800, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(8037811822645051776, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(3599979517947607200, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(1206647803780373360, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(311333643161390640, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(63030812099294896, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(10142299865511450, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(1307535010540395, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(135585182899530, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(11310276995381, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(756111184500, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(40171771630, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(1672280820, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(53327946, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(1256850, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(20615, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(210, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(1, uLL) + }; + return boost::math::tools::evaluate_rational(num, denom, z); + } + + template <class T> + static T lanczos_sum_expG_scaled(const T& z) + { + static const T num[22] = { + static_cast<T>(6939996264376682180.277485395074954356211L), + static_cast<T>(6570067992110214451.87201438870245659384L), + static_cast<T>(2961859037444440551.986724631496417064121L), + static_cast<T>(845657339772791245.3541226499766163431651L), + static_cast<T>(171556737035449095.2475716923888737881837L), + static_cast<T>(26296059072490867.7822441885603400926007L), + static_cast<T>(3161305619652108.433798300149816829198706L), + static_cast<T>(305400596026022.4774396904484542582526472L), + static_cast<T>(24094681058862.55120507202622377623528108L), + static_cast<T>(1569055604375.919477574824168939428328839L), + static_cast<T>(84886558909.02047889339710230696942513159L), + static_cast<T>(3827024985.166751989686050643579753162298L), + static_cast<T>(143782298.9273215199098728674282885500522L), + static_cast<T>(4487794.24541641841336786238909171265944L), + static_cast<T>(115618.2025760830513505888216285273541959L), + static_cast<T>(2432.580773108508276957461757328744780439L), + static_cast<T>(41.12782532742893597168530008461874360191L), + static_cast<T>(0.5453771709477689805460179187388702295792L), + static_cast<T>(0.005464211062612080347167337964166505282809L), + static_cast<T>(0.388992321263586767037090706042788910953e-4L), + static_cast<T>(0.1753839324538447655939518484052327068859e-6L), + static_cast<T>(0.3765495513732730583386223384116545391759e-9L) + }; + static const BOOST_MATH_INT_TABLE_TYPE(T, boost::uint64_t) denom[22] = { + BOOST_MATH_INT_VALUE_SUFFIX(0, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(2432902008176640000, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(8752948036761600000, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(13803759753640704000, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(12870931245150988800, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(8037811822645051776, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(3599979517947607200, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(1206647803780373360, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(311333643161390640, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(63030812099294896, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(10142299865511450, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(1307535010540395, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(135585182899530, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(11310276995381, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(756111184500, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(40171771630, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(1672280820, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(53327946, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(1256850, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(20615, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(210, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(1, uLL) + }; + return boost::math::tools::evaluate_rational(num, denom, z); + } + + + template<class T> + static T lanczos_sum_near_1(const T& dz) + { + static const T d[21] = { + static_cast<T>(8.318998691953337183034781139546384476554L), + static_cast<T>(-63.15415991415959158214140353299240638675L), + static_cast<T>(217.3108224383632868591462242669081540163L), + static_cast<T>(-448.5134281386108366899784093610397354889L), + static_cast<T>(619.2903759363285456927248474593012711346L), + static_cast<T>(-604.1630177420625418522025080080444177046L), + static_cast<T>(428.8166750424646119935047118287362193314L), + static_cast<T>(-224.6988753721310913866347429589434550302L), + static_cast<T>(87.32181627555510833499451817622786940961L), + static_cast<T>(-25.07866854821128965662498003029199058098L), + static_cast<T>(5.264398125689025351448861011657789005392L), + static_cast<T>(-0.792518936256495243383586076579921559914L), + static_cast<T>(0.08317448364744713773350272460937904691566L), + static_cast<T>(-0.005845345166274053157781068150827567998882L), + static_cast<T>(0.0002599412126352082483326238522490030412391L), + static_cast<T>(-0.6748102079670763884917431338234783496303e-5L), + static_cast<T>(0.908824383434109002762325095643458603605e-7L), + static_cast<T>(-0.5299325929309389890892469299969669579725e-9L), + static_cast<T>(0.994306085859549890267983602248532869362e-12L), + static_cast<T>(-0.3499893692975262747371544905820891835298e-15L), + static_cast<T>(0.7260746353663365145454867069182884694961e-20L), + }; + T result = 0; + for(unsigned k = 1; k <= sizeof(d)/sizeof(d[0]); ++k) + { + result += (-d[k-1]*dz)/(k*dz + k*k); + } + return result; + } + + template<class T> + static T lanczos_sum_near_2(const T& dz) + { + static const T d[21] = { + static_cast<T>(75.39272007105208086018421070699575462226L), + static_cast<T>(-572.3481967049935412452681346759966390319L), + static_cast<T>(1969.426202741555335078065370698955484358L), + static_cast<T>(-4064.74968778032030891520063865996757519L), + static_cast<T>(5612.452614138013929794736248384309574814L), + static_cast<T>(-5475.357667500026172903620177988213902339L), + static_cast<T>(3886.243614216111328329547926490398103492L), + static_cast<T>(-2036.382026072125407192448069428134470564L), + static_cast<T>(791.3727954936062108045551843636692287652L), + static_cast<T>(-227.2808432388436552794021219198885223122L), + static_cast<T>(47.70974355562144229897637024320739257284L), + static_cast<T>(-7.182373807798293545187073539819697141572L), + static_cast<T>(0.7537866989631514559601547530490976100468L), + static_cast<T>(-0.05297470142240154822658739758236594717787L), + static_cast<T>(0.00235577330936380542539812701472320434133L), + static_cast<T>(-0.6115613067659273118098229498679502138802e-4L), + static_cast<T>(0.8236417010170941915758315020695551724181e-6L), + static_cast<T>(-0.4802628430993048190311242611330072198089e-8L), + static_cast<T>(0.9011113376981524418952720279739624707342e-11L), + static_cast<T>(-0.3171854152689711198382455703658589996796e-14L), + static_cast<T>(0.6580207998808093935798753964580596673177e-19L), + }; + T result = 0; + T z = dz + 2; + for(unsigned k = 1; k <= sizeof(d)/sizeof(d[0]); ++k) + { + result += (-d[k-1]*dz)/(z + k*z + k*k - 1); + } + return result; + } + + static double g(){ return 22.61890999999999962710717227309942245483; } +}; + +// +// Lanczos Coefficients for N=6 G=1.428456135094165802001953125 +// Max experimental error (with arbitary precision arithmetic) 8.111667e-8 +// Generated with compiler: Microsoft Visual C++ version 8.0 on Win32 at Mar 23 2006 +// +struct lanczos6m24 : public mpl::int_<24> +{ + // + // Use for float precision, when evaluated as a float: + // + template <class T> + static T lanczos_sum(const T& z) + { + static const T num[6] = { + static_cast<T>(58.52061591769095910314047740215847630266L), + static_cast<T>(182.5248962595894264831189414768236280862L), + static_cast<T>(211.0971093028510041839168287718170827259L), + static_cast<T>(112.2526547883668146736465390902227161763L), + static_cast<T>(27.5192015197455403062503721613097825345L), + static_cast<T>(2.50662858515256974113978724717473206342L) + }; + static const BOOST_MATH_INT_TABLE_TYPE(T, boost::uint16_t) denom[6] = { + static_cast<boost::uint16_t>(0u), + static_cast<boost::uint16_t>(24u), + static_cast<boost::uint16_t>(50u), + static_cast<boost::uint16_t>(35u), + static_cast<boost::uint16_t>(10u), + static_cast<boost::uint16_t>(1u) + }; + return boost::math::tools::evaluate_rational(num, denom, z); + } + + template <class T> + static T lanczos_sum_expG_scaled(const T& z) + { + static const T num[6] = { + static_cast<T>(14.0261432874996476619570577285003839357L), + static_cast<T>(43.74732405540314316089531289293124360129L), + static_cast<T>(50.59547402616588964511581430025589038612L), + static_cast<T>(26.90456680562548195593733429204228910299L), + static_cast<T>(6.595765571169314946316366571954421695196L), + static_cast<T>(0.6007854010515290065101128585795542383721L) + }; + static const BOOST_MATH_INT_TABLE_TYPE(T, boost::uint16_t) denom[6] = { + static_cast<boost::uint16_t>(0u), + static_cast<boost::uint16_t>(24u), + static_cast<boost::uint16_t>(50u), + static_cast<boost::uint16_t>(35u), + static_cast<boost::uint16_t>(10u), + static_cast<boost::uint16_t>(1u) + }; + return boost::math::tools::evaluate_rational(num, denom, z); + } + + + template<class T> + static T lanczos_sum_near_1(const T& dz) + { + static const T d[5] = { + static_cast<T>(0.4922488055204602807654354732674868442106L), + static_cast<T>(0.004954497451132152436631238060933905650346L), + static_cast<T>(-0.003374784572167105840686977985330859371848L), + static_cast<T>(0.001924276018962061937026396537786414831385L), + static_cast<T>(-0.00056533046336427583708166383712907694434L), + }; + T result = 0; + for(unsigned k = 1; k <= sizeof(d)/sizeof(d[0]); ++k) + { + result += (-d[k-1]*dz)/(k*dz + k*k); + } + return result; + } + + template<class T> + static T lanczos_sum_near_2(const T& dz) + { + static const T d[5] = { + static_cast<T>(0.6534966888520080645505805298901130485464L), + static_cast<T>(0.006577461728560758362509168026049182707101L), + static_cast<T>(-0.004480276069269967207178373559014835978161L), + static_cast<T>(0.00255461870648818292376982818026706528842L), + static_cast<T>(-0.000750517993690428370380996157470900204524L), + }; + T result = 0; + T z = dz + 2; + for(unsigned k = 1; k <= sizeof(d)/sizeof(d[0]); ++k) + { + result += (-d[k-1]*dz)/(z + k*z + k*k - 1); + } + return result; + } + + static double g(){ return 1.428456135094165802001953125; } +}; + +// +// Lanczos Coefficients for N=13 G=6.024680040776729583740234375 +// Max experimental error (with arbitary precision arithmetic) 1.196214e-17 +// Generated with compiler: Microsoft Visual C++ version 8.0 on Win32 at Mar 23 2006 +// +struct lanczos13m53 : public mpl::int_<53> +{ + // + // Use for double precision, when evaluated as a double: + // + template <class T> + static T lanczos_sum(const T& z) + { + static const T num[13] = { + static_cast<T>(23531376880.41075968857200767445163675473L), + static_cast<T>(42919803642.64909876895789904700198885093L), + static_cast<T>(35711959237.35566804944018545154716670596L), + static_cast<T>(17921034426.03720969991975575445893111267L), + static_cast<T>(6039542586.35202800506429164430729792107L), + static_cast<T>(1439720407.311721673663223072794912393972L), + static_cast<T>(248874557.8620541565114603864132294232163L), + static_cast<T>(31426415.58540019438061423162831820536287L), + static_cast<T>(2876370.628935372441225409051620849613599L), + static_cast<T>(186056.2653952234950402949897160456992822L), + static_cast<T>(8071.672002365816210638002902272250613822L), + static_cast<T>(210.8242777515793458725097339207133627117L), + static_cast<T>(2.506628274631000270164908177133837338626L) + }; + static const BOOST_MATH_INT_TABLE_TYPE(T, boost::uint32_t) denom[13] = { + static_cast<boost::uint32_t>(0u), + static_cast<boost::uint32_t>(39916800u), + static_cast<boost::uint32_t>(120543840u), + static_cast<boost::uint32_t>(150917976u), + static_cast<boost::uint32_t>(105258076u), + static_cast<boost::uint32_t>(45995730u), + static_cast<boost::uint32_t>(13339535u), + static_cast<boost::uint32_t>(2637558u), + static_cast<boost::uint32_t>(357423u), + static_cast<boost::uint32_t>(32670u), + static_cast<boost::uint32_t>(1925u), + static_cast<boost::uint32_t>(66u), + static_cast<boost::uint32_t>(1u) + }; + return boost::math::tools::evaluate_rational(num, denom, z); + } + + template <class T> + static T lanczos_sum_expG_scaled(const T& z) + { + static const T num[13] = { + static_cast<T>(56906521.91347156388090791033559122686859L), + static_cast<T>(103794043.1163445451906271053616070238554L), + static_cast<T>(86363131.28813859145546927288977868422342L), + static_cast<T>(43338889.32467613834773723740590533316085L), + static_cast<T>(14605578.08768506808414169982791359218571L), + static_cast<T>(3481712.15498064590882071018964774556468L), + static_cast<T>(601859.6171681098786670226533699352302507L), + static_cast<T>(75999.29304014542649875303443598909137092L), + static_cast<T>(6955.999602515376140356310115515198987526L), + static_cast<T>(449.9445569063168119446858607650988409623L), + static_cast<T>(19.51992788247617482847860966235652136208L), + static_cast<T>(0.5098416655656676188125178644804694509993L), + static_cast<T>(0.006061842346248906525783753964555936883222L) + }; + static const BOOST_MATH_INT_TABLE_TYPE(T, boost::uint32_t) denom[13] = { + static_cast<boost::uint32_t>(0u), + static_cast<boost::uint32_t>(39916800u), + static_cast<boost::uint32_t>(120543840u), + static_cast<boost::uint32_t>(150917976u), + static_cast<boost::uint32_t>(105258076u), + static_cast<boost::uint32_t>(45995730u), + static_cast<boost::uint32_t>(13339535u), + static_cast<boost::uint32_t>(2637558u), + static_cast<boost::uint32_t>(357423u), + static_cast<boost::uint32_t>(32670u), + static_cast<boost::uint32_t>(1925u), + static_cast<boost::uint32_t>(66u), + static_cast<boost::uint32_t>(1u) + }; + return boost::math::tools::evaluate_rational(num, denom, z); + } + + + template<class T> + static T lanczos_sum_near_1(const T& dz) + { + static const T d[12] = { + static_cast<T>(2.208709979316623790862569924861841433016L), + static_cast<T>(-3.327150580651624233553677113928873034916L), + static_cast<T>(1.483082862367253753040442933770164111678L), + static_cast<T>(-0.1993758927614728757314233026257810172008L), + static_cast<T>(0.004785200610085071473880915854204301886437L), + static_cast<T>(-0.1515973019871092388943437623825208095123e-5L), + static_cast<T>(-0.2752907702903126466004207345038327818713e-7L), + static_cast<T>(0.3075580174791348492737947340039992829546e-7L), + static_cast<T>(-0.1933117898880828348692541394841204288047e-7L), + static_cast<T>(0.8690926181038057039526127422002498960172e-8L), + static_cast<T>(-0.2499505151487868335680273909354071938387e-8L), + static_cast<T>(0.3394643171893132535170101292240837927725e-9L), + }; + T result = 0; + for(unsigned k = 1; k <= sizeof(d)/sizeof(d[0]); ++k) + { + result += (-d[k-1]*dz)/(k*dz + k*k); + } + return result; + } + + template<class T> + static T lanczos_sum_near_2(const T& dz) + { + static const T d[12] = { + static_cast<T>(6.565936202082889535528455955485877361223L), + static_cast<T>(-9.8907772644920670589288081640128194231L), + static_cast<T>(4.408830289125943377923077727900630927902L), + static_cast<T>(-0.5926941084905061794445733628891024027949L), + static_cast<T>(0.01422519127192419234315002746252160965831L), + static_cast<T>(-0.4506604409707170077136555010018549819192e-5L), + static_cast<T>(-0.8183698410724358930823737982119474130069e-7L), + static_cast<T>(0.9142922068165324132060550591210267992072e-7L), + static_cast<T>(-0.5746670642147041587497159649318454348117e-7L), + static_cast<T>(0.2583592566524439230844378948704262291927e-7L), + static_cast<T>(-0.7430396708998719707642735577238449585822e-8L), + static_cast<T>(0.1009141566987569892221439918230042368112e-8L), + }; + T result = 0; + T z = dz + 2; + for(unsigned k = 1; k <= sizeof(d)/sizeof(d[0]); ++k) + { + result += (-d[k-1]*dz)/(z + k*z + k*k - 1); + } + return result; + } + + static double g(){ return 6.024680040776729583740234375; } +}; + +// +// Lanczos Coefficients for N=17 G=12.2252227365970611572265625 +// Max experimental error (with arbitary precision arithmetic) 2.7699e-26 +// Generated with compiler: Microsoft Visual C++ version 8.0 on Win32 at Mar 23 2006 +// +struct lanczos17m64 : public mpl::int_<64> +{ + // + // Use for extended-double precision, when evaluated as an extended-double: + // + template <class T> + static T lanczos_sum(const T& z) + { + static const T num[17] = { + static_cast<T>(553681095419291969.2230556393350368550504L), + static_cast<T>(731918863887667017.2511276782146694632234L), + static_cast<T>(453393234285807339.4627124634539085143364L), + static_cast<T>(174701893724452790.3546219631779712198035L), + static_cast<T>(46866125995234723.82897281620357050883077L), + static_cast<T>(9281280675933215.169109622777099699054272L), + static_cast<T>(1403600894156674.551057997617468721789536L), + static_cast<T>(165345984157572.7305349809894046783973837L), + static_cast<T>(15333629842677.31531822808737907246817024L), + static_cast<T>(1123152927963.956626161137169462874517318L), + static_cast<T>(64763127437.92329018717775593533620578237L), + static_cast<T>(2908830362.657527782848828237106640944457L), + static_cast<T>(99764700.56999856729959383751710026787811L), + static_cast<T>(2525791.604886139959837791244686290089331L), + static_cast<T>(44516.94034970167828580039370201346554872L), + static_cast<T>(488.0063567520005730476791712814838113252L), + static_cast<T>(2.50662827463100050241576877135758834683L) + }; + static const BOOST_MATH_INT_TABLE_TYPE(T, boost::uint64_t) denom[17] = { + BOOST_MATH_INT_VALUE_SUFFIX(0, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(1307674368000, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(4339163001600, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(6165817614720, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(5056995703824, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(2706813345600, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(1009672107080, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(272803210680, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(54631129553, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(8207628000, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(928095740, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(78558480, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(4899622, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(218400, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(6580, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(120, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(1, uLL) + }; + return boost::math::tools::evaluate_rational(num, denom, z); + } + + template <class T> + static T lanczos_sum_expG_scaled(const T& z) + { + static const T num[17] = { + static_cast<T>(2715894658327.717377557655133124376674911L), + static_cast<T>(3590179526097.912105038525528721129550434L), + static_cast<T>(2223966599737.814969312127353235818710172L), + static_cast<T>(856940834518.9562481809925866825485883417L), + static_cast<T>(229885871668.749072933597446453399395469L), + static_cast<T>(45526171687.54610815813502794395753410032L), + static_cast<T>(6884887713.165178784550917647709216424823L), + static_cast<T>(811048596.1407531864760282453852372777439L), + static_cast<T>(75213915.96540822314499613623119501704812L), + static_cast<T>(5509245.417224265151697527957954952830126L), + static_cast<T>(317673.5368435419126714931842182369574221L), + static_cast<T>(14268.27989845035520147014373320337523596L), + static_cast<T>(489.3618720403263670213909083601787814792L), + static_cast<T>(12.38941330038454449295883217865458609584L), + static_cast<T>(0.2183627389504614963941574507281683147897L), + static_cast<T>(0.002393749522058449186690627996063983095463L), + static_cast<T>(0.1229541408909435212800785616808830746135e-4L) + }; + static const BOOST_MATH_INT_TABLE_TYPE(T, boost::uint64_t) denom[17] = { + BOOST_MATH_INT_VALUE_SUFFIX(0, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(1307674368000, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(4339163001600, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(6165817614720, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(5056995703824, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(2706813345600, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(1009672107080, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(272803210680, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(54631129553, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(8207628000, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(928095740, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(78558480, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(4899622, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(218400, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(6580, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(120, uLL), + BOOST_MATH_INT_VALUE_SUFFIX(1, uLL) + }; + return boost::math::tools::evaluate_rational(num, denom, z); + } + + + template<class T> + static T lanczos_sum_near_1(const T& dz) + { + static const T d[16] = { + static_cast<T>(4.493645054286536365763334986866616581265L), + static_cast<T>(-16.95716370392468543800733966378143997694L), + static_cast<T>(26.19196892983737527836811770970479846644L), + static_cast<T>(-21.3659076437988814488356323758179283908L), + static_cast<T>(9.913992596774556590710751047594507535764L), + static_cast<T>(-2.62888300018780199210536267080940382158L), + static_cast<T>(0.3807056693542503606384861890663080735588L), + static_cast<T>(-0.02714647489697685807340312061034730486958L), + static_cast<T>(0.0007815484715461206757220527133967191796747L), + static_cast<T>(-0.6108630817371501052576880554048972272435e-5L), + static_cast<T>(0.5037380238864836824167713635482801545086e-8L), + static_cast<T>(-0.1483232144262638814568926925964858237006e-13L), + static_cast<T>(0.1346609158752142460943888149156716841693e-14L), + static_cast<T>(-0.660492688923978805315914918995410340796e-15L), + static_cast<T>(0.1472114697343266749193617793755763792681e-15L), + static_cast<T>(-0.1410901942033374651613542904678399264447e-16L), + }; + T result = 0; + for(unsigned k = 1; k <= sizeof(d)/sizeof(d[0]); ++k) + { + result += (-d[k-1]*dz)/(k*dz + k*k); + } + return result; + } + + template<class T> + static T lanczos_sum_near_2(const T& dz) + { + static const T d[16] = { + static_cast<T>(23.56409085052261327114594781581930373708L), + static_cast<T>(-88.92116338946308797946237246006238652361L), + static_cast<T>(137.3472822086847596961177383569603988797L), + static_cast<T>(-112.0400438263562152489272966461114852861L), + static_cast<T>(51.98768915202973863076166956576777843805L), + static_cast<T>(-13.78552090862799358221343319574970124948L), + static_cast<T>(1.996371068830872830250406773917646121742L), + static_cast<T>(-0.1423525874909934506274738563671862576161L), + static_cast<T>(0.004098338646046865122459664947239111298524L), + static_cast<T>(-0.3203286637326511000882086573060433529094e-4L), + static_cast<T>(0.2641536751640138646146395939004587594407e-7L), + static_cast<T>(-0.7777876663062235617693516558976641009819e-13L), + static_cast<T>(0.7061443477097101636871806229515157914789e-14L), + static_cast<T>(-0.3463537849537988455590834887691613484813e-14L), + static_cast<T>(0.7719578215795234036320348283011129450595e-15L), + static_cast<T>(-0.7398586479708476329563577384044188912075e-16L), + }; + T result = 0; + T z = dz + 2; + for(unsigned k = 1; k <= sizeof(d)/sizeof(d[0]); ++k) + { + result += (-d[k-1]*dz)/(z + k*z + k*k - 1); + } + return result; + } + + static double g(){ return 12.2252227365970611572265625; } +}; + +// +// Lanczos Coefficients for N=24 G=20.3209821879863739013671875 +// Max experimental error (with arbitary precision arithmetic) 1.0541e-38 +// Generated with compiler: Microsoft Visual C++ version 8.0 on Win32 at Mar 23 2006 +// +struct lanczos24m113 : public mpl::int_<113> +{ + // + // Use for long-double precision, when evaluated as an long-double: + // + template <class T> + static T lanczos_sum(const T& z) + { + static const T num[24] = { + static_cast<T>(2029889364934367661624137213253.22102954656825019111612712252027267955023987678816620961507L), + static_cast<T>(2338599599286656537526273232565.2727349714338768161421882478417543004440597874814359063158L), + static_cast<T>(1288527989493833400335117708406.3953711906175960449186720680201425446299360322830739180195L), + static_cast<T>(451779745834728745064649902914.550539158066332484594436145043388809847364393288132164411521L), + static_cast<T>(113141284461097964029239556815.291212318665536114012605167994061291631013303788706545334708L), + static_cast<T>(21533689802794625866812941616.7509064680880468667055339259146063256555368135236149614592432L), + static_cast<T>(3235510315314840089932120340.71494940111731241353655381919722177496659303550321056514776757L), + static_cast<T>(393537392344185475704891959.081297108513472083749083165179784098220158201055270548272414314L), + static_cast<T>(39418265082950435024868801.5005452240816902251477336582325944930252142622315101857742955673L), + static_cast<T>(3290158764187118871697791.05850632319194734270969161036889516414516566453884272345518372696L), + static_cast<T>(230677110449632078321772.618245845856640677845629174549731890660612368500786684333975350954L), + static_cast<T>(13652233645509183190158.5916189185218250859402806777406323001463296297553612462737044693697L), + static_cast<T>(683661466754325350495.216655026531202476397782296585200982429378069417193575896602446904762L), + static_cast<T>(28967871782219334117.0122379171041074970463982134039409352925258212207710168851968215545064L), + static_cast<T>(1036104088560167006.2022834098572346459442601718514554488352117620272232373622553429728555L), + static_cast<T>(31128490785613152.8380102669349814751268126141105475287632676569913936040772990253369753962L), + static_cast<T>(779327504127342.536207878988196814811198475410572992436243686674896894543126229424358472541L), + static_cast<T>(16067543181294.643350688789124777020407337133926174150582333950666044399234540521336771876L), + static_cast<T>(268161795520.300916569439413185778557212729611517883948634711190170998896514639936969855484L), + static_cast<T>(3533216359.10528191668842486732408440112703691790824611391987708562111396961696753452085068L), + static_cast<T>(35378979.5479656110614685178752543826919239614088343789329169535932709470588426584501652577L), + static_cast<T>(253034.881362204346444503097491737872930637147096453940375713745904094735506180552724766444L), + static_cast<T>(1151.61895453463992438325318456328526085882924197763140514450975619271382783957699017875304L), + static_cast<T>(2.50662827463100050241576528481104515966515623051532908941425544355490413900497467936202516L) + }; + static const T denom[24] = { + static_cast<T>(0L), + static_cast<T>(0.112400072777760768e22L), + static_cast<T>(0.414847677933545472e22L), + static_cast<T>(6756146673770930688000.0L), + static_cast<T>(6548684852703068697600.0L), + static_cast<T>(4280722865357147142912.0L), + static_cast<T>(2021687376910682741568.0L), + static_cast<T>(720308216440924653696.0L), + static_cast<T>(199321978221066137360.0L), + static_cast<T>(43714229649594412832.0L), + static_cast<T>(7707401101297361068.0L), + static_cast<T>(1103230881185949736.0L), + static_cast<T>(129006659818331295.0L), + static_cast<T>(12363045847086207.0L), + static_cast<T>(971250460939913.0L), + static_cast<T>(62382416421941.0L), + static_cast<T>(3256091103430.0L), + static_cast<T>(136717357942.0L), + static_cast<T>(4546047198.0L), + static_cast<T>(116896626L), + static_cast<T>(2240315L), + static_cast<T>(30107L), + static_cast<T>(253L), + static_cast<T>(1L) + }; + return boost::math::tools::evaluate_rational(num, denom, z); + } + + template <class T> + static T lanczos_sum_expG_scaled(const T& z) + { + static const T num[24] = { + static_cast<T>(3035162425359883494754.02878223286972654682199012688209026810841953293372712802258398358538L), + static_cast<T>(3496756894406430103600.16057175075063458536101374170860226963245118484234495645518505519827L), + static_cast<T>(1926652656689320888654.01954015145958293168365236755537645929361841917596501251362171653478L), + static_cast<T>(675517066488272766316.083023742440619929434602223726894748181327187670231286180156444871912L), + static_cast<T>(169172853104918752780.086262749564831660238912144573032141700464995906149421555926000038492L), + static_cast<T>(32197935167225605785.6444116302160245528783954573163541751756353183343357329404208062043808L), + static_cast<T>(4837849542714083249.37587447454818124327561966323276633775195138872820542242539845253171632L), + static_cast<T>(588431038090493242.308438203986649553459461798968819276505178004064031201740043314534404158L), + static_cast<T>(58939585141634058.6206417889192563007809470547755357240808035714047014324843817783741669733L), + static_cast<T>(4919561837722192.82991866530802080996138070630296720420704876654726991998309206256077395868L), + static_cast<T>(344916580244240.407442753122831512004021081677987651622305356145640394384006997569631719101L), + static_cast<T>(20413302960687.8250598845969238472629322716685686993835561234733641729957841485003560103066L), + static_cast<T>(1022234822943.78400752460970689311934727763870970686747383486600540378889311406851534545789L), + static_cast<T>(43313787191.9821354846952908076307094286897439975815501673706144217246093900159173598852503L), + static_cast<T>(1549219505.59667418528481770869280437577581951167003505825834192510436144666564648361001914L), + static_cast<T>(46544421.1998761919380541579358096705925369145324466147390364674998568485110045455014967149L), + static_cast<T>(1165278.06807504975090675074910052763026564833951579556132777702952882101173607903881127542L), + static_cast<T>(24024.759267256769471083727721827405338569868270177779485912486668586611981795179894572115L), + static_cast<T>(400.965008113421955824358063769761286758463521789765880962939528760888853281920872064838918L), + static_cast<T>(5.28299015654478269617039029170846385138134929147421558771949982217659507918482272439717603L), + static_cast<T>(0.0528999024412510102409256676599360516359062802002483877724963720047531347449011629466149805L), + static_cast<T>(0.000378346710654740685454266569593414561162134092347356968516522170279688139165340746957511115L), + static_cast<T>(0.172194142179211139195966608011235161516824700287310869949928393345257114743230967204370963e-5L), + static_cast<T>(0.374799931707148855771381263542708435935402853962736029347951399323367765509988401336565436e-8L) + }; + static const T denom[24] = { + static_cast<T>(0L), + static_cast<T>(0.112400072777760768e22L), + static_cast<T>(0.414847677933545472e22L), + static_cast<T>(6756146673770930688000.0L), + static_cast<T>(6548684852703068697600.0L), + static_cast<T>(4280722865357147142912.0L), + static_cast<T>(2021687376910682741568.0L), + static_cast<T>(720308216440924653696.0L), + static_cast<T>(199321978221066137360.0L), + static_cast<T>(43714229649594412832.0L), + static_cast<T>(7707401101297361068.0L), + static_cast<T>(1103230881185949736.0L), + static_cast<T>(129006659818331295.0L), + static_cast<T>(12363045847086207.0L), + static_cast<T>(971250460939913.0L), + static_cast<T>(62382416421941.0L), + static_cast<T>(3256091103430.0L), + static_cast<T>(136717357942.0L), + static_cast<T>(4546047198.0L), + static_cast<T>(116896626L), + static_cast<T>(2240315L), + static_cast<T>(30107L), + static_cast<T>(253L), + static_cast<T>(1L) + }; + return boost::math::tools::evaluate_rational(num, denom, z); + } + + + template<class T> + static T lanczos_sum_near_1(const T& dz) + { + static const T d[23] = { + static_cast<T>(7.4734083002469026177867421609938203388868806387315406134072298925733950040583068760685908L), + static_cast<T>(-50.4225805042247530267317342133388132970816607563062253708655085754357843064134941138154171L), + static_cast<T>(152.288200621747008570784082624444625293884063492396162110698238568311211546361189979357019L), + static_cast<T>(-271.894959539150384169327513139846971255640842175739337449692360299099322742181325023644769L), + static_cast<T>(319.240102980202312307047586791116902719088581839891008532114107693294261542869734803906793L), + static_cast<T>(-259.493144143048088289689500935518073716201741349569864988870534417890269467336454358361499L), + static_cast<T>(149.747518319689708813209645403067832020714660918583227716408482877303972685262557460145835L), + static_cast<T>(-61.9261301009341333289187201425188698128684426428003249782448828881580630606817104372760037L), + static_cast<T>(18.3077524177286961563937379403377462608113523887554047531153187277072451294845795496072365L), + static_cast<T>(-3.82011322251948043097070160584761236869363471824695092089556195047949392738162970152230254L), + static_cast<T>(0.549382685505691522516705902336780999493262538301283190963770663549981309645795228539620711L), + static_cast<T>(-0.0524814679715180697633723771076668718265358076235229045603747927518423453658004287459638024L), + static_cast<T>(0.00315392664003333528534120626687784812050217700942910879712808180705014754163256855643360698L), + static_cast<T>(-0.000110098373127648510519799564665442121339511198561008748083409549601095293123407080388658329L), + static_cast<T>(0.19809382866681658224945717689377373458866950897791116315219376038432014207446832310901893e-5L), + static_cast<T>(-0.152278977408600291408265615203504153130482270424202400677280558181047344681214058227949755e-7L), + static_cast<T>(0.364344768076106268872239259083188037615571711218395765792787047015406264051536972018235217e-10L), + static_cast<T>(-0.148897510480440424971521542520683536298361220674662555578951242811522959610991621951203526e-13L), + static_cast<T>(0.261199241161582662426512749820666625442516059622425213340053324061794752786482115387573582e-18L), + static_cast<T>(-0.780072664167099103420998436901014795601783313858454665485256897090476089641613851903791529e-24L), + static_cast<T>(0.303465867587106629530056603454807425512962762653755513440561256044986695349304176849392735e-24L), + static_cast<T>(-0.615420597971283870342083342286977366161772327800327789325710571275345878439656918541092056e-25L), + static_cast<T>(0.499641233843540749369110053005439398774706583601830828776209650445427083113181961630763702e-26L), + }; + T result = 0; + for(unsigned k = 1; k <= sizeof(d)/sizeof(d[0]); ++k) + { + result += (-d[k-1]*dz)/(k*dz + k*k); + } + return result; + } + + template<class T> + static T lanczos_sum_near_2(const T& dz) + { + static const T d[23] = { + static_cast<T>(61.4165001061101455341808888883960361969557848005400286332291451422461117307237198559485365L), + static_cast<T>(-414.372973678657049667308134761613915623353625332248315105320470271523320700386200587519147L), + static_cast<T>(1251.50505818554680171298972755376376836161706773644771875668053742215217922228357204561873L), + static_cast<T>(-2234.43389421602399514176336175766511311493214354568097811220122848998413358085613880612158L), + static_cast<T>(2623.51647746991904821899989145639147785427273427135380151752779100215839537090464785708684L), + static_cast<T>(-2132.51572435428751962745870184529534443305617818870214348386131243463614597272260797772423L), + static_cast<T>(1230.62572059218405766499842067263311220019173335523810725664442147670956427061920234820189L), + static_cast<T>(-508.90919151163744999377586956023909888833335885805154492270846381061182696305011395981929L), + static_cast<T>(150.453184562246579758706538566480316921938628645961177699894388251635886834047343195475395L), + static_cast<T>(-31.3937061525822497422230490071156186113405446381476081565548185848237169870395131828731397L), + static_cast<T>(4.51482916590287954234936829724231512565732528859217337795452389161322923867318809206313688L), + static_cast<T>(-0.431292919341108177524462194102701868233551186625103849565527515201492276412231365776131952L), + static_cast<T>(0.0259189820815586225636729971503340447445001375909094681698918294680345547092233915092128323L), + static_cast<T>(-0.000904788882557558697594884691337532557729219389814315972435534723829065673966567231504429712L), + static_cast<T>(0.162793589759218213439218473348810982422449144393340433592232065020562974405674317564164312e-4L), + static_cast<T>(-0.125142926178202562426432039899709511761368233479483128438847484617555752948755923647214487e-6L), + static_cast<T>(0.299418680048132583204152682950097239197934281178261879500770485862852229898797687301941982e-9L), + static_cast<T>(-0.122364035267809278675627784883078206654408225276233049012165202996967011873995261617995421e-12L), + static_cast<T>(0.21465364366598631597052073538883430194257709353929022544344097235100199405814005393447785e-17L), + static_cast<T>(-0.641064035802907518396608051803921688237330857546406669209280666066685733941549058513986818e-23L), + static_cast<T>(0.249388374622173329690271566855185869111237201309011956145463506483151054813346819490278951e-23L), + static_cast<T>(-0.505752900177513489906064295001851463338022055787536494321532352380960774349054239257683149e-24L), + static_cast<T>(0.410605371184590959139968810080063542546949719163227555918846829816144878123034347778284006e-25L), + }; + T result = 0; + T z = dz + 2; + for(unsigned k = 1; k <= sizeof(d)/sizeof(d[0]); ++k) + { + result += (-d[k-1]*dz)/(z + k*z + k*k - 1); + } + return result; + } + + static double g(){ return 20.3209821879863739013671875; } +}; + + +// +// placeholder for no lanczos info available: +// +struct undefined_lanczos : public mpl::int_<INT_MAX - 1> { }; + +#if 0 +#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS +#define BOOST_MATH_FLT_DIGITS ::std::numeric_limits<float>::digits +#define BOOST_MATH_DBL_DIGITS ::std::numeric_limits<double>::digits +#define BOOST_MATH_LDBL_DIGITS ::std::numeric_limits<long double>::digits +#else +#define BOOST_MATH_FLT_DIGITS FLT_MANT_DIG +#define BOOST_MATH_DBL_DIGITS DBL_MANT_DIG +#define BOOST_MATH_LDBL_DIGITS LDBL_MANT_DIG +#endif +#endif + +typedef mpl::list< + lanczos6m24, +/* lanczos6, */ + lanczos13m53, +/* lanczos13, */ + lanczos17m64, + lanczos24m113, + lanczos22, + undefined_lanczos> lanczos_list; + +template <class Real, class Policy> +struct lanczos +{ + typedef typename mpl::if_< + typename mpl::less_equal< + typename policies::precision<Real, Policy>::type, + mpl::int_<0> + >::type, + mpl::int_<INT_MAX - 2>, + typename policies::precision<Real, Policy>::type + >::type target_precision; + + typedef typename mpl::deref<typename mpl::find_if< + lanczos_list, + mpl::less_equal<target_precision, mpl::_1> >::type>::type type; +}; + +} // namespace lanczos +} // namespace math +} // namespace boost + +#if (defined(_M_IX86_FP) && (_M_IX86_FP >= 2)) || defined(__SSE2__) +#include <boost/math/special_functions/detail/lanczos_sse2.hpp> +#endif + +#endif // BOOST_MATH_SPECIAL_FUNCTIONS_LANCZOS + + + + diff --git a/Utilities/BGL/boost/math/special_functions/legendre.hpp b/Utilities/BGL/boost/math/special_functions/legendre.hpp new file mode 100644 index 0000000000000000000000000000000000000000..e05feb688305f13141ff2bf93a078ed86e8bf4b9 --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/legendre.hpp @@ -0,0 +1,194 @@ + +// (C) Copyright John Maddock 2006. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_SPECIAL_LEGENDRE_HPP +#define BOOST_MATH_SPECIAL_LEGENDRE_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/math/special_functions/math_fwd.hpp> +#include <boost/math/special_functions/factorials.hpp> +#include <boost/math/tools/config.hpp> + +namespace boost{ +namespace math{ + +// Recurrance relation for legendre P and Q polynomials: +template <class T1, class T2, class T3> +inline typename tools::promote_args<T1, T2, T3>::type + legendre_next(unsigned l, T1 x, T2 Pl, T3 Plm1) +{ + typedef typename tools::promote_args<T1, T2, T3>::type result_type; + return ((2 * l + 1) * result_type(x) * result_type(Pl) - l * result_type(Plm1)) / (l + 1); +} + +namespace detail{ + +// Implement Legendre P and Q polynomials via recurrance: +template <class T, class Policy> +T legendre_imp(unsigned l, T x, const Policy& pol, bool second = false) +{ + static const char* function = "boost::math::legrendre_p<%1%>(unsigned, %1%)"; + // Error handling: + if((x < -1) || (x > 1)) + return policies::raise_domain_error<T>( + function, + "The Legendre Polynomial is defined for" + " -1 <= x <= 1, but got x = %1%.", x, pol); + + T p0, p1; + if(second) + { + // A solution of the second kind (Q): + p0 = (boost::math::log1p(x, pol) - boost::math::log1p(-x, pol)) / 2; + p1 = x * p0 - 1; + } + else + { + // A solution of the first kind (P): + p0 = 1; + p1 = x; + } + if(l == 0) + return p0; + + unsigned n = 1; + + while(n < l) + { + std::swap(p0, p1); + p1 = boost::math::legendre_next(n, x, p0, p1); + ++n; + } + return p1; +} + +} // namespace detail + +template <class T, class Policy> +inline typename tools::promote_args<T>::type + legendre_p(int l, T x, const Policy& pol) +{ + typedef typename tools::promote_args<T>::type result_type; + typedef typename policies::evaluation<result_type, Policy>::type value_type; + static const char* function = "boost::math::legendre_p<%1%>(unsigned, %1%)"; + if(l < 0) + return policies::checked_narrowing_cast<result_type, Policy>(detail::legendre_imp(-l-1, static_cast<value_type>(x), pol, false), function); + return policies::checked_narrowing_cast<result_type, Policy>(detail::legendre_imp(l, static_cast<value_type>(x), pol, false), function); +} + +template <class T> +inline typename tools::promote_args<T>::type + legendre_p(int l, T x) +{ + return boost::math::legendre_p(l, x, policies::policy<>()); +} + +template <class T, class Policy> +inline typename tools::promote_args<T>::type + legendre_q(unsigned l, T x, const Policy& pol) +{ + typedef typename tools::promote_args<T>::type result_type; + typedef typename policies::evaluation<result_type, Policy>::type value_type; + return policies::checked_narrowing_cast<result_type, Policy>(detail::legendre_imp(l, static_cast<value_type>(x), pol, true), "boost::math::legendre_q<%1%>(unsigned, %1%)"); +} + +template <class T> +inline typename tools::promote_args<T>::type + legendre_q(unsigned l, T x) +{ + return boost::math::legendre_q(l, x, policies::policy<>()); +} + +// Recurrence for associated polynomials: +template <class T1, class T2, class T3> +inline typename tools::promote_args<T1, T2, T3>::type + legendre_next(unsigned l, unsigned m, T1 x, T2 Pl, T3 Plm1) +{ + typedef typename tools::promote_args<T1, T2, T3>::type result_type; + return ((2 * l + 1) * result_type(x) * result_type(Pl) - (l + m) * result_type(Plm1)) / (l + 1 - m); +} + +namespace detail{ +// Legendre P associated polynomial: +template <class T, class Policy> +T legendre_p_imp(int l, int m, T x, T sin_theta_power, const Policy& pol) +{ + // Error handling: + if((x < -1) || (x > 1)) + return policies::raise_domain_error<T>( + "boost::math::legendre_p<%1%>(int, int, %1%)", + "The associated Legendre Polynomial is defined for" + " -1 <= x <= 1, but got x = %1%.", x, pol); + // Handle negative arguments first: + if(l < 0) + return legendre_p_imp(-l-1, m, x, sin_theta_power, pol); + if(m < 0) + { + int sign = (m&1) ? -1 : 1; + return sign * boost::math::tgamma_ratio(static_cast<T>(l+m+1), static_cast<T>(l+1-m), pol) * legendre_p_imp(l, -m, x, sin_theta_power, pol); + } + // Special cases: + if(m > l) + return 0; + if(m == 0) + return boost::math::legendre_p(l, x, pol); + + T p0 = boost::math::double_factorial<T>(2 * m - 1, pol) * sin_theta_power; + + if(m&1) + p0 *= -1; + if(m == l) + return p0; + + T p1 = x * (2 * m + 1) * p0; + + int n = m + 1; + + while(n < l) + { + std::swap(p0, p1); + p1 = boost::math::legendre_next(n, m, x, p0, p1); + ++n; + } + return p1; +} + +template <class T, class Policy> +inline T legendre_p_imp(int l, int m, T x, const Policy& pol) +{ + BOOST_MATH_STD_USING + // TODO: we really could use that mythical "pow1p" function here: + return legendre_p_imp(l, m, x, pow(1 - x*x, T(abs(m))/2), pol); +} + +} + +template <class T, class Policy> +inline typename tools::promote_args<T>::type + legendre_p(int l, int m, T x, const Policy& pol) +{ + typedef typename tools::promote_args<T>::type result_type; + typedef typename policies::evaluation<result_type, Policy>::type value_type; + return policies::checked_narrowing_cast<result_type, Policy>(detail::legendre_p_imp(l, m, static_cast<value_type>(x), pol), "bost::math::legendre_p<%1%>(int, int, %1%)"); +} + +template <class T> +inline typename tools::promote_args<T>::type + legendre_p(int l, int m, T x) +{ + return boost::math::legendre_p(l, m, x, policies::policy<>()); +} + +} // namespace math +} // namespace boost + +#endif // BOOST_MATH_SPECIAL_LEGENDRE_HPP + + + diff --git a/Utilities/BGL/boost/math/special_functions/log1p.hpp b/Utilities/BGL/boost/math/special_functions/log1p.hpp new file mode 100644 index 0000000000000000000000000000000000000000..9ac7a4ef4fbe90113a150784bcb3585e0903e4ea --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/log1p.hpp @@ -0,0 +1,466 @@ +// (C) Copyright John Maddock 2005-2006. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_LOG1P_INCLUDED +#define BOOST_MATH_LOG1P_INCLUDED + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/config/no_tr1/cmath.hpp> +#include <math.h> // platform's ::log1p +#include <boost/limits.hpp> +#include <boost/math/tools/config.hpp> +#include <boost/math/tools/series.hpp> +#include <boost/math/tools/rational.hpp> +#include <boost/math/policies/error_handling.hpp> +#include <boost/math/special_functions/math_fwd.hpp> + +#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS +# include <boost/static_assert.hpp> +#else +# include <boost/assert.hpp> +#endif + +namespace boost{ namespace math{ + +namespace detail +{ + // Functor log1p_series returns the next term in the Taylor series + // pow(-1, k-1)*pow(x, k) / k + // each time that operator() is invoked. + // + template <class T> + struct log1p_series + { + typedef T result_type; + + log1p_series(T x) + : k(0), m_mult(-x), m_prod(-1){} + + T operator()() + { + m_prod *= m_mult; + return m_prod / ++k; + } + + int count()const + { + return k; + } + + private: + int k; + const T m_mult; + T m_prod; + log1p_series(const log1p_series&); + log1p_series& operator=(const log1p_series&); + }; + +// Algorithm log1p is part of C99, but is not yet provided by many compilers. +// +// This version uses a Taylor series expansion for 0.5 > x > epsilon, which may +// require up to std::numeric_limits<T>::digits+1 terms to be calculated. +// It would be much more efficient to use the equivalence: +// log(1+x) == (log(1+x) * x) / ((1-x) - 1) +// Unfortunately many optimizing compilers make such a mess of this, that +// it performs no better than log(1+x): which is to say not very well at all. +// +template <class T, class Policy> +T log1p_imp(T const & x, const Policy& pol, const mpl::int_<0>&) +{ // The function returns the natural logarithm of 1 + x. + typedef typename tools::promote_args<T>::type result_type; + BOOST_MATH_STD_USING + using std::abs; + + static const char* function = "boost::math::log1p<%1%>(%1%)"; + + if(x < -1) + return policies::raise_domain_error<T>( + function, "log1p(x) requires x > -1, but got x = %1%.", x, pol); + if(x == -1) + return -policies::raise_overflow_error<T>( + function, 0, pol); + + result_type a = abs(result_type(x)); + if(a > result_type(0.5f)) + return log(1 + result_type(x)); + // Note that without numeric_limits specialisation support, + // epsilon just returns zero, and our "optimisation" will always fail: + if(a < tools::epsilon<result_type>()) + return x; + detail::log1p_series<result_type> s(x); + boost::uintmax_t max_iter = policies::get_max_series_iterations<Policy>(); +#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582)) && !BOOST_WORKAROUND(__EDG_VERSION__, <= 245) + result_type result = tools::sum_series(s, policies::get_epsilon<result_type, Policy>(), max_iter); +#else + result_type zero = 0; + result_type result = tools::sum_series(s, policies::get_epsilon<result_type, Policy>(), max_iter, zero); +#endif + policies::check_series_iterations(function, max_iter, pol); + return result; +} + +template <class T, class Policy> +T log1p_imp(T const& x, const Policy& pol, const mpl::int_<53>&) +{ // The function returns the natural logarithm of 1 + x. + BOOST_MATH_STD_USING + + static const char* function = "boost::math::log1p<%1%>(%1%)"; + + if(x < -1) + return policies::raise_domain_error<T>( + function, "log1p(x) requires x > -1, but got x = %1%.", x, pol); + if(x == -1) + return -policies::raise_overflow_error<T>( + function, 0, pol); + + T a = fabs(x); + if(a > 0.5f) + return log(1 + x); + // Note that without numeric_limits specialisation support, + // epsilon just returns zero, and our "optimisation" will always fail: + if(a < tools::epsilon<T>()) + return x; + + // Maximum Deviation Found: 1.846e-017 + // Expected Error Term: 1.843e-017 + // Maximum Relative Change in Control Points: 8.138e-004 + // Max Error found at double precision = 3.250766e-016 + static const T P[] = { + 0.15141069795941984e-16L, + 0.35495104378055055e-15L, + 0.33333333333332835L, + 0.99249063543365859L, + 1.1143969784156509L, + 0.58052937949269651L, + 0.13703234928513215L, + 0.011294864812099712L + }; + static const T Q[] = { + 1L, + 3.7274719063011499L, + 5.5387948649720334L, + 4.159201143419005L, + 1.6423855110312755L, + 0.31706251443180914L, + 0.022665554431410243L, + -0.29252538135177773e-5L + }; + + T result = 1 - x / 2 + tools::evaluate_polynomial(P, x) / tools::evaluate_polynomial(Q, x); + result *= x; + + return result; +} + +template <class T, class Policy> +T log1p_imp(T const& x, const Policy& pol, const mpl::int_<64>&) +{ // The function returns the natural logarithm of 1 + x. + BOOST_MATH_STD_USING + + static const char* function = "boost::math::log1p<%1%>(%1%)"; + + if(x < -1) + return policies::raise_domain_error<T>( + function, "log1p(x) requires x > -1, but got x = %1%.", x, pol); + if(x == -1) + return -policies::raise_overflow_error<T>( + function, 0, pol); + + T a = fabs(x); + if(a > 0.5f) + return log(1 + x); + // Note that without numeric_limits specialisation support, + // epsilon just returns zero, and our "optimisation" will always fail: + if(a < tools::epsilon<T>()) + return x; + + // Maximum Deviation Found: 8.089e-20 + // Expected Error Term: 8.088e-20 + // Maximum Relative Change in Control Points: 9.648e-05 + // Max Error found at long double precision = 2.242324e-19 + static const T P[] = { + -0.807533446680736736712e-19L, + -0.490881544804798926426e-18L, + 0.333333333333333373941L, + 1.17141290782087994162L, + 1.62790522814926264694L, + 1.13156411870766876113L, + 0.408087379932853785336L, + 0.0706537026422828914622L, + 0.00441709903782239229447L + }; + static const T Q[] = { + 1L, + 4.26423872346263928361L, + 7.48189472704477708962L, + 6.94757016732904280913L, + 3.6493508622280767304L, + 1.06884863623790638317L, + 0.158292216998514145947L, + 0.00885295524069924328658L, + -0.560026216133415663808e-6L + }; + + T result = 1 - x / 2 + tools::evaluate_polynomial(P, x) / tools::evaluate_polynomial(Q, x); + result *= x; + + return result; +} + +template <class T, class Policy> +T log1p_imp(T const& x, const Policy& pol, const mpl::int_<24>&) +{ // The function returns the natural logarithm of 1 + x. + BOOST_MATH_STD_USING + + static const char* function = "boost::math::log1p<%1%>(%1%)"; + + if(x < -1) + return policies::raise_domain_error<T>( + function, "log1p(x) requires x > -1, but got x = %1%.", x, pol); + if(x == -1) + return -policies::raise_overflow_error<T>( + function, 0, pol); + + T a = fabs(x); + if(a > 0.5f) + return log(1 + x); + // Note that without numeric_limits specialisation support, + // epsilon just returns zero, and our "optimisation" will always fail: + if(a < tools::epsilon<T>()) + return x; + + // Maximum Deviation Found: 6.910e-08 + // Expected Error Term: 6.910e-08 + // Maximum Relative Change in Control Points: 2.509e-04 + // Max Error found at double precision = 6.910422e-08 + // Max Error found at float precision = 8.357242e-08 + static const T P[] = { + -0.671192866803148236519e-7L, + 0.119670999140731844725e-6L, + 0.333339469182083148598L, + 0.237827183019664122066L + }; + static const T Q[] = { + 1L, + 1.46348272586988539733L, + 0.497859871350117338894L, + -0.00471666268910169651936L + }; + + T result = 1 - x / 2 + tools::evaluate_polynomial(P, x) / tools::evaluate_polynomial(Q, x); + result *= x; + + return result; +} + +} // namespace detail + +template <class T, class Policy> +inline typename tools::promote_args<T>::type log1p(T x, const Policy&) +{ + typedef typename tools::promote_args<T>::type result_type; + typedef typename policies::evaluation<result_type, Policy>::type value_type; + typedef typename policies::precision<result_type, Policy>::type precision_type; + typedef typename policies::normalise< + Policy, + policies::promote_float<false>, + policies::promote_double<false>, + policies::discrete_quantile<>, + policies::assert_undefined<> >::type forwarding_policy; + + typedef typename mpl::if_< + mpl::less_equal<precision_type, mpl::int_<0> >, + mpl::int_<0>, + typename mpl::if_< + mpl::less_equal<precision_type, mpl::int_<53> >, + mpl::int_<53>, // double + typename mpl::if_< + mpl::less_equal<precision_type, mpl::int_<64> >, + mpl::int_<64>, // 80-bit long double + mpl::int_<0> // too many bits, use generic version. + >::type + >::type + >::type tag_type; + return policies::checked_narrowing_cast<result_type, forwarding_policy>( + detail::log1p_imp(static_cast<value_type>(x), forwarding_policy(), tag_type()), "boost::math::log1p<%1%>(%1%)"); +} + +#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) +// These overloads work around a type deduction bug: +inline float log1p(float z) +{ + return log1p<float>(z); +} +inline double log1p(double z) +{ + return log1p<double>(z); +} +#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS +inline long double log1p(long double z) +{ + return log1p<long double>(z); +} +#endif +#endif + +#ifdef log1p +# ifndef BOOST_HAS_LOG1P +# define BOOST_HAS_LOG1P +# endif +# undef log1p +#endif + +#if defined(BOOST_HAS_LOG1P) && !(defined(__osf__) && defined(__DECCXX_VER)) +# ifdef BOOST_MATH_USE_C99 +template <class Policy> +inline float log1p(float x, const Policy& pol) +{ + if(x < -1) + return policies::raise_domain_error<float>( + "log1p<%1%>(%1%)", "log1p(x) requires x > -1, but got x = %1%.", x, pol); + if(x == -1) + return -policies::raise_overflow_error<float>( + "log1p<%1%>(%1%)", 0, pol); + return ::log1pf(x); +} +#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS +template <class Policy> +inline long double log1p(long double x, const Policy& pol) +{ + if(x < -1) + return policies::raise_domain_error<long double>( + "log1p<%1%>(%1%)", "log1p(x) requires x > -1, but got x = %1%.", x, pol); + if(x == -1) + return -policies::raise_overflow_error<long double>( + "log1p<%1%>(%1%)", 0, pol); + return ::log1pl(x); +} +#endif +#else +template <class Policy> +inline float log1p(float x, const Policy& pol) +{ + if(x < -1) + return policies::raise_domain_error<float>( + "log1p<%1%>(%1%)", "log1p(x) requires x > -1, but got x = %1%.", x, pol); + if(x == -1) + return -policies::raise_overflow_error<float>( + "log1p<%1%>(%1%)", 0, pol); + return ::log1p(x); +} +#endif +template <class Policy> +inline double log1p(double x, const Policy& pol) +{ + if(x < -1) + return policies::raise_domain_error<double>( + "log1p<%1%>(%1%)", "log1p(x) requires x > -1, but got x = %1%.", x, pol); + if(x == -1) + return -policies::raise_overflow_error<double>( + "log1p<%1%>(%1%)", 0, pol); + return ::log1p(x); +} +#elif defined(_MSC_VER) && (BOOST_MSVC >= 1400) +// +// You should only enable this branch if you are absolutely sure +// that your compilers optimizer won't mess this code up!! +// Currently tested with VC8 and Intel 9.1. +// +template <class Policy> +inline double log1p(double x, const Policy& pol) +{ + if(x < -1) + return policies::raise_domain_error<double>( + "log1p<%1%>(%1%)", "log1p(x) requires x > -1, but got x = %1%.", x, pol); + if(x == -1) + return -policies::raise_overflow_error<double>( + "log1p<%1%>(%1%)", 0, pol); + double u = 1+x; + if(u == 1.0) + return x; + else + return ::log(u)*(x/(u-1.0)); +} +template <class Policy> +inline float log1p(float x, const Policy& pol) +{ + return static_cast<float>(boost::math::log1p(static_cast<double>(x), pol)); +} +template <class Policy> +inline long double log1p(long double x, const Policy& pol) +{ + if(x < -1) + return policies::raise_domain_error<long double>( + "log1p<%1%>(%1%)", "log1p(x) requires x > -1, but got x = %1%.", x, pol); + if(x == -1) + return -policies::raise_overflow_error<long double>( + "log1p<%1%>(%1%)", 0, pol); + long double u = 1+x; + if(u == 1.0) + return x; + else + return ::logl(u)*(x/(u-1.0)); +} +#endif + +template <class T> +inline typename tools::promote_args<T>::type log1p(T x) +{ + return boost::math::log1p(x, policies::policy<>()); +} +// +// Compute log(1+x)-x: +// +template <class T, class Policy> +inline typename tools::promote_args<T>::type + log1pmx(T x, const Policy& pol) +{ + typedef typename tools::promote_args<T>::type result_type; + BOOST_MATH_STD_USING + static const char* function = "boost::math::log1pmx<%1%>(%1%)"; + + if(x < -1) + return policies::raise_domain_error<T>( + function, "log1pmx(x) requires x > -1, but got x = %1%.", x, pol); + if(x == -1) + return -policies::raise_overflow_error<T>( + function, 0, pol); + + result_type a = abs(result_type(x)); + if(a > result_type(0.95f)) + return log(1 + result_type(x)) - result_type(x); + // Note that without numeric_limits specialisation support, + // epsilon just returns zero, and our "optimisation" will always fail: + if(a < tools::epsilon<result_type>()) + return -x * x / 2; + boost::math::detail::log1p_series<T> s(x); + s(); + boost::uintmax_t max_iter = policies::get_max_series_iterations<Policy>(); +#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582)) + T zero = 0; + T result = boost::math::tools::sum_series(s, policies::get_epsilon<T, Policy>(), max_iter, zero); +#else + T result = boost::math::tools::sum_series(s, policies::get_epsilon<T, Policy>(), max_iter); +#endif + policies::check_series_iterations(function, max_iter, pol); + return result; +} + +template <class T> +inline typename tools::promote_args<T>::type log1pmx(T x) +{ + return log1pmx(x, policies::policy<>()); +} + +} // namespace math +} // namespace boost + +#endif // BOOST_MATH_LOG1P_INCLUDED + + + diff --git a/Utilities/BGL/boost/math/special_functions/math_fwd.hpp b/Utilities/BGL/boost/math/special_functions/math_fwd.hpp new file mode 100644 index 0000000000000000000000000000000000000000..b4cd50bd84936ae9cb05cef011fe49da8bf67be6 --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/math_fwd.hpp @@ -0,0 +1,1055 @@ +// math_fwd.hpp + +// TODO revise completely for new distribution classes. + +// Copyright Paul A. Bristow 2006. +// Copyright John Maddock 2006. + +// Use, modification and distribution are subject to 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) + +// Omnibus list of forward declarations of math special functions. + +// IT = Integer type. +// RT = Real type (built-in floating-point types, float, double, long double) & User Defined Types +// AT = Integer or Real type + +#ifndef BOOST_MATH_SPECIAL_MATH_FWD_HPP +#define BOOST_MATH_SPECIAL_MATH_FWD_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/math/special_functions/detail/round_fwd.hpp> +#include <boost/math/tools/promotion.hpp> // for argument promotion. +#include <boost/math/policies/policy.hpp> +#include <boost/mpl/comparison.hpp> +#include <boost/config/no_tr1/complex.hpp> + +#define BOOST_NO_MACRO_EXPAND /**/ + +namespace boost +{ + namespace math + { // Math functions (in roughly alphabetic order). + + // Beta functions. + template <class RT1, class RT2> + typename tools::promote_args<RT1, RT2>::type + beta(RT1 a, RT2 b); // Beta function (2 arguments). + + template <class RT1, class RT2, class A> + typename tools::promote_args<RT1, RT2, A>::type + beta(RT1 a, RT2 b, A x); // Beta function (3 arguments). + + template <class RT1, class RT2, class RT3, class Policy> + typename tools::promote_args<RT1, RT2, RT3>::type + beta(RT1 a, RT2 b, RT3 x, const Policy& pol); // Beta function (3 arguments). + + template <class RT1, class RT2, class RT3> + typename tools::promote_args<RT1, RT2, RT3>::type + betac(RT1 a, RT2 b, RT3 x); + + template <class RT1, class RT2, class RT3, class Policy> + typename tools::promote_args<RT1, RT2, RT3>::type + betac(RT1 a, RT2 b, RT3 x, const Policy& pol); + + template <class RT1, class RT2, class RT3> + typename tools::promote_args<RT1, RT2, RT3>::type + ibeta(RT1 a, RT2 b, RT3 x); // Incomplete beta function. + + template <class RT1, class RT2, class RT3, class Policy> + typename tools::promote_args<RT1, RT2, RT3>::type + ibeta(RT1 a, RT2 b, RT3 x, const Policy& pol); // Incomplete beta function. + + template <class RT1, class RT2, class RT3> + typename tools::promote_args<RT1, RT2, RT3>::type + ibetac(RT1 a, RT2 b, RT3 x); // Incomplete beta complement function. + + template <class RT1, class RT2, class RT3, class Policy> + typename tools::promote_args<RT1, RT2, RT3>::type + ibetac(RT1 a, RT2 b, RT3 x, const Policy& pol); // Incomplete beta complement function. + + template <class T1, class T2, class T3, class T4> + typename tools::promote_args<T1, T2, T3, T4>::type + ibeta_inv(T1 a, T2 b, T3 p, T4* py); + + template <class T1, class T2, class T3, class T4, class Policy> + typename tools::promote_args<T1, T2, T3, T4>::type + ibeta_inv(T1 a, T2 b, T3 p, T4* py, const Policy& pol); + + template <class RT1, class RT2, class RT3> + typename tools::promote_args<RT1, RT2, RT3>::type + ibeta_inv(RT1 a, RT2 b, RT3 p); // Incomplete beta inverse function. + + template <class RT1, class RT2, class RT3, class Policy> + typename tools::promote_args<RT1, RT2, RT3>::type + ibeta_inv(RT1 a, RT2 b, RT3 p, const Policy&); // Incomplete beta inverse function. + + template <class RT1, class RT2, class RT3> + typename tools::promote_args<RT1, RT2, RT3>::type + ibeta_inva(RT1 a, RT2 b, RT3 p); // Incomplete beta inverse function. + + template <class RT1, class RT2, class RT3, class Policy> + typename tools::promote_args<RT1, RT2, RT3>::type + ibeta_inva(RT1 a, RT2 b, RT3 p, const Policy&); // Incomplete beta inverse function. + + template <class RT1, class RT2, class RT3> + typename tools::promote_args<RT1, RT2, RT3>::type + ibeta_invb(RT1 a, RT2 b, RT3 p); // Incomplete beta inverse function. + + template <class RT1, class RT2, class RT3, class Policy> + typename tools::promote_args<RT1, RT2, RT3>::type + ibeta_invb(RT1 a, RT2 b, RT3 p, const Policy&); // Incomplete beta inverse function. + + template <class T1, class T2, class T3, class T4> + typename tools::promote_args<T1, T2, T3, T4>::type + ibetac_inv(T1 a, T2 b, T3 q, T4* py); + + template <class T1, class T2, class T3, class T4, class Policy> + typename tools::promote_args<T1, T2, T3, T4>::type + ibetac_inv(T1 a, T2 b, T3 q, T4* py, const Policy& pol); + + template <class RT1, class RT2, class RT3> + typename tools::promote_args<RT1, RT2, RT3>::type + ibetac_inv(RT1 a, RT2 b, RT3 q); // Incomplete beta complement inverse function. + + template <class RT1, class RT2, class RT3, class Policy> + typename tools::promote_args<RT1, RT2, RT3>::type + ibetac_inv(RT1 a, RT2 b, RT3 q, const Policy&); // Incomplete beta complement inverse function. + + template <class RT1, class RT2, class RT3> + typename tools::promote_args<RT1, RT2, RT3>::type + ibetac_inva(RT1 a, RT2 b, RT3 q); // Incomplete beta complement inverse function. + + template <class RT1, class RT2, class RT3, class Policy> + typename tools::promote_args<RT1, RT2, RT3>::type + ibetac_inva(RT1 a, RT2 b, RT3 q, const Policy&); // Incomplete beta complement inverse function. + + template <class RT1, class RT2, class RT3> + typename tools::promote_args<RT1, RT2, RT3>::type + ibetac_invb(RT1 a, RT2 b, RT3 q); // Incomplete beta complement inverse function. + + template <class RT1, class RT2, class RT3, class Policy> + typename tools::promote_args<RT1, RT2, RT3>::type + ibetac_invb(RT1 a, RT2 b, RT3 q, const Policy&); // Incomplete beta complement inverse function. + + template <class RT1, class RT2, class RT3> + typename tools::promote_args<RT1, RT2, RT3>::type + ibeta_derivative(RT1 a, RT2 b, RT3 x); // derivative of incomplete beta + + template <class RT1, class RT2, class RT3, class Policy> + typename tools::promote_args<RT1, RT2, RT3>::type + ibeta_derivative(RT1 a, RT2 b, RT3 x, const Policy& pol); // derivative of incomplete beta + + // erf & erfc error functions. + template <class RT> // Error function. + typename tools::promote_args<RT>::type erf(RT z); + template <class RT, class Policy> // Error function. + typename tools::promote_args<RT>::type erf(RT z, const Policy&); + + template <class RT>// Error function complement. + typename tools::promote_args<RT>::type erfc(RT z); + template <class RT, class Policy>// Error function complement. + typename tools::promote_args<RT>::type erfc(RT z, const Policy&); + + template <class RT>// Error function inverse. + typename tools::promote_args<RT>::type erf_inv(RT z); + template <class RT, class Policy>// Error function inverse. + typename tools::promote_args<RT>::type erf_inv(RT z, const Policy& pol); + + template <class RT>// Error function complement inverse. + typename tools::promote_args<RT>::type erfc_inv(RT z); + template <class RT, class Policy>// Error function complement inverse. + typename tools::promote_args<RT>::type erfc_inv(RT z, const Policy& pol); + + // Polynomials: + template <class T1, class T2, class T3> + typename tools::promote_args<T1, T2, T3>::type + legendre_next(unsigned l, T1 x, T2 Pl, T3 Plm1); + + template <class T> + typename tools::promote_args<T>::type + legendre_p(int l, T x); + + template <class T, class Policy> + typename tools::promote_args<T>::type + legendre_p(int l, T x, const Policy& pol); + + template <class T> + typename tools::promote_args<T>::type + legendre_q(unsigned l, T x); + + template <class T, class Policy> + typename tools::promote_args<T>::type + legendre_q(unsigned l, T x, const Policy& pol); + + template <class T1, class T2, class T3> + typename tools::promote_args<T1, T2, T3>::type + legendre_next(unsigned l, unsigned m, T1 x, T2 Pl, T3 Plm1); + + template <class T> + typename tools::promote_args<T>::type + legendre_p(int l, int m, T x); + + template <class T, class Policy> + typename tools::promote_args<T>::type + legendre_p(int l, int m, T x, const Policy& pol); + + template <class T1, class T2, class T3> + typename tools::promote_args<T1, T2, T3>::type + laguerre_next(unsigned n, T1 x, T2 Ln, T3 Lnm1); + + template <class T1, class T2, class T3> + typename tools::promote_args<T1, T2, T3>::type + laguerre_next(unsigned n, unsigned l, T1 x, T2 Pl, T3 Plm1); + + template <class T> + typename tools::promote_args<T>::type + laguerre(unsigned n, T x); + + template <class T, class Policy> + typename tools::promote_args<T>::type + laguerre(unsigned n, unsigned m, T x, const Policy& pol); + + template <class T1, class T2> + struct laguerre_result + { + typedef typename mpl::if_< + policies::is_policy<T2>, + typename tools::promote_args<T1>::type, + typename tools::promote_args<T2>::type + >::type type; + }; + + template <class T1, class T2> + typename laguerre_result<T1, T2>::type + laguerre(unsigned n, T1 m, T2 x); + + template <class T> + typename tools::promote_args<T>::type + hermite(unsigned n, T x); + + template <class T, class Policy> + typename tools::promote_args<T>::type + hermite(unsigned n, T x, const Policy& pol); + + template <class T1, class T2, class T3> + typename tools::promote_args<T1, T2, T3>::type + hermite_next(unsigned n, T1 x, T2 Hn, T3 Hnm1); + + template <class T1, class T2> + std::complex<typename tools::promote_args<T1, T2>::type> + spherical_harmonic(unsigned n, int m, T1 theta, T2 phi); + + template <class T1, class T2, class Policy> + std::complex<typename tools::promote_args<T1, T2>::type> + spherical_harmonic(unsigned n, int m, T1 theta, T2 phi, const Policy& pol); + + template <class T1, class T2> + typename tools::promote_args<T1, T2>::type + spherical_harmonic_r(unsigned n, int m, T1 theta, T2 phi); + + template <class T1, class T2, class Policy> + typename tools::promote_args<T1, T2>::type + spherical_harmonic_r(unsigned n, int m, T1 theta, T2 phi, const Policy& pol); + + template <class T1, class T2> + typename tools::promote_args<T1, T2>::type + spherical_harmonic_i(unsigned n, int m, T1 theta, T2 phi); + + template <class T1, class T2, class Policy> + typename tools::promote_args<T1, T2>::type + spherical_harmonic_i(unsigned n, int m, T1 theta, T2 phi, const Policy& pol); + + // Elliptic integrals: + template <class T1, class T2, class T3> + typename tools::promote_args<T1, T2, T3>::type + ellint_rf(T1 x, T2 y, T3 z); + + template <class T1, class T2, class T3, class Policy> + typename tools::promote_args<T1, T2, T3>::type + ellint_rf(T1 x, T2 y, T3 z, const Policy& pol); + + template <class T1, class T2, class T3> + typename tools::promote_args<T1, T2, T3>::type + ellint_rd(T1 x, T2 y, T3 z); + + template <class T1, class T2, class T3, class Policy> + typename tools::promote_args<T1, T2, T3>::type + ellint_rd(T1 x, T2 y, T3 z, const Policy& pol); + + template <class T1, class T2> + typename tools::promote_args<T1, T2>::type + ellint_rc(T1 x, T2 y); + + template <class T1, class T2, class Policy> + typename tools::promote_args<T1, T2>::type + ellint_rc(T1 x, T2 y, const Policy& pol); + + template <class T1, class T2, class T3, class T4> + typename tools::promote_args<T1, T2, T3, T4>::type + ellint_rj(T1 x, T2 y, T3 z, T4 p); + + template <class T1, class T2, class T3, class T4, class Policy> + typename tools::promote_args<T1, T2, T3, T4>::type + ellint_rj(T1 x, T2 y, T3 z, T4 p, const Policy& pol); + + template <typename T> + typename tools::promote_args<T>::type ellint_2(T k); + + template <class T1, class T2> + typename tools::promote_args<T1, T2>::type ellint_2(T1 k, T2 phi); + + template <class T1, class T2, class Policy> + typename tools::promote_args<T1, T2>::type ellint_2(T1 k, T2 phi, const Policy& pol); + + template <typename T> + typename tools::promote_args<T>::type ellint_1(T k); + + template <class T1, class T2> + typename tools::promote_args<T1, T2>::type ellint_1(T1 k, T2 phi); + + template <class T1, class T2, class Policy> + typename tools::promote_args<T1, T2>::type ellint_1(T1 k, T2 phi, const Policy& pol); + + namespace detail{ + + template <class T, class U, class V> + struct ellint_3_result + { + typedef typename mpl::if_< + policies::is_policy<V>, + typename tools::promote_args<T, U>::type, + typename tools::promote_args<T, U, V>::type + >::type type; + }; + + } // namespace detail + + + template <class T1, class T2, class T3> + typename detail::ellint_3_result<T1, T2, T3>::type ellint_3(T1 k, T2 v, T3 phi); + + template <class T1, class T2, class T3, class Policy> + typename tools::promote_args<T1, T2, T3>::type ellint_3(T1 k, T2 v, T3 phi, const Policy& pol); + + template <class T1, class T2> + typename tools::promote_args<T1, T2>::type ellint_3(T1 k, T2 v); + + // Factorial functions. + // Note: not for integral types, at present. + template <class RT> + struct max_factorial; + template <class RT> + RT factorial(unsigned int); + template <class RT, class Policy> + RT factorial(unsigned int, const Policy& pol); + template <class RT> + RT unchecked_factorial(unsigned int BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE(RT)); + template <class RT> + RT double_factorial(unsigned i); + template <class RT, class Policy> + RT double_factorial(unsigned i, const Policy& pol); + + template <class RT> + typename tools::promote_args<RT>::type falling_factorial(RT x, unsigned n); + + template <class RT, class Policy> + typename tools::promote_args<RT>::type falling_factorial(RT x, unsigned n, const Policy& pol); + + template <class RT> + typename tools::promote_args<RT>::type rising_factorial(RT x, int n); + + template <class RT, class Policy> + typename tools::promote_args<RT>::type rising_factorial(RT x, int n, const Policy& pol); + + // Gamma functions. + template <class RT> + typename tools::promote_args<RT>::type tgamma(RT z); + + template <class RT> + typename tools::promote_args<RT>::type tgamma1pm1(RT z); + + template <class RT, class Policy> + typename tools::promote_args<RT>::type tgamma1pm1(RT z, const Policy& pol); + + template <class RT1, class RT2> + typename tools::promote_args<RT1, RT2>::type tgamma(RT1 a, RT2 z); + + template <class RT1, class RT2, class Policy> + typename tools::promote_args<RT1, RT2>::type tgamma(RT1 a, RT2 z, const Policy& pol); + + template <class RT> + typename tools::promote_args<RT>::type lgamma(RT z, int* sign); + + template <class RT, class Policy> + typename tools::promote_args<RT>::type lgamma(RT z, int* sign, const Policy& pol); + + template <class RT> + typename tools::promote_args<RT>::type lgamma(RT x); + + template <class RT, class Policy> + typename tools::promote_args<RT>::type lgamma(RT x, const Policy& pol); + + template <class RT1, class RT2> + typename tools::promote_args<RT1, RT2>::type tgamma_lower(RT1 a, RT2 z); + + template <class RT1, class RT2, class Policy> + typename tools::promote_args<RT1, RT2>::type tgamma_lower(RT1 a, RT2 z, const Policy&); + + template <class RT1, class RT2> + typename tools::promote_args<RT1, RT2>::type gamma_q(RT1 a, RT2 z); + + template <class RT1, class RT2, class Policy> + typename tools::promote_args<RT1, RT2>::type gamma_q(RT1 a, RT2 z, const Policy&); + + template <class RT1, class RT2> + typename tools::promote_args<RT1, RT2>::type gamma_p(RT1 a, RT2 z); + + template <class RT1, class RT2, class Policy> + typename tools::promote_args<RT1, RT2>::type gamma_p(RT1 a, RT2 z, const Policy&); + + template <class T1, class T2> + typename tools::promote_args<T1, T2>::type tgamma_delta_ratio(T1 z, T2 delta); + + template <class T1, class T2, class Policy> + typename tools::promote_args<T1, T2>::type tgamma_delta_ratio(T1 z, T2 delta, const Policy&); + + template <class T1, class T2> + typename tools::promote_args<T1, T2>::type tgamma_ratio(T1 a, T2 b); + + template <class T1, class T2, class Policy> + typename tools::promote_args<T1, T2>::type tgamma_ratio(T1 a, T2 b, const Policy&); + + template <class T1, class T2> + typename tools::promote_args<T1, T2>::type gamma_p_derivative(T1 a, T2 x); + + template <class T1, class T2, class Policy> + typename tools::promote_args<T1, T2>::type gamma_p_derivative(T1 a, T2 x, const Policy&); + + // gamma inverse. + template <class T1, class T2> + typename tools::promote_args<T1, T2>::type gamma_p_inv(T1 a, T2 p); + + template <class T1, class T2, class Policy> + typename tools::promote_args<T1, T2>::type gamma_p_inva(T1 a, T2 p, const Policy&); + + template <class T1, class T2> + typename tools::promote_args<T1, T2>::type gamma_p_inva(T1 a, T2 p); + + template <class T1, class T2, class Policy> + typename tools::promote_args<T1, T2>::type gamma_p_inv(T1 a, T2 p, const Policy&); + + template <class T1, class T2> + typename tools::promote_args<T1, T2>::type gamma_q_inv(T1 a, T2 q); + + template <class T1, class T2, class Policy> + typename tools::promote_args<T1, T2>::type gamma_q_inv(T1 a, T2 q, const Policy&); + + template <class T1, class T2> + typename tools::promote_args<T1, T2>::type gamma_q_inva(T1 a, T2 q); + + template <class T1, class T2, class Policy> + typename tools::promote_args<T1, T2>::type gamma_q_inva(T1 a, T2 q, const Policy&); + + // digamma: + template <class T> + typename tools::promote_args<T>::type digamma(T x); + + template <class T, class Policy> + typename tools::promote_args<T>::type digamma(T x, const Policy&); + + // Hypotenuse function sqrt(x ^ 2 + y ^ 2). + template <class T1, class T2> + typename tools::promote_args<T1, T2>::type + hypot(T1 x, T2 y); + + template <class T1, class T2, class Policy> + typename tools::promote_args<T1, T2>::type + hypot(T1 x, T2 y, const Policy&); + + // cbrt - cube root. + template <class RT> + typename tools::promote_args<RT>::type cbrt(RT z); + + template <class RT, class Policy> + typename tools::promote_args<RT>::type cbrt(RT z, const Policy&); + + // log1p is log(x + 1) + template <class T> + typename tools::promote_args<T>::type log1p(T); + + template <class T, class Policy> + typename tools::promote_args<T>::type log1p(T, const Policy&); + + // log1pmx is log(x + 1) - x + template <class T> + typename tools::promote_args<T>::type log1pmx(T); + + template <class T, class Policy> + typename tools::promote_args<T>::type log1pmx(T, const Policy&); + + // Exp (x) minus 1 functions. + template <class T> + typename tools::promote_args<T>::type expm1(T); + + template <class T, class Policy> + typename tools::promote_args<T>::type expm1(T, const Policy&); + + // Power - 1 + template <class T1, class T2> + typename tools::promote_args<T1, T2>::type + powm1(const T1 a, const T2 z); + + template <class T1, class T2, class Policy> + typename tools::promote_args<T1, T2>::type + powm1(const T1 a, const T2 z, const Policy&); + + // sqrt(1+x) - 1 + template <class T> + typename tools::promote_args<T>::type sqrt1pm1(const T& val); + + template <class T, class Policy> + typename tools::promote_args<T>::type sqrt1pm1(const T& val, const Policy&); + + // sinus cardinals: + template <class T> + typename tools::promote_args<T>::type sinc_pi(T x); + + template <class T, class Policy> + typename tools::promote_args<T>::type sinc_pi(T x, const Policy&); + + template <class T> + typename tools::promote_args<T>::type sinhc_pi(T x); + + template <class T, class Policy> + typename tools::promote_args<T>::type sinhc_pi(T x, const Policy&); + + // inverse hyperbolics: + template<typename T> + typename tools::promote_args<T>::type asinh(T x); + + template<typename T, class Policy> + typename tools::promote_args<T>::type asinh(T x, const Policy&); + + template<typename T> + typename tools::promote_args<T>::type acosh(T x); + + template<typename T, class Policy> + typename tools::promote_args<T>::type acosh(T x, const Policy&); + + template<typename T> + typename tools::promote_args<T>::type atanh(T x); + + template<typename T, class Policy> + typename tools::promote_args<T>::type atanh(T x, const Policy&); + + namespace detail{ + + typedef mpl::int_<0> bessel_no_int_tag; // No integer optimisation possible. + typedef mpl::int_<1> bessel_maybe_int_tag; // Maybe integer optimisation. + typedef mpl::int_<2> bessel_int_tag; // Definite integer optimistaion. + + template <class T1, class T2, class Policy> + struct bessel_traits + { + typedef typename tools::promote_args< + T1, T2 + >::type result_type; + + typedef typename policies::precision<result_type, Policy>::type precision_type; + + typedef typename mpl::if_< + mpl::or_< + mpl::less_equal<precision_type, mpl::int_<0> >, + mpl::greater<precision_type, mpl::int_<64> > >, + bessel_no_int_tag, + typename mpl::if_< + is_integral<T1>, + bessel_int_tag, + bessel_maybe_int_tag + >::type + >::type optimisation_tag; + }; + } // detail + + // Bessel functions: + template <class T1, class T2, class Policy> + typename detail::bessel_traits<T1, T2, Policy>::result_type cyl_bessel_j(T1 v, T2 x, const Policy& pol); + + template <class T1, class T2> + typename detail::bessel_traits<T1, T2, policies::policy<> >::result_type cyl_bessel_j(T1 v, T2 x); + + template <class T, class Policy> + typename detail::bessel_traits<T, T, Policy>::result_type sph_bessel(unsigned v, T x, const Policy& pol); + + template <class T> + typename detail::bessel_traits<T, T, policies::policy<> >::result_type sph_bessel(unsigned v, T x); + + template <class T1, class T2, class Policy> + typename detail::bessel_traits<T1, T2, Policy>::result_type cyl_bessel_i(T1 v, T2 x, const Policy& pol); + + template <class T1, class T2> + typename detail::bessel_traits<T1, T2, policies::policy<> >::result_type cyl_bessel_i(T1 v, T2 x); + + template <class T1, class T2, class Policy> + typename detail::bessel_traits<T1, T2, Policy>::result_type cyl_bessel_k(T1 v, T2 x, const Policy& pol); + + template <class T1, class T2> + typename detail::bessel_traits<T1, T2, policies::policy<> >::result_type cyl_bessel_k(T1 v, T2 x); + + template <class T1, class T2, class Policy> + typename detail::bessel_traits<T1, T2, Policy>::result_type cyl_neumann(T1 v, T2 x, const Policy& pol); + + template <class T1, class T2> + typename detail::bessel_traits<T1, T2, policies::policy<> >::result_type cyl_neumann(T1 v, T2 x); + + template <class T, class Policy> + typename detail::bessel_traits<T, T, Policy>::result_type sph_neumann(unsigned v, T x, const Policy& pol); + + template <class T> + typename detail::bessel_traits<T, T, policies::policy<> >::result_type sph_neumann(unsigned v, T x); + + template <class T, class Policy> + typename tools::promote_args<T>::type sin_pi(T x, const Policy&); + + template <class T> + typename tools::promote_args<T>::type sin_pi(T x); + + template <class T, class Policy> + typename tools::promote_args<T>::type cos_pi(T x, const Policy&); + + template <class T> + typename tools::promote_args<T>::type cos_pi(T x); + + template <class T> + int fpclassify BOOST_NO_MACRO_EXPAND(T t); + + template <class T> + bool isfinite BOOST_NO_MACRO_EXPAND(T z); + + template <class T> + bool isinf BOOST_NO_MACRO_EXPAND(T t); + + template <class T> + bool isnan BOOST_NO_MACRO_EXPAND(T t); + + template <class T> + bool isnormal BOOST_NO_MACRO_EXPAND(T t); + + // Exponential integrals: + namespace detail{ + + template <class T, class U> + struct expint_result + { + typedef typename mpl::if_< + policies::is_policy<U>, + typename tools::promote_args<T>::type, + typename tools::promote_args<U>::type + >::type type; + }; + + } // namespace detail + + template <class T, class Policy> + typename tools::promote_args<T>::type expint(unsigned n, T z, const Policy&); + + template <class T, class U> + typename detail::expint_result<T, U>::type expint(T const z, U const u); + + template <class T> + typename tools::promote_args<T>::type expint(T z); + + // Zeta: + template <class T, class Policy> + typename tools::promote_args<T>::type zeta(T s, const Policy&); + + template <class T> + typename tools::promote_args<T>::type zeta(T s); + + // pow: + template <int N, typename T, class Policy> + typename tools::promote_args<T>::type pow(T base, const Policy& policy); + + template <int N, typename T> + typename tools::promote_args<T>::type pow(T base); + + // next: + template <class T, class Policy> + T nextafter(const T&, const T&, const Policy&); + template <class T> + T nextafter(const T&, const T&); + template <class T, class Policy> + T float_next(const T&, const Policy&); + template <class T> + T float_next(const T&); + template <class T, class Policy> + T float_prior(const T&, const Policy&); + template <class T> + T float_prior(const T&); + template <class T, class Policy> + T float_distance(const T&, const T&, const Policy&); + template <class T> + T float_distance(const T&, const T&); + + } // namespace math +} // namespace boost + +#ifdef BOOST_HAS_LONG_LONG +#define BOOST_MATH_DETAIL_LL_FUNC(Policy)\ + \ + template <class T>\ + inline T modf(const T& v, boost::long_long_type* ipart){ using boost::math::modf; return modf(v, ipart, Policy()); }\ + \ + template <class T>\ + inline boost::long_long_type lltrunc(const T& v){ using boost::math::lltrunc; return lltrunc(v, Policy()); }\ + \ + template <class T>\ + inline boost::long_long_type llround(const T& v){ using boost::math::llround; return llround(v, Policy()); }\ + +#else +#define BOOST_MATH_DETAIL_LL_FUNC(Policy) +#endif + +#define BOOST_MATH_DECLARE_SPECIAL_FUNCTIONS(Policy)\ + \ + BOOST_MATH_DETAIL_LL_FUNC(Policy)\ + \ + template <class RT1, class RT2>\ + inline typename boost::math::tools::promote_args<RT1, RT2>::type \ + beta(RT1 a, RT2 b) { return ::boost::math::beta(a, b, Policy()); }\ +\ + template <class RT1, class RT2, class A>\ + inline typename boost::math::tools::promote_args<RT1, RT2, A>::type \ + beta(RT1 a, RT2 b, A x){ return ::boost::math::beta(a, b, x, Policy()); }\ +\ + template <class RT1, class RT2, class RT3>\ + inline typename boost::math::tools::promote_args<RT1, RT2, RT3>::type \ + betac(RT1 a, RT2 b, RT3 x) { return ::boost::math::betac(a, b, x, Policy()); }\ +\ + template <class RT1, class RT2, class RT3>\ + inline typename boost::math::tools::promote_args<RT1, RT2, RT3>::type \ + ibeta(RT1 a, RT2 b, RT3 x){ return ::boost::math::ibeta(a, b, x, Policy()); }\ +\ + template <class RT1, class RT2, class RT3>\ + inline typename boost::math::tools::promote_args<RT1, RT2, RT3>::type \ + ibetac(RT1 a, RT2 b, RT3 x){ return ::boost::math::ibetac(a, b, x, Policy()); }\ +\ + template <class T1, class T2, class T3, class T4>\ + inline typename boost::math::tools::promote_args<T1, T2, T3, T4>::type \ + ibeta_inv(T1 a, T2 b, T3 p, T4* py){ return ::boost::math::ibeta_inv(a, b, p, py, Policy()); }\ +\ + template <class RT1, class RT2, class RT3>\ + inline typename boost::math::tools::promote_args<RT1, RT2, RT3>::type \ + ibeta_inv(RT1 a, RT2 b, RT3 p){ return ::boost::math::ibeta_inv(a, b, p, Policy()); }\ +\ + template <class T1, class T2, class T3, class T4>\ + inline typename boost::math::tools::promote_args<T1, T2, T3, T4>::type \ + ibetac_inv(T1 a, T2 b, T3 q, T4* py){ return ::boost::math::ibetac_inv(a, b, q, py, Policy()); }\ +\ + template <class RT1, class RT2, class RT3>\ + inline typename boost::math::tools::promote_args<RT1, RT2, RT3>::type \ + ibeta_inva(RT1 a, RT2 b, RT3 p){ return ::boost::math::ibeta_inva(a, b, p, Policy()); }\ +\ + template <class T1, class T2, class T3>\ + inline typename boost::math::tools::promote_args<T1, T2, T3>::type \ + ibetac_inva(T1 a, T2 b, T3 q){ return ::boost::math::ibetac_inva(a, b, q, Policy()); }\ +\ + template <class RT1, class RT2, class RT3>\ + inline typename boost::math::tools::promote_args<RT1, RT2, RT3>::type \ + ibeta_invb(RT1 a, RT2 b, RT3 p){ return ::boost::math::ibeta_invb(a, b, p, Policy()); }\ +\ + template <class T1, class T2, class T3>\ + inline typename boost::math::tools::promote_args<T1, T2, T3>::type \ + ibetac_invb(T1 a, T2 b, T3 q){ return ::boost::math::ibetac_invb(a, b, q, Policy()); }\ +\ + template <class RT1, class RT2, class RT3>\ + inline typename boost::math::tools::promote_args<RT1, RT2, RT3>::type \ + ibetac_inv(RT1 a, RT2 b, RT3 q){ return ::boost::math::ibetac_inv(a, b, q, Policy()); }\ +\ + template <class RT1, class RT2, class RT3>\ + inline typename boost::math::tools::promote_args<RT1, RT2, RT3>::type \ + ibeta_derivative(RT1 a, RT2 b, RT3 x){ return ::boost::math::ibeta_derivative(a, b, x, Policy()); }\ +\ + template <class RT>\ + inline typename boost::math::tools::promote_args<RT>::type erf(RT z) { return ::boost::math::erf(z, Policy()); }\ +\ + template <class RT>\ + inline typename boost::math::tools::promote_args<RT>::type erfc(RT z){ return ::boost::math::erfc(z, Policy()); }\ +\ + template <class RT>\ + inline typename boost::math::tools::promote_args<RT>::type erf_inv(RT z) { return ::boost::math::erf_inv(z, Policy()); }\ +\ + template <class RT>\ + inline typename boost::math::tools::promote_args<RT>::type erfc_inv(RT z){ return ::boost::math::erfc_inv(z, Policy()); }\ +\ + using boost::math::legendre_next;\ +\ + template <class T>\ + inline typename boost::math::tools::promote_args<T>::type \ + legendre_p(int l, T x){ return ::boost::math::legendre_p(l, x, Policy()); }\ +\ + template <class T>\ + inline typename boost::math::tools::promote_args<T>::type \ + legendre_q(unsigned l, T x){ return ::boost::math::legendre_q(l, x, Policy()); }\ +\ + using ::boost::math::legendre_next;\ +\ + template <class T>\ + inline typename boost::math::tools::promote_args<T>::type \ + legendre_p(int l, int m, T x){ return ::boost::math::legendre_p(l, m, x, Policy()); }\ +\ + using ::boost::math::laguerre_next;\ +\ + template <class T>\ + inline typename boost::math::tools::promote_args<T>::type \ + laguerre(unsigned n, T x){ return ::boost::math::laguerre(n, x, Policy()); }\ +\ + template <class T1, class T2>\ + inline typename boost::math::laguerre_result<T1, T2>::type \ + laguerre(unsigned n, T1 m, T2 x) { return ::boost::math::laguerre(n, m, x, Policy()); }\ +\ + template <class T>\ + inline typename boost::math::tools::promote_args<T>::type \ + hermite(unsigned n, T x){ return ::boost::math::hermite(n, x, Policy()); }\ +\ + using boost::math::hermite_next;\ +\ + template <class T1, class T2>\ + inline std::complex<typename boost::math::tools::promote_args<T1, T2>::type> \ + spherical_harmonic(unsigned n, int m, T1 theta, T2 phi){ return boost::math::spherical_harmonic(n, m, theta, phi, Policy()); }\ +\ + template <class T1, class T2>\ + inline typename boost::math::tools::promote_args<T1, T2>::type \ + spherical_harmonic_r(unsigned n, int m, T1 theta, T2 phi){ return ::boost::math::spherical_harmonic_r(n, m, theta, phi, Policy()); }\ +\ + template <class T1, class T2>\ + inline typename boost::math::tools::promote_args<T1, T2>::type \ + spherical_harmonic_i(unsigned n, int m, T1 theta, T2 phi){ return boost::math::spherical_harmonic_i(n, m, theta, phi, Policy()); }\ +\ + template <class T1, class T2, class Policy>\ + inline typename boost::math::tools::promote_args<T1, T2>::type \ + spherical_harmonic_i(unsigned n, int m, T1 theta, T2 phi, const Policy& pol);\ +\ + template <class T1, class T2, class T3>\ + inline typename boost::math::tools::promote_args<T1, T2, T3>::type \ + ellint_rf(T1 x, T2 y, T3 z){ return ::boost::math::ellint_rf(x, y, z, Policy()); }\ +\ + template <class T1, class T2, class T3>\ + inline typename boost::math::tools::promote_args<T1, T2, T3>::type \ + ellint_rd(T1 x, T2 y, T3 z){ return ::boost::math::ellint_rd(x, y, z, Policy()); }\ +\ + template <class T1, class T2>\ + inline typename boost::math::tools::promote_args<T1, T2>::type \ + ellint_rc(T1 x, T2 y){ return ::boost::math::ellint_rc(x, y, Policy()); }\ +\ + template <class T1, class T2, class T3, class T4>\ + inline typename boost::math::tools::promote_args<T1, T2, T3, T4>::type \ + ellint_rj(T1 x, T2 y, T3 z, T4 p){ return boost::math::ellint_rj(x, y, z, p, Policy()); }\ +\ + template <typename T>\ + inline typename boost::math::tools::promote_args<T>::type ellint_2(T k){ return boost::math::ellint_2(k, Policy()); }\ +\ + template <class T1, class T2>\ + inline typename boost::math::tools::promote_args<T1, T2>::type ellint_2(T1 k, T2 phi){ return boost::math::ellint_2(k, phi, Policy()); }\ +\ + template <typename T>\ + inline typename boost::math::tools::promote_args<T>::type ellint_1(T k){ return boost::math::ellint_1(k, Policy()); }\ +\ + template <class T1, class T2>\ + inline typename boost::math::tools::promote_args<T1, T2>::type ellint_1(T1 k, T2 phi){ return boost::math::ellint_1(k, phi, Policy()); }\ +\ + template <class T1, class T2, class T3>\ + inline typename boost::math::tools::promote_args<T1, T2, T3>::type ellint_3(T1 k, T2 v, T3 phi){ return boost::math::ellint_3(k, v, phi, Policy()); }\ +\ + template <class T1, class T2>\ + inline typename boost::math::tools::promote_args<T1, T2>::type ellint_3(T1 k, T2 v){ return boost::math::ellint_3(k, v, Policy()); }\ +\ + using boost::math::max_factorial;\ + template <class RT>\ + inline RT factorial(unsigned int i) { return boost::math::factorial<RT>(i, Policy()); }\ + using boost::math::unchecked_factorial;\ + template <class RT>\ + inline RT double_factorial(unsigned i){ return boost::math::double_factorial<RT>(i, Policy()); }\ + template <class RT>\ + inline typename boost::math::tools::promote_args<RT>::type falling_factorial(RT x, unsigned n){ return boost::math::falling_factorial(x, n, Policy()); }\ + template <class RT>\ + inline typename boost::math::tools::promote_args<RT>::type rising_factorial(RT x, unsigned n){ return boost::math::rising_factorial(x, n, Policy()); }\ + using boost::math::fpclassify;\ +\ + template <class RT>\ + inline typename boost::math::tools::promote_args<RT>::type tgamma(RT z){ return boost::math::tgamma(z, Policy()); }\ +\ + template <class RT>\ + inline typename boost::math::tools::promote_args<RT>::type tgamma1pm1(RT z){ return boost::math::tgamma1pm1(z, Policy()); }\ +\ + template <class RT1, class RT2>\ + inline typename boost::math::tools::promote_args<RT1, RT2>::type tgamma(RT1 a, RT2 z){ return boost::math::tgamma(a, z, Policy()); }\ +\ + template <class RT>\ + inline typename boost::math::tools::promote_args<RT>::type lgamma(RT z, int* sign){ return boost::math::lgamma(z, sign, Policy()); }\ +\ + template <class RT>\ + inline typename boost::math::tools::promote_args<RT>::type lgamma(RT x){ return boost::math::lgamma(x, Policy()); }\ +\ + template <class RT1, class RT2>\ + inline typename boost::math::tools::promote_args<RT1, RT2>::type tgamma_lower(RT1 a, RT2 z){ return boost::math::tgamma_lower(a, z, Policy()); }\ +\ + template <class RT1, class RT2>\ + inline typename boost::math::tools::promote_args<RT1, RT2>::type gamma_q(RT1 a, RT2 z){ return boost::math::gamma_q(a, z, Policy()); }\ +\ + template <class RT1, class RT2>\ + inline typename boost::math::tools::promote_args<RT1, RT2>::type gamma_p(RT1 a, RT2 z){ return boost::math::gamma_p(a, z, Policy()); }\ +\ + template <class T1, class T2>\ + inline typename boost::math::tools::promote_args<T1, T2>::type tgamma_delta_ratio(T1 z, T2 delta){ return boost::math::tgamma_delta_ratio(z, delta, Policy()); }\ +\ + template <class T1, class T2>\ + inline typename boost::math::tools::promote_args<T1, T2>::type tgamma_ratio(T1 a, T2 b) { return boost::math::tgamma_ratio(a, b, Policy()); }\ +\ + template <class T1, class T2>\ + inline typename boost::math::tools::promote_args<T1, T2>::type gamma_p_derivative(T1 a, T2 x){ return boost::math::gamma_p_derivative(a, x, Policy()); }\ +\ + template <class T1, class T2>\ + inline typename boost::math::tools::promote_args<T1, T2>::type gamma_p_inv(T1 a, T2 p){ return boost::math::gamma_p_inv(a, p, Policy()); }\ +\ + template <class T1, class T2>\ + inline typename boost::math::tools::promote_args<T1, T2>::type gamma_p_inva(T1 a, T2 p){ return boost::math::gamma_p_inva(a, p, Policy()); }\ +\ + template <class T1, class T2>\ + inline typename boost::math::tools::promote_args<T1, T2>::type gamma_q_inv(T1 a, T2 q){ return boost::math::gamma_q_inv(a, q, Policy()); }\ +\ + template <class T1, class T2>\ + inline typename boost::math::tools::promote_args<T1, T2>::type gamma_q_inva(T1 a, T2 q){ return boost::math::gamma_q_inva(a, q, Policy()); }\ +\ + template <class T>\ + inline typename boost::math::tools::promote_args<T>::type digamma(T x){ return boost::math::digamma(x, Policy()); }\ +\ + template <class T1, class T2>\ + inline typename boost::math::tools::promote_args<T1, T2>::type \ + hypot(T1 x, T2 y){ return boost::math::hypot(x, y, Policy()); }\ +\ + template <class RT>\ + inline typename boost::math::tools::promote_args<RT>::type cbrt(RT z){ return boost::math::cbrt(z, Policy()); }\ +\ + template <class T>\ + inline typename boost::math::tools::promote_args<T>::type log1p(T x){ return boost::math::log1p(x, Policy()); }\ +\ + template <class T>\ + inline typename boost::math::tools::promote_args<T>::type log1pmx(T x){ return boost::math::log1pmx(x, Policy()); }\ +\ + template <class T>\ + inline typename boost::math::tools::promote_args<T>::type expm1(T x){ return boost::math::expm1(x, Policy()); }\ +\ + template <class T1, class T2>\ + inline typename boost::math::tools::promote_args<T1, T2>::type \ + powm1(const T1 a, const T2 z){ return boost::math::powm1(a, z, Policy()); }\ +\ + template <class T>\ + inline typename boost::math::tools::promote_args<T>::type sqrt1pm1(const T& val){ return boost::math::sqrt1pm1(val, Policy()); }\ +\ + template <class T>\ + inline typename boost::math::tools::promote_args<T>::type sinc_pi(T x){ return boost::math::sinc_pi(x, Policy()); }\ +\ + template <class T>\ + inline typename boost::math::tools::promote_args<T>::type sinhc_pi(T x){ return boost::math::sinhc_pi(x, Policy()); }\ +\ + template<typename T>\ + inline typename boost::math::tools::promote_args<T>::type asinh(const T x){ return boost::math::asinh(x, Policy()); }\ +\ + template<typename T>\ + inline typename boost::math::tools::promote_args<T>::type acosh(const T x){ return boost::math::acosh(x, Policy()); }\ +\ + template<typename T>\ + inline typename boost::math::tools::promote_args<T>::type atanh(const T x){ return boost::math::atanh(x, Policy()); }\ +\ + template <class T1, class T2>\ + inline typename boost::math::detail::bessel_traits<T1, T2, Policy >::result_type cyl_bessel_j(T1 v, T2 x)\ + { return boost::math::cyl_bessel_j(v, x, Policy()); }\ +\ + template <class T>\ + inline typename boost::math::detail::bessel_traits<T, T, Policy >::result_type sph_bessel(unsigned v, T x)\ + { return boost::math::sph_bessel(v, x, Policy()); }\ +\ + template <class T1, class T2>\ + inline typename boost::math::detail::bessel_traits<T1, T2, Policy >::result_type \ + cyl_bessel_i(T1 v, T2 x) { return boost::math::cyl_bessel_i(v, x, Policy()); }\ +\ + template <class T1, class T2>\ + inline typename boost::math::detail::bessel_traits<T1, T2, Policy >::result_type \ + cyl_bessel_k(T1 v, T2 x) { return boost::math::cyl_bessel_k(v, x, Policy()); }\ +\ + template <class T1, class T2>\ + inline typename boost::math::detail::bessel_traits<T1, T2, Policy >::result_type \ + cyl_neumann(T1 v, T2 x){ return boost::math::cyl_neumann(v, x, Policy()); }\ +\ + template <class T>\ + inline typename boost::math::detail::bessel_traits<T, T, Policy >::result_type \ + sph_neumann(unsigned v, T x){ return boost::math::sph_neumann(v, x, Policy()); }\ +\ + template <class T>\ + inline typename boost::math::tools::promote_args<T>::type sin_pi(T x){ return boost::math::sin_pi(x); }\ +\ + template <class T>\ + inline typename boost::math::tools::promote_args<T>::type cos_pi(T x){ return boost::math::cos_pi(x); }\ +\ + using boost::math::fpclassify;\ + using boost::math::isfinite;\ + using boost::math::isinf;\ + using boost::math::isnan;\ + using boost::math::isnormal;\ + \ + template <class T, class U>\ + inline typename boost::math::tools::promote_args<T,U>::type expint(T const& z, U const& u)\ + { return boost::math::expint(z, u, Policy()); }\ + \ + template <class T>\ + inline typename boost::math::tools::promote_args<T>::type expint(T z){ return boost::math::expint(z, Policy()); }\ + \ + template <class T>\ + inline typename boost::math::tools::promote_args<T>::type zeta(T s){ return boost::math::zeta(s, Policy()); }\ + \ + template <class T>\ + inline T round(const T& v){ using boost::math::round; return round(v, Policy()); }\ + \ + template <class T>\ + inline int iround(const T& v){ using boost::math::iround; return iround(v, Policy()); }\ + \ + template <class T>\ + inline long lround(const T& v){ using boost::math::lround; return lround(v, Policy()); }\ + \ + template <class T>\ + inline T trunc(const T& v){ using boost::math::trunc; return trunc(v, Policy()); }\ + \ + template <class T>\ + inline int itrunc(const T& v){ using boost::math::itrunc; return itrunc(v, Policy()); }\ + \ + template <class T>\ + inline long ltrunc(const T& v){ using boost::math::ltrunc; return ltrunc(v, Policy()); }\ + \ + template <class T>\ + inline T modf(const T& v, T* ipart){ using boost::math::modf; return modf(v, ipart, Policy()); }\ + \ + template <class T>\ + inline T modf(const T& v, int* ipart){ using boost::math::modf; return modf(v, ipart, Policy()); }\ + \ + template <class T>\ + inline T modf(const T& v, long* ipart){ using boost::math::modf; return modf(v, ipart, Policy()); }\ + \ + template <int N, class T>\ + inline typename boost::math::tools::promote_args<T>::type pow(T v){ return boost::math::pow<N>(v, Policy()); }\ + \ + template <class T> T nextafter(const T& a, const T& b){ return boost::math::nextafter(a, b, Policy()); }\ + template <class T> T float_next(const T& a){ return boost::math::float_next(a, Policy()); }\ + template <class T> T float_prior(const T& a){ return boost::math::float_prior(a, Policy()); }\ + template <class T> T float_distance(const T& a, const T& b){ return boost::math::float_distance(a, b, Policy()); }\ + + +#endif // BOOST_MATH_SPECIAL_MATH_FWD_HPP + + diff --git a/Utilities/BGL/boost/math/special_functions/modf.hpp b/Utilities/BGL/boost/math/special_functions/modf.hpp new file mode 100644 index 0000000000000000000000000000000000000000..23ef3a2a59c4c81e1dadd6ce6f485e926a403270 --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/modf.hpp @@ -0,0 +1,70 @@ +// Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_MODF_HPP +#define BOOST_MATH_MODF_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/math/tools/config.hpp> +#include <boost/math/special_functions/trunc.hpp> + +namespace boost{ namespace math{ + +template <class T, class Policy> +inline T modf(const T& v, T* ipart, const Policy& pol) +{ + *ipart = trunc(v, pol); + return v - *ipart; +} +template <class T> +inline T modf(const T& v, T* ipart) +{ + return modf(v, ipart, policies::policy<>()); +} + +template <class T, class Policy> +inline T modf(const T& v, int* ipart, const Policy& pol) +{ + *ipart = itrunc(v, pol); + return v - *ipart; +} +template <class T> +inline T modf(const T& v, int* ipart) +{ + return modf(v, ipart, policies::policy<>()); +} + +template <class T, class Policy> +inline T modf(const T& v, long* ipart, const Policy& pol) +{ + *ipart = ltrunc(v, pol); + return v - *ipart; +} +template <class T> +inline T modf(const T& v, long* ipart) +{ + return modf(v, ipart, policies::policy<>()); +} + +#ifdef BOOST_HAS_LONG_LONG +template <class T, class Policy> +inline T modf(const T& v, boost::long_long_type* ipart, const Policy& pol) +{ + *ipart = lltrunc(v, pol); + return v - *ipart; +} +template <class T> +inline T modf(const T& v, boost::long_long_type* ipart) +{ + return modf(v, ipart, policies::policy<>()); +} +#endif + +}} // namespaces + +#endif // BOOST_MATH_MODF_HPP diff --git a/Utilities/BGL/boost/math/special_functions/next.hpp b/Utilities/BGL/boost/math/special_functions/next.hpp new file mode 100644 index 0000000000000000000000000000000000000000..f664537d6ce0f4b1587ab5f8c59c378f5a1c695e --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/next.hpp @@ -0,0 +1,313 @@ +// (C) Copyright John Maddock 2008. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_SPECIAL_NEXT_HPP +#define BOOST_MATH_SPECIAL_NEXT_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/math/policies/error_handling.hpp> +#include <boost/math/special_functions/fpclassify.hpp> +#include <boost/math/special_functions/sign.hpp> +#include <boost/math/special_functions/trunc.hpp> + +#ifdef BOOST_MSVC +#include <float.h> +#endif + +namespace boost{ namespace math{ + +namespace detail{ + +template <class T> +inline T get_smallest_value(mpl::true_ const&) +{ + return std::numeric_limits<T>::denorm_min(); +} + +template <class T> +inline T get_smallest_value(mpl::false_ const&) +{ + return tools::min_value<T>(); +} + +template <class T> +inline T get_smallest_value() +{ +#if defined(BOOST_MSVC) && (BOOST_MSVC <= 1310) + return get_smallest_value<T>(mpl::bool_<std::numeric_limits<T>::is_specialized && (std::numeric_limits<T>::has_denorm == 1)>()); +#else + return get_smallest_value<T>(mpl::bool_<std::numeric_limits<T>::is_specialized && (std::numeric_limits<T>::has_denorm == std::denorm_present)>()); +#endif +} + +} + +template <class T, class Policy> +T float_next(const T& val, const Policy& pol) +{ + BOOST_MATH_STD_USING + int expon; + static const char* function = "float_next<%1%>(%1%)"; + + if(!(boost::math::isfinite)(val)) + return policies::raise_domain_error<T>( + function, + "Argument must be finite, but got %1%", val, pol); + + if(val >= tools::max_value<T>()) + return policies::raise_overflow_error<T>(function, 0, pol); + + if(val == 0) + return detail::get_smallest_value<T>(); + + if(-0.5f == frexp(val, &expon)) + --expon; // reduce exponent when val is a power of two, and negative. + T diff = ldexp(T(1), expon - tools::digits<T>()); + if(diff == 0) + diff = detail::get_smallest_value<T>(); + return val + diff; +} + +#ifdef BOOST_MSVC +template <class Policy> +inline double float_next(const double& val, const Policy& pol) +{ + static const char* function = "float_next<%1%>(%1%)"; + + if(!(boost::math::isfinite)(val)) + return policies::raise_domain_error<double>( + function, + "Argument must be finite, but got %1%", val, pol); + + if(val >= tools::max_value<double>()) + return policies::raise_overflow_error<double>(function, 0, pol); + + return ::_nextafter(val, tools::max_value<double>()); +} +#endif + +template <class T> +inline T float_next(const T& val) +{ + return float_next(val, policies::policy<>()); +} + +template <class T, class Policy> +T float_prior(const T& val, const Policy& pol) +{ + BOOST_MATH_STD_USING + int expon; + static const char* function = "float_prior<%1%>(%1%)"; + + if(!(boost::math::isfinite)(val)) + return policies::raise_domain_error<T>( + function, + "Argument must be finite, but got %1%", val, pol); + + if(val <= -tools::max_value<T>()) + return -policies::raise_overflow_error<T>(function, 0, pol); + + if(val == 0) + return -detail::get_smallest_value<T>(); + + T remain = frexp(val, &expon); + if(remain == 0.5) + --expon; // when val is a power of two we must reduce the exponent + T diff = ldexp(T(1), expon - tools::digits<T>()); + if(diff == 0) + diff = detail::get_smallest_value<T>(); + return val - diff; +} + +#ifdef BOOST_MSVC +template <class Policy> +inline double float_prior(const double& val, const Policy& pol) +{ + static const char* function = "float_prior<%1%>(%1%)"; + + if(!(boost::math::isfinite)(val)) + return policies::raise_domain_error<double>( + function, + "Argument must be finite, but got %1%", val, pol); + + if(val <= -tools::max_value<double>()) + return -policies::raise_overflow_error<double>(function, 0, pol); + + return ::_nextafter(val, -tools::max_value<double>()); +} +#endif + +template <class T> +inline T float_prior(const T& val) +{ + return float_prior(val, policies::policy<>()); +} + +template <class T, class Policy> +inline T nextafter(const T& val, const T& direction, const Policy& pol) +{ + return val < direction ? boost::math::float_next(val, pol) : val == direction ? val : boost::math::float_prior(val, pol); +} + +template <class T> +inline T nextafter(const T& val, const T& direction) +{ + return nextafter(val, direction, policies::policy<>()); +} + +template <class T, class Policy> +T float_distance(const T& a, const T& b, const Policy& pol) +{ + BOOST_MATH_STD_USING + // + // Error handling: + // + static const char* function = "float_distance<%1%>(%1%, %1%)"; + if(!(boost::math::isfinite)(a)) + return policies::raise_domain_error<T>( + function, + "Argument a must be finite, but got %1%", a, pol); + if(!(boost::math::isfinite)(b)) + return policies::raise_domain_error<T>( + function, + "Argument b must be finite, but got %1%", b, pol); + // + // Special cases: + // + if(a > b) + return -float_distance(b, a); + if(a == b) + return 0; + if(a == 0) + return 1 + fabs(float_distance(static_cast<T>(boost::math::sign(b) * detail::get_smallest_value<T>()), b, pol)); + if(b == 0) + return 1 + fabs(float_distance(static_cast<T>(boost::math::sign(a) * detail::get_smallest_value<T>()), a, pol)); + if(boost::math::sign(a) != boost::math::sign(b)) + return 2 + fabs(float_distance(static_cast<T>(boost::math::sign(b) * detail::get_smallest_value<T>()), b, pol)) + + fabs(float_distance(static_cast<T>(boost::math::sign(a) * detail::get_smallest_value<T>()), a, pol)); + // + // By the time we get here, both a and b must have the same sign, we want + // b > a and both postive for the following logic: + // + if(a < 0) + return float_distance(static_cast<T>(-b), static_cast<T>(-a)); + + BOOST_ASSERT(a >= 0); + BOOST_ASSERT(b >= a); + + BOOST_MATH_STD_USING + int expon; + // + // Note that if a is a denorm then the usual formula fails + // because we actually have fewer than tools::digits<T>() + // significant bits in the representation: + // + frexp(((boost::math::fpclassify)(a) == FP_SUBNORMAL) ? tools::min_value<T>() : a, &expon); + T upper = ldexp(T(1), expon); + T result = 0; + expon = tools::digits<T>() - expon; + // + // If b is greater than upper, then we *must* split the calculation + // as the size of the ULP changes with each order of magnitude change: + // + if(b > upper) + { + result = float_distance(upper, b); + } + // + // Use compensated double-double addition to avoid rounding + // errors in the subtraction: + // + T mb = -(std::min)(upper, b); + T x = a + mb; + T z = x - a; + T y = (a - (x - z)) + (mb - z); + if(x < 0) + { + x = -x; + y = -y; + } + result += ldexp(x, expon) + ldexp(y, expon); + // + // Result must be an integer: + // + BOOST_ASSERT(result == floor(result)); + return result; +} + +template <class T> +T float_distance(const T& a, const T& b) +{ + return boost::math::float_distance(a, b, policies::policy<>()); +} + +template <class T, class Policy> +T float_advance(T val, int distance, const Policy& pol) +{ + // + // Error handling: + // + static const char* function = "float_advance<%1%>(%1%, int)"; + if(!(boost::math::isfinite)(val)) + return policies::raise_domain_error<T>( + function, + "Argument val must be finite, but got %1%", val, pol); + + if(val < 0) + return -float_advance(-val, -distance, pol); + if(distance == 0) + return val; + if(distance == 1) + return float_next(val, pol); + if(distance == -1) + return float_prior(val, pol); + BOOST_MATH_STD_USING + int expon; + frexp(val, &expon); + T limit = ldexp((distance < 0 ? T(0.5f) : T(1)), expon); + if(val <= tools::min_value<T>()) + { + limit = sign(T(distance)) * tools::min_value<T>(); + } + T limit_distance = float_distance(val, limit); + while(fabs(limit_distance) < abs(distance)) + { + distance -= itrunc(limit_distance); + val = limit; + if(distance < 0) + { + limit /= 2; + expon--; + } + else + { + limit *= 2; + expon++; + } + limit_distance = float_distance(val, limit); + } + if((0.5f == frexp(val, &expon)) && (distance < 0)) + --expon; + T diff = 0; + if(val != 0) + diff = distance * ldexp(T(1), expon - tools::digits<T>()); + if(diff == 0) + diff = distance * detail::get_smallest_value<T>(); + return val += diff; +} + +template <class T> +inline T float_advance(const T& val, int distance) +{ + return boost::math::float_advance(val, distance, policies::policy<>()); +} + +}} // namespaces + +#endif // BOOST_MATH_SPECIAL_NEXT_HPP + diff --git a/Utilities/BGL/boost/math/special_functions/pow.hpp b/Utilities/BGL/boost/math/special_functions/pow.hpp new file mode 100644 index 0000000000000000000000000000000000000000..080a4f9c2a1c7c548d20402bee0838ac334a34ba --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/pow.hpp @@ -0,0 +1,142 @@ +// Boost pow.hpp header file +// Computes a power with exponent known at compile-time + +// (C) Copyright Bruno Lalande 2008. +// 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) + +// See http://www.boost.org for updates, documentation, and revision history. + + +#ifndef BOOST_MATH_POW_HPP +#define BOOST_MATH_POW_HPP + + +#include <boost/math/policies/policy.hpp> +#include <boost/math/policies/error_handling.hpp> +#include <boost/math/tools/promotion.hpp> +#include <boost/mpl/greater_equal.hpp> + + +namespace boost { +namespace math { + + +namespace detail { + + +template <int N, int M = N%2> +struct positive_power +{ + template <typename T> + static typename tools::promote_args<T>::type result(T base) + { + typename tools::promote_args<T>::type power = + positive_power<N/2>::result(base); + return power * power; + } +}; + +template <int N> +struct positive_power<N, 1> +{ + template <typename T> + static typename tools::promote_args<T>::type result(T base) + { + typename tools::promote_args<T>::type power = + positive_power<N/2>::result(base); + return base * power * power; + } +}; + +template <> +struct positive_power<1, 1> +{ + template <typename T> + static typename tools::promote_args<T>::type result(T base) + { return base; } +}; + + +template <int N, bool> +struct power_if_positive +{ + template <typename T, class Policy> + static typename tools::promote_args<T>::type result(T base, const Policy&) + { return positive_power<N>::result(base); } +}; + +template <int N> +struct power_if_positive<N, false> +{ + template <typename T, class Policy> + static typename tools::promote_args<T>::type + result(T base, const Policy& policy) + { + if (base == 0) + { + return policies::raise_overflow_error<T>( + "boost::math::pow(%1%)", + "Attempted to compute a negative power of 0", + policy + ); + } + + return T(1) / positive_power<-N>::result(base); + } +}; + +template <> +struct power_if_positive<0, true> +{ + template <typename T, class Policy> + static typename tools::promote_args<T>::type + result(T base, const Policy& policy) + { + if (base == 0) + { + return policies::raise_indeterminate_result_error<T>( + "boost::math::pow(%1%)", + "The result of pow<0>(%1%) is undetermined", + base, + T(1), + policy + ); + } + + return T(1); + } +}; + + +template <int N> +struct select_power_if_positive +{ + typedef typename mpl::greater_equal< + mpl::int_<N>, + mpl::int_<0> + >::type is_positive; + + typedef power_if_positive<N, is_positive::value> type; +}; + + +} // namespace detail + + +template <int N, typename T, class Policy> +inline typename tools::promote_args<T>::type pow(T base, const Policy& policy) +{ return detail::select_power_if_positive<N>::type::result(base, policy); } + + +template <int N, typename T> +inline typename tools::promote_args<T>::type pow(T base) +{ return pow<N>(base, policies::policy<>()); } + + +} // namespace math +} // namespace boost + + +#endif diff --git a/Utilities/BGL/boost/math/special_functions/powm1.hpp b/Utilities/BGL/boost/math/special_functions/powm1.hpp new file mode 100644 index 0000000000000000000000000000000000000000..f065708a7956a54d610d45df24f69bc558563ef4 --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/powm1.hpp @@ -0,0 +1,61 @@ +// (C) Copyright John Maddock 2006. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_POWM1 +#define BOOST_MATH_POWM1 + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/math/special_functions/log1p.hpp> +#include <boost/math/special_functions/expm1.hpp> +#include <boost/math/special_functions/math_fwd.hpp> +#include <boost/assert.hpp> + +namespace boost{ namespace math{ namespace detail{ + +template <class T, class Policy> +inline T powm1_imp(const T a, const T z, const Policy& pol) +{ + BOOST_MATH_STD_USING + + if((fabs(a) < 1) || (fabs(z) < 1)) + { + T p = log(a) * z; + if(fabs(p) < 2) + return boost::math::expm1(p, pol); + // otherwise fall though: + } + return pow(a, z) - 1; +} + +} // detail + +template <class T1, class T2> +inline typename tools::promote_args<T1, T2>::type + powm1(const T1 a, const T2 z) +{ + typedef typename tools::promote_args<T1, T2>::type result_type; + return detail::powm1_imp(static_cast<result_type>(a), static_cast<result_type>(z), policies::policy<>()); +} + +template <class T1, class T2, class Policy> +inline typename tools::promote_args<T1, T2>::type + powm1(const T1 a, const T2 z, const Policy& pol) +{ + typedef typename tools::promote_args<T1, T2>::type result_type; + return detail::powm1_imp(static_cast<result_type>(a), static_cast<result_type>(z), pol); +} + +} // namespace math +} // namespace boost + +#endif // BOOST_MATH_POWM1 + + + + + diff --git a/Utilities/BGL/boost/math/special_functions/prime.hpp b/Utilities/BGL/boost/math/special_functions/prime.hpp new file mode 100644 index 0000000000000000000000000000000000000000..8e56d729f434eb3fbab2b1b85c07f5577a630c9f --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/prime.hpp @@ -0,0 +1,1214 @@ +// Copyright 2008 John Maddock +// +// Use, modification and distribution are subject to 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) + +#include <boost/array.hpp> +#include <boost/cstdint.hpp> +#include <boost/math/policies/error_handling.hpp> + +namespace boost{ namespace math{ + + template <class Policy> + boost::uint32_t prime(unsigned n, const Policy& pol) + { + // + // This is basically three big tables which together + // occupy 19946 bytes, we use the smallest type which + // will handle each value, and store the final set of + // values in a uint16_t with the values offset by 0xffff. + // That gives us the first 10000 primes with the largest + // being 104729: + // + static const unsigned b1 = 53; + static const unsigned b2 = 6541; + static const unsigned b3 = 10000; + static const boost::array<unsigned char, 54> a1 = { + 2u, 3u, 5u, 7u, 11u, 13u, 17u, 19u, 23u, 29u, 31u, + 37u, 41u, 43u, 47u, 53u, 59u, 61u, 67u, 71u, 73u, + 79u, 83u, 89u, 97u, 101u, 103u, 107u, 109u, 113u, + 127u, 131u, 137u, 139u, 149u, 151u, 157u, 163u, + 167u, 173u, 179u, 181u, 191u, 193u, 197u, 199u, + 211u, 223u, 227u, 229u, 233u, 239u, 241u, 251u + }; + static const boost::array<boost::uint16_t, 6488> a2 = { + 257u, 263u, 269u, 271u, 277u, 281u, 283u, 293u, + 307u, 311u, 313u, 317u, 331u, 337u, 347u, 349u, 353u, + 359u, 367u, 373u, 379u, 383u, 389u, 397u, 401u, 409u, + 419u, 421u, 431u, 433u, 439u, 443u, 449u, 457u, 461u, + 463u, 467u, 479u, 487u, 491u, 499u, 503u, 509u, 521u, + 523u, 541u, 547u, 557u, 563u, 569u, 571u, 577u, 587u, + 593u, 599u, 601u, 607u, 613u, 617u, 619u, 631u, 641u, + 643u, 647u, 653u, 659u, 661u, 673u, 677u, 683u, 691u, + 701u, 709u, 719u, 727u, 733u, 739u, 743u, 751u, 757u, + 761u, 769u, 773u, 787u, 797u, 809u, 811u, 821u, 823u, + 827u, 829u, 839u, 853u, 857u, 859u, 863u, 877u, 881u, + 883u, 887u, 907u, 911u, 919u, 929u, 937u, 941u, 947u, + 953u, 967u, 971u, 977u, 983u, 991u, 997u, 1009u, 1013u, + 1019u, 1021u, 1031u, 1033u, 1039u, 1049u, 1051u, 1061u, 1063u, + 1069u, 1087u, 1091u, 1093u, 1097u, 1103u, 1109u, 1117u, 1123u, + 1129u, 1151u, 1153u, 1163u, 1171u, 1181u, 1187u, 1193u, 1201u, + 1213u, 1217u, 1223u, 1229u, 1231u, 1237u, 1249u, 1259u, 1277u, + 1279u, 1283u, 1289u, 1291u, 1297u, 1301u, 1303u, 1307u, 1319u, + 1321u, 1327u, 1361u, 1367u, 1373u, 1381u, 1399u, 1409u, 1423u, + 1427u, 1429u, 1433u, 1439u, 1447u, 1451u, 1453u, 1459u, 1471u, + 1481u, 1483u, 1487u, 1489u, 1493u, 1499u, 1511u, 1523u, 1531u, + 1543u, 1549u, 1553u, 1559u, 1567u, 1571u, 1579u, 1583u, 1597u, + 1601u, 1607u, 1609u, 1613u, 1619u, 1621u, 1627u, 1637u, 1657u, + 1663u, 1667u, 1669u, 1693u, 1697u, 1699u, 1709u, 1721u, 1723u, + 1733u, 1741u, 1747u, 1753u, 1759u, 1777u, 1783u, 1787u, 1789u, + 1801u, 1811u, 1823u, 1831u, 1847u, 1861u, 1867u, 1871u, 1873u, + 1877u, 1879u, 1889u, 1901u, 1907u, 1913u, 1931u, 1933u, 1949u, + 1951u, 1973u, 1979u, 1987u, 1993u, 1997u, 1999u, 2003u, 2011u, + 2017u, 2027u, 2029u, 2039u, 2053u, 2063u, 2069u, 2081u, 2083u, + 2087u, 2089u, 2099u, 2111u, 2113u, 2129u, 2131u, 2137u, 2141u, + 2143u, 2153u, 2161u, 2179u, 2203u, 2207u, 2213u, 2221u, 2237u, + 2239u, 2243u, 2251u, 2267u, 2269u, 2273u, 2281u, 2287u, 2293u, + 2297u, 2309u, 2311u, 2333u, 2339u, 2341u, 2347u, 2351u, 2357u, + 2371u, 2377u, 2381u, 2383u, 2389u, 2393u, 2399u, 2411u, 2417u, + 2423u, 2437u, 2441u, 2447u, 2459u, 2467u, 2473u, 2477u, 2503u, + 2521u, 2531u, 2539u, 2543u, 2549u, 2551u, 2557u, 2579u, 2591u, + 2593u, 2609u, 2617u, 2621u, 2633u, 2647u, 2657u, 2659u, 2663u, + 2671u, 2677u, 2683u, 2687u, 2689u, 2693u, 2699u, 2707u, 2711u, + 2713u, 2719u, 2729u, 2731u, 2741u, 2749u, 2753u, 2767u, 2777u, + 2789u, 2791u, 2797u, 2801u, 2803u, 2819u, 2833u, 2837u, 2843u, + 2851u, 2857u, 2861u, 2879u, 2887u, 2897u, 2903u, 2909u, 2917u, + 2927u, 2939u, 2953u, 2957u, 2963u, 2969u, 2971u, 2999u, 3001u, + 3011u, 3019u, 3023u, 3037u, 3041u, 3049u, 3061u, 3067u, 3079u, + 3083u, 3089u, 3109u, 3119u, 3121u, 3137u, 3163u, 3167u, 3169u, + 3181u, 3187u, 3191u, 3203u, 3209u, 3217u, 3221u, 3229u, 3251u, + 3253u, 3257u, 3259u, 3271u, 3299u, 3301u, 3307u, 3313u, 3319u, + 3323u, 3329u, 3331u, 3343u, 3347u, 3359u, 3361u, 3371u, 3373u, + 3389u, 3391u, 3407u, 3413u, 3433u, 3449u, 3457u, 3461u, 3463u, + 3467u, 3469u, 3491u, 3499u, 3511u, 3517u, 3527u, 3529u, 3533u, + 3539u, 3541u, 3547u, 3557u, 3559u, 3571u, 3581u, 3583u, 3593u, + 3607u, 3613u, 3617u, 3623u, 3631u, 3637u, 3643u, 3659u, 3671u, + 3673u, 3677u, 3691u, 3697u, 3701u, 3709u, 3719u, 3727u, 3733u, + 3739u, 3761u, 3767u, 3769u, 3779u, 3793u, 3797u, 3803u, 3821u, + 3823u, 3833u, 3847u, 3851u, 3853u, 3863u, 3877u, 3881u, 3889u, + 3907u, 3911u, 3917u, 3919u, 3923u, 3929u, 3931u, 3943u, 3947u, + 3967u, 3989u, 4001u, 4003u, 4007u, 4013u, 4019u, 4021u, 4027u, + 4049u, 4051u, 4057u, 4073u, 4079u, 4091u, 4093u, 4099u, 4111u, + 4127u, 4129u, 4133u, 4139u, 4153u, 4157u, 4159u, 4177u, 4201u, + 4211u, 4217u, 4219u, 4229u, 4231u, 4241u, 4243u, 4253u, 4259u, + 4261u, 4271u, 4273u, 4283u, 4289u, 4297u, 4327u, 4337u, 4339u, + 4349u, 4357u, 4363u, 4373u, 4391u, 4397u, 4409u, 4421u, 4423u, + 4441u, 4447u, 4451u, 4457u, 4463u, 4481u, 4483u, 4493u, 4507u, + 4513u, 4517u, 4519u, 4523u, 4547u, 4549u, 4561u, 4567u, 4583u, + 4591u, 4597u, 4603u, 4621u, 4637u, 4639u, 4643u, 4649u, 4651u, + 4657u, 4663u, 4673u, 4679u, 4691u, 4703u, 4721u, 4723u, 4729u, + 4733u, 4751u, 4759u, 4783u, 4787u, 4789u, 4793u, 4799u, 4801u, + 4813u, 4817u, 4831u, 4861u, 4871u, 4877u, 4889u, 4903u, 4909u, + 4919u, 4931u, 4933u, 4937u, 4943u, 4951u, 4957u, 4967u, 4969u, + 4973u, 4987u, 4993u, 4999u, 5003u, 5009u, 5011u, 5021u, 5023u, + 5039u, 5051u, 5059u, 5077u, 5081u, 5087u, 5099u, 5101u, 5107u, + 5113u, 5119u, 5147u, 5153u, 5167u, 5171u, 5179u, 5189u, 5197u, + 5209u, 5227u, 5231u, 5233u, 5237u, 5261u, 5273u, 5279u, 5281u, + 5297u, 5303u, 5309u, 5323u, 5333u, 5347u, 5351u, 5381u, 5387u, + 5393u, 5399u, 5407u, 5413u, 5417u, 5419u, 5431u, 5437u, 5441u, + 5443u, 5449u, 5471u, 5477u, 5479u, 5483u, 5501u, 5503u, 5507u, + 5519u, 5521u, 5527u, 5531u, 5557u, 5563u, 5569u, 5573u, 5581u, + 5591u, 5623u, 5639u, 5641u, 5647u, 5651u, 5653u, 5657u, 5659u, + 5669u, 5683u, 5689u, 5693u, 5701u, 5711u, 5717u, 5737u, 5741u, + 5743u, 5749u, 5779u, 5783u, 5791u, 5801u, 5807u, 5813u, 5821u, + 5827u, 5839u, 5843u, 5849u, 5851u, 5857u, 5861u, 5867u, 5869u, + 5879u, 5881u, 5897u, 5903u, 5923u, 5927u, 5939u, 5953u, 5981u, + 5987u, 6007u, 6011u, 6029u, 6037u, 6043u, 6047u, 6053u, 6067u, + 6073u, 6079u, 6089u, 6091u, 6101u, 6113u, 6121u, 6131u, 6133u, + 6143u, 6151u, 6163u, 6173u, 6197u, 6199u, 6203u, 6211u, 6217u, + 6221u, 6229u, 6247u, 6257u, 6263u, 6269u, 6271u, 6277u, 6287u, + 6299u, 6301u, 6311u, 6317u, 6323u, 6329u, 6337u, 6343u, 6353u, + 6359u, 6361u, 6367u, 6373u, 6379u, 6389u, 6397u, 6421u, 6427u, + 6449u, 6451u, 6469u, 6473u, 6481u, 6491u, 6521u, 6529u, 6547u, + 6551u, 6553u, 6563u, 6569u, 6571u, 6577u, 6581u, 6599u, 6607u, + 6619u, 6637u, 6653u, 6659u, 6661u, 6673u, 6679u, 6689u, 6691u, + 6701u, 6703u, 6709u, 6719u, 6733u, 6737u, 6761u, 6763u, 6779u, + 6781u, 6791u, 6793u, 6803u, 6823u, 6827u, 6829u, 6833u, 6841u, + 6857u, 6863u, 6869u, 6871u, 6883u, 6899u, 6907u, 6911u, 6917u, + 6947u, 6949u, 6959u, 6961u, 6967u, 6971u, 6977u, 6983u, 6991u, + 6997u, 7001u, 7013u, 7019u, 7027u, 7039u, 7043u, 7057u, 7069u, + 7079u, 7103u, 7109u, 7121u, 7127u, 7129u, 7151u, 7159u, 7177u, + 7187u, 7193u, 7207u, 7211u, 7213u, 7219u, 7229u, 7237u, 7243u, + 7247u, 7253u, 7283u, 7297u, 7307u, 7309u, 7321u, 7331u, 7333u, + 7349u, 7351u, 7369u, 7393u, 7411u, 7417u, 7433u, 7451u, 7457u, + 7459u, 7477u, 7481u, 7487u, 7489u, 7499u, 7507u, 7517u, 7523u, + 7529u, 7537u, 7541u, 7547u, 7549u, 7559u, 7561u, 7573u, 7577u, + 7583u, 7589u, 7591u, 7603u, 7607u, 7621u, 7639u, 7643u, 7649u, + 7669u, 7673u, 7681u, 7687u, 7691u, 7699u, 7703u, 7717u, 7723u, + 7727u, 7741u, 7753u, 7757u, 7759u, 7789u, 7793u, 7817u, 7823u, + 7829u, 7841u, 7853u, 7867u, 7873u, 7877u, 7879u, 7883u, 7901u, + 7907u, 7919u, 7927u, 7933u, 7937u, 7949u, 7951u, 7963u, 7993u, + 8009u, 8011u, 8017u, 8039u, 8053u, 8059u, 8069u, 8081u, 8087u, + 8089u, 8093u, 8101u, 8111u, 8117u, 8123u, 8147u, 8161u, 8167u, + 8171u, 8179u, 8191u, 8209u, 8219u, 8221u, 8231u, 8233u, 8237u, + 8243u, 8263u, 8269u, 8273u, 8287u, 8291u, 8293u, 8297u, 8311u, + 8317u, 8329u, 8353u, 8363u, 8369u, 8377u, 8387u, 8389u, 8419u, + 8423u, 8429u, 8431u, 8443u, 8447u, 8461u, 8467u, 8501u, 8513u, + 8521u, 8527u, 8537u, 8539u, 8543u, 8563u, 8573u, 8581u, 8597u, + 8599u, 8609u, 8623u, 8627u, 8629u, 8641u, 8647u, 8663u, 8669u, + 8677u, 8681u, 8689u, 8693u, 8699u, 8707u, 8713u, 8719u, 8731u, + 8737u, 8741u, 8747u, 8753u, 8761u, 8779u, 8783u, 8803u, 8807u, + 8819u, 8821u, 8831u, 8837u, 8839u, 8849u, 8861u, 8863u, 8867u, + 8887u, 8893u, 8923u, 8929u, 8933u, 8941u, 8951u, 8963u, 8969u, + 8971u, 8999u, 9001u, 9007u, 9011u, 9013u, 9029u, 9041u, 9043u, + 9049u, 9059u, 9067u, 9091u, 9103u, 9109u, 9127u, 9133u, 9137u, + 9151u, 9157u, 9161u, 9173u, 9181u, 9187u, 9199u, 9203u, 9209u, + 9221u, 9227u, 9239u, 9241u, 9257u, 9277u, 9281u, 9283u, 9293u, + 9311u, 9319u, 9323u, 9337u, 9341u, 9343u, 9349u, 9371u, 9377u, + 9391u, 9397u, 9403u, 9413u, 9419u, 9421u, 9431u, 9433u, 9437u, + 9439u, 9461u, 9463u, 9467u, 9473u, 9479u, 9491u, 9497u, 9511u, + 9521u, 9533u, 9539u, 9547u, 9551u, 9587u, 9601u, 9613u, 9619u, + 9623u, 9629u, 9631u, 9643u, 9649u, 9661u, 9677u, 9679u, 9689u, + 9697u, 9719u, 9721u, 9733u, 9739u, 9743u, 9749u, 9767u, 9769u, + 9781u, 9787u, 9791u, 9803u, 9811u, 9817u, 9829u, 9833u, 9839u, + 9851u, 9857u, 9859u, 9871u, 9883u, 9887u, 9901u, 9907u, 9923u, + 9929u, 9931u, 9941u, 9949u, 9967u, 9973u, 10007u, 10009u, 10037u, + 10039u, 10061u, 10067u, 10069u, 10079u, 10091u, 10093u, 10099u, 10103u, + 10111u, 10133u, 10139u, 10141u, 10151u, 10159u, 10163u, 10169u, 10177u, + 10181u, 10193u, 10211u, 10223u, 10243u, 10247u, 10253u, 10259u, 10267u, + 10271u, 10273u, 10289u, 10301u, 10303u, 10313u, 10321u, 10331u, 10333u, + 10337u, 10343u, 10357u, 10369u, 10391u, 10399u, 10427u, 10429u, 10433u, + 10453u, 10457u, 10459u, 10463u, 10477u, 10487u, 10499u, 10501u, 10513u, + 10529u, 10531u, 10559u, 10567u, 10589u, 10597u, 10601u, 10607u, 10613u, + 10627u, 10631u, 10639u, 10651u, 10657u, 10663u, 10667u, 10687u, 10691u, + 10709u, 10711u, 10723u, 10729u, 10733u, 10739u, 10753u, 10771u, 10781u, + 10789u, 10799u, 10831u, 10837u, 10847u, 10853u, 10859u, 10861u, 10867u, + 10883u, 10889u, 10891u, 10903u, 10909u, 10937u, 10939u, 10949u, 10957u, + 10973u, 10979u, 10987u, 10993u, 11003u, 11027u, 11047u, 11057u, 11059u, + 11069u, 11071u, 11083u, 11087u, 11093u, 11113u, 11117u, 11119u, 11131u, + 11149u, 11159u, 11161u, 11171u, 11173u, 11177u, 11197u, 11213u, 11239u, + 11243u, 11251u, 11257u, 11261u, 11273u, 11279u, 11287u, 11299u, 11311u, + 11317u, 11321u, 11329u, 11351u, 11353u, 11369u, 11383u, 11393u, 11399u, + 11411u, 11423u, 11437u, 11443u, 11447u, 11467u, 11471u, 11483u, 11489u, + 11491u, 11497u, 11503u, 11519u, 11527u, 11549u, 11551u, 11579u, 11587u, + 11593u, 11597u, 11617u, 11621u, 11633u, 11657u, 11677u, 11681u, 11689u, + 11699u, 11701u, 11717u, 11719u, 11731u, 11743u, 11777u, 11779u, 11783u, + 11789u, 11801u, 11807u, 11813u, 11821u, 11827u, 11831u, 11833u, 11839u, + 11863u, 11867u, 11887u, 11897u, 11903u, 11909u, 11923u, 11927u, 11933u, + 11939u, 11941u, 11953u, 11959u, 11969u, 11971u, 11981u, 11987u, 12007u, + 12011u, 12037u, 12041u, 12043u, 12049u, 12071u, 12073u, 12097u, 12101u, + 12107u, 12109u, 12113u, 12119u, 12143u, 12149u, 12157u, 12161u, 12163u, + 12197u, 12203u, 12211u, 12227u, 12239u, 12241u, 12251u, 12253u, 12263u, + 12269u, 12277u, 12281u, 12289u, 12301u, 12323u, 12329u, 12343u, 12347u, + 12373u, 12377u, 12379u, 12391u, 12401u, 12409u, 12413u, 12421u, 12433u, + 12437u, 12451u, 12457u, 12473u, 12479u, 12487u, 12491u, 12497u, 12503u, + 12511u, 12517u, 12527u, 12539u, 12541u, 12547u, 12553u, 12569u, 12577u, + 12583u, 12589u, 12601u, 12611u, 12613u, 12619u, 12637u, 12641u, 12647u, + 12653u, 12659u, 12671u, 12689u, 12697u, 12703u, 12713u, 12721u, 12739u, + 12743u, 12757u, 12763u, 12781u, 12791u, 12799u, 12809u, 12821u, 12823u, + 12829u, 12841u, 12853u, 12889u, 12893u, 12899u, 12907u, 12911u, 12917u, + 12919u, 12923u, 12941u, 12953u, 12959u, 12967u, 12973u, 12979u, 12983u, + 13001u, 13003u, 13007u, 13009u, 13033u, 13037u, 13043u, 13049u, 13063u, + 13093u, 13099u, 13103u, 13109u, 13121u, 13127u, 13147u, 13151u, 13159u, + 13163u, 13171u, 13177u, 13183u, 13187u, 13217u, 13219u, 13229u, 13241u, + 13249u, 13259u, 13267u, 13291u, 13297u, 13309u, 13313u, 13327u, 13331u, + 13337u, 13339u, 13367u, 13381u, 13397u, 13399u, 13411u, 13417u, 13421u, + 13441u, 13451u, 13457u, 13463u, 13469u, 13477u, 13487u, 13499u, 13513u, + 13523u, 13537u, 13553u, 13567u, 13577u, 13591u, 13597u, 13613u, 13619u, + 13627u, 13633u, 13649u, 13669u, 13679u, 13681u, 13687u, 13691u, 13693u, + 13697u, 13709u, 13711u, 13721u, 13723u, 13729u, 13751u, 13757u, 13759u, + 13763u, 13781u, 13789u, 13799u, 13807u, 13829u, 13831u, 13841u, 13859u, + 13873u, 13877u, 13879u, 13883u, 13901u, 13903u, 13907u, 13913u, 13921u, + 13931u, 13933u, 13963u, 13967u, 13997u, 13999u, 14009u, 14011u, 14029u, + 14033u, 14051u, 14057u, 14071u, 14081u, 14083u, 14087u, 14107u, 14143u, + 14149u, 14153u, 14159u, 14173u, 14177u, 14197u, 14207u, 14221u, 14243u, + 14249u, 14251u, 14281u, 14293u, 14303u, 14321u, 14323u, 14327u, 14341u, + 14347u, 14369u, 14387u, 14389u, 14401u, 14407u, 14411u, 14419u, 14423u, + 14431u, 14437u, 14447u, 14449u, 14461u, 14479u, 14489u, 14503u, 14519u, + 14533u, 14537u, 14543u, 14549u, 14551u, 14557u, 14561u, 14563u, 14591u, + 14593u, 14621u, 14627u, 14629u, 14633u, 14639u, 14653u, 14657u, 14669u, + 14683u, 14699u, 14713u, 14717u, 14723u, 14731u, 14737u, 14741u, 14747u, + 14753u, 14759u, 14767u, 14771u, 14779u, 14783u, 14797u, 14813u, 14821u, + 14827u, 14831u, 14843u, 14851u, 14867u, 14869u, 14879u, 14887u, 14891u, + 14897u, 14923u, 14929u, 14939u, 14947u, 14951u, 14957u, 14969u, 14983u, + 15013u, 15017u, 15031u, 15053u, 15061u, 15073u, 15077u, 15083u, 15091u, + 15101u, 15107u, 15121u, 15131u, 15137u, 15139u, 15149u, 15161u, 15173u, + 15187u, 15193u, 15199u, 15217u, 15227u, 15233u, 15241u, 15259u, 15263u, + 15269u, 15271u, 15277u, 15287u, 15289u, 15299u, 15307u, 15313u, 15319u, + 15329u, 15331u, 15349u, 15359u, 15361u, 15373u, 15377u, 15383u, 15391u, + 15401u, 15413u, 15427u, 15439u, 15443u, 15451u, 15461u, 15467u, 15473u, + 15493u, 15497u, 15511u, 15527u, 15541u, 15551u, 15559u, 15569u, 15581u, + 15583u, 15601u, 15607u, 15619u, 15629u, 15641u, 15643u, 15647u, 15649u, + 15661u, 15667u, 15671u, 15679u, 15683u, 15727u, 15731u, 15733u, 15737u, + 15739u, 15749u, 15761u, 15767u, 15773u, 15787u, 15791u, 15797u, 15803u, + 15809u, 15817u, 15823u, 15859u, 15877u, 15881u, 15887u, 15889u, 15901u, + 15907u, 15913u, 15919u, 15923u, 15937u, 15959u, 15971u, 15973u, 15991u, + 16001u, 16007u, 16033u, 16057u, 16061u, 16063u, 16067u, 16069u, 16073u, + 16087u, 16091u, 16097u, 16103u, 16111u, 16127u, 16139u, 16141u, 16183u, + 16187u, 16189u, 16193u, 16217u, 16223u, 16229u, 16231u, 16249u, 16253u, + 16267u, 16273u, 16301u, 16319u, 16333u, 16339u, 16349u, 16361u, 16363u, + 16369u, 16381u, 16411u, 16417u, 16421u, 16427u, 16433u, 16447u, 16451u, + 16453u, 16477u, 16481u, 16487u, 16493u, 16519u, 16529u, 16547u, 16553u, + 16561u, 16567u, 16573u, 16603u, 16607u, 16619u, 16631u, 16633u, 16649u, + 16651u, 16657u, 16661u, 16673u, 16691u, 16693u, 16699u, 16703u, 16729u, + 16741u, 16747u, 16759u, 16763u, 16787u, 16811u, 16823u, 16829u, 16831u, + 16843u, 16871u, 16879u, 16883u, 16889u, 16901u, 16903u, 16921u, 16927u, + 16931u, 16937u, 16943u, 16963u, 16979u, 16981u, 16987u, 16993u, 17011u, + 17021u, 17027u, 17029u, 17033u, 17041u, 17047u, 17053u, 17077u, 17093u, + 17099u, 17107u, 17117u, 17123u, 17137u, 17159u, 17167u, 17183u, 17189u, + 17191u, 17203u, 17207u, 17209u, 17231u, 17239u, 17257u, 17291u, 17293u, + 17299u, 17317u, 17321u, 17327u, 17333u, 17341u, 17351u, 17359u, 17377u, + 17383u, 17387u, 17389u, 17393u, 17401u, 17417u, 17419u, 17431u, 17443u, + 17449u, 17467u, 17471u, 17477u, 17483u, 17489u, 17491u, 17497u, 17509u, + 17519u, 17539u, 17551u, 17569u, 17573u, 17579u, 17581u, 17597u, 17599u, + 17609u, 17623u, 17627u, 17657u, 17659u, 17669u, 17681u, 17683u, 17707u, + 17713u, 17729u, 17737u, 17747u, 17749u, 17761u, 17783u, 17789u, 17791u, + 17807u, 17827u, 17837u, 17839u, 17851u, 17863u, 17881u, 17891u, 17903u, + 17909u, 17911u, 17921u, 17923u, 17929u, 17939u, 17957u, 17959u, 17971u, + 17977u, 17981u, 17987u, 17989u, 18013u, 18041u, 18043u, 18047u, 18049u, + 18059u, 18061u, 18077u, 18089u, 18097u, 18119u, 18121u, 18127u, 18131u, + 18133u, 18143u, 18149u, 18169u, 18181u, 18191u, 18199u, 18211u, 18217u, + 18223u, 18229u, 18233u, 18251u, 18253u, 18257u, 18269u, 18287u, 18289u, + 18301u, 18307u, 18311u, 18313u, 18329u, 18341u, 18353u, 18367u, 18371u, + 18379u, 18397u, 18401u, 18413u, 18427u, 18433u, 18439u, 18443u, 18451u, + 18457u, 18461u, 18481u, 18493u, 18503u, 18517u, 18521u, 18523u, 18539u, + 18541u, 18553u, 18583u, 18587u, 18593u, 18617u, 18637u, 18661u, 18671u, + 18679u, 18691u, 18701u, 18713u, 18719u, 18731u, 18743u, 18749u, 18757u, + 18773u, 18787u, 18793u, 18797u, 18803u, 18839u, 18859u, 18869u, 18899u, + 18911u, 18913u, 18917u, 18919u, 18947u, 18959u, 18973u, 18979u, 19001u, + 19009u, 19013u, 19031u, 19037u, 19051u, 19069u, 19073u, 19079u, 19081u, + 19087u, 19121u, 19139u, 19141u, 19157u, 19163u, 19181u, 19183u, 19207u, + 19211u, 19213u, 19219u, 19231u, 19237u, 19249u, 19259u, 19267u, 19273u, + 19289u, 19301u, 19309u, 19319u, 19333u, 19373u, 19379u, 19381u, 19387u, + 19391u, 19403u, 19417u, 19421u, 19423u, 19427u, 19429u, 19433u, 19441u, + 19447u, 19457u, 19463u, 19469u, 19471u, 19477u, 19483u, 19489u, 19501u, + 19507u, 19531u, 19541u, 19543u, 19553u, 19559u, 19571u, 19577u, 19583u, + 19597u, 19603u, 19609u, 19661u, 19681u, 19687u, 19697u, 19699u, 19709u, + 19717u, 19727u, 19739u, 19751u, 19753u, 19759u, 19763u, 19777u, 19793u, + 19801u, 19813u, 19819u, 19841u, 19843u, 19853u, 19861u, 19867u, 19889u, + 19891u, 19913u, 19919u, 19927u, 19937u, 19949u, 19961u, 19963u, 19973u, + 19979u, 19991u, 19993u, 19997u, 20011u, 20021u, 20023u, 20029u, 20047u, + 20051u, 20063u, 20071u, 20089u, 20101u, 20107u, 20113u, 20117u, 20123u, + 20129u, 20143u, 20147u, 20149u, 20161u, 20173u, 20177u, 20183u, 20201u, + 20219u, 20231u, 20233u, 20249u, 20261u, 20269u, 20287u, 20297u, 20323u, + 20327u, 20333u, 20341u, 20347u, 20353u, 20357u, 20359u, 20369u, 20389u, + 20393u, 20399u, 20407u, 20411u, 20431u, 20441u, 20443u, 20477u, 20479u, + 20483u, 20507u, 20509u, 20521u, 20533u, 20543u, 20549u, 20551u, 20563u, + 20593u, 20599u, 20611u, 20627u, 20639u, 20641u, 20663u, 20681u, 20693u, + 20707u, 20717u, 20719u, 20731u, 20743u, 20747u, 20749u, 20753u, 20759u, + 20771u, 20773u, 20789u, 20807u, 20809u, 20849u, 20857u, 20873u, 20879u, + 20887u, 20897u, 20899u, 20903u, 20921u, 20929u, 20939u, 20947u, 20959u, + 20963u, 20981u, 20983u, 21001u, 21011u, 21013u, 21017u, 21019u, 21023u, + 21031u, 21059u, 21061u, 21067u, 21089u, 21101u, 21107u, 21121u, 21139u, + 21143u, 21149u, 21157u, 21163u, 21169u, 21179u, 21187u, 21191u, 21193u, + 21211u, 21221u, 21227u, 21247u, 21269u, 21277u, 21283u, 21313u, 21317u, + 21319u, 21323u, 21341u, 21347u, 21377u, 21379u, 21383u, 21391u, 21397u, + 21401u, 21407u, 21419u, 21433u, 21467u, 21481u, 21487u, 21491u, 21493u, + 21499u, 21503u, 21517u, 21521u, 21523u, 21529u, 21557u, 21559u, 21563u, + 21569u, 21577u, 21587u, 21589u, 21599u, 21601u, 21611u, 21613u, 21617u, + 21647u, 21649u, 21661u, 21673u, 21683u, 21701u, 21713u, 21727u, 21737u, + 21739u, 21751u, 21757u, 21767u, 21773u, 21787u, 21799u, 21803u, 21817u, + 21821u, 21839u, 21841u, 21851u, 21859u, 21863u, 21871u, 21881u, 21893u, + 21911u, 21929u, 21937u, 21943u, 21961u, 21977u, 21991u, 21997u, 22003u, + 22013u, 22027u, 22031u, 22037u, 22039u, 22051u, 22063u, 22067u, 22073u, + 22079u, 22091u, 22093u, 22109u, 22111u, 22123u, 22129u, 22133u, 22147u, + 22153u, 22157u, 22159u, 22171u, 22189u, 22193u, 22229u, 22247u, 22259u, + 22271u, 22273u, 22277u, 22279u, 22283u, 22291u, 22303u, 22307u, 22343u, + 22349u, 22367u, 22369u, 22381u, 22391u, 22397u, 22409u, 22433u, 22441u, + 22447u, 22453u, 22469u, 22481u, 22483u, 22501u, 22511u, 22531u, 22541u, + 22543u, 22549u, 22567u, 22571u, 22573u, 22613u, 22619u, 22621u, 22637u, + 22639u, 22643u, 22651u, 22669u, 22679u, 22691u, 22697u, 22699u, 22709u, + 22717u, 22721u, 22727u, 22739u, 22741u, 22751u, 22769u, 22777u, 22783u, + 22787u, 22807u, 22811u, 22817u, 22853u, 22859u, 22861u, 22871u, 22877u, + 22901u, 22907u, 22921u, 22937u, 22943u, 22961u, 22963u, 22973u, 22993u, + 23003u, 23011u, 23017u, 23021u, 23027u, 23029u, 23039u, 23041u, 23053u, + 23057u, 23059u, 23063u, 23071u, 23081u, 23087u, 23099u, 23117u, 23131u, + 23143u, 23159u, 23167u, 23173u, 23189u, 23197u, 23201u, 23203u, 23209u, + 23227u, 23251u, 23269u, 23279u, 23291u, 23293u, 23297u, 23311u, 23321u, + 23327u, 23333u, 23339u, 23357u, 23369u, 23371u, 23399u, 23417u, 23431u, + 23447u, 23459u, 23473u, 23497u, 23509u, 23531u, 23537u, 23539u, 23549u, + 23557u, 23561u, 23563u, 23567u, 23581u, 23593u, 23599u, 23603u, 23609u, + 23623u, 23627u, 23629u, 23633u, 23663u, 23669u, 23671u, 23677u, 23687u, + 23689u, 23719u, 23741u, 23743u, 23747u, 23753u, 23761u, 23767u, 23773u, + 23789u, 23801u, 23813u, 23819u, 23827u, 23831u, 23833u, 23857u, 23869u, + 23873u, 23879u, 23887u, 23893u, 23899u, 23909u, 23911u, 23917u, 23929u, + 23957u, 23971u, 23977u, 23981u, 23993u, 24001u, 24007u, 24019u, 24023u, + 24029u, 24043u, 24049u, 24061u, 24071u, 24077u, 24083u, 24091u, 24097u, + 24103u, 24107u, 24109u, 24113u, 24121u, 24133u, 24137u, 24151u, 24169u, + 24179u, 24181u, 24197u, 24203u, 24223u, 24229u, 24239u, 24247u, 24251u, + 24281u, 24317u, 24329u, 24337u, 24359u, 24371u, 24373u, 24379u, 24391u, + 24407u, 24413u, 24419u, 24421u, 24439u, 24443u, 24469u, 24473u, 24481u, + 24499u, 24509u, 24517u, 24527u, 24533u, 24547u, 24551u, 24571u, 24593u, + 24611u, 24623u, 24631u, 24659u, 24671u, 24677u, 24683u, 24691u, 24697u, + 24709u, 24733u, 24749u, 24763u, 24767u, 24781u, 24793u, 24799u, 24809u, + 24821u, 24841u, 24847u, 24851u, 24859u, 24877u, 24889u, 24907u, 24917u, + 24919u, 24923u, 24943u, 24953u, 24967u, 24971u, 24977u, 24979u, 24989u, + 25013u, 25031u, 25033u, 25037u, 25057u, 25073u, 25087u, 25097u, 25111u, + 25117u, 25121u, 25127u, 25147u, 25153u, 25163u, 25169u, 25171u, 25183u, + 25189u, 25219u, 25229u, 25237u, 25243u, 25247u, 25253u, 25261u, 25301u, + 25303u, 25307u, 25309u, 25321u, 25339u, 25343u, 25349u, 25357u, 25367u, + 25373u, 25391u, 25409u, 25411u, 25423u, 25439u, 25447u, 25453u, 25457u, + 25463u, 25469u, 25471u, 25523u, 25537u, 25541u, 25561u, 25577u, 25579u, + 25583u, 25589u, 25601u, 25603u, 25609u, 25621u, 25633u, 25639u, 25643u, + 25657u, 25667u, 25673u, 25679u, 25693u, 25703u, 25717u, 25733u, 25741u, + 25747u, 25759u, 25763u, 25771u, 25793u, 25799u, 25801u, 25819u, 25841u, + 25847u, 25849u, 25867u, 25873u, 25889u, 25903u, 25913u, 25919u, 25931u, + 25933u, 25939u, 25943u, 25951u, 25969u, 25981u, 25997u, 25999u, 26003u, + 26017u, 26021u, 26029u, 26041u, 26053u, 26083u, 26099u, 26107u, 26111u, + 26113u, 26119u, 26141u, 26153u, 26161u, 26171u, 26177u, 26183u, 26189u, + 26203u, 26209u, 26227u, 26237u, 26249u, 26251u, 26261u, 26263u, 26267u, + 26293u, 26297u, 26309u, 26317u, 26321u, 26339u, 26347u, 26357u, 26371u, + 26387u, 26393u, 26399u, 26407u, 26417u, 26423u, 26431u, 26437u, 26449u, + 26459u, 26479u, 26489u, 26497u, 26501u, 26513u, 26539u, 26557u, 26561u, + 26573u, 26591u, 26597u, 26627u, 26633u, 26641u, 26647u, 26669u, 26681u, + 26683u, 26687u, 26693u, 26699u, 26701u, 26711u, 26713u, 26717u, 26723u, + 26729u, 26731u, 26737u, 26759u, 26777u, 26783u, 26801u, 26813u, 26821u, + 26833u, 26839u, 26849u, 26861u, 26863u, 26879u, 26881u, 26891u, 26893u, + 26903u, 26921u, 26927u, 26947u, 26951u, 26953u, 26959u, 26981u, 26987u, + 26993u, 27011u, 27017u, 27031u, 27043u, 27059u, 27061u, 27067u, 27073u, + 27077u, 27091u, 27103u, 27107u, 27109u, 27127u, 27143u, 27179u, 27191u, + 27197u, 27211u, 27239u, 27241u, 27253u, 27259u, 27271u, 27277u, 27281u, + 27283u, 27299u, 27329u, 27337u, 27361u, 27367u, 27397u, 27407u, 27409u, + 27427u, 27431u, 27437u, 27449u, 27457u, 27479u, 27481u, 27487u, 27509u, + 27527u, 27529u, 27539u, 27541u, 27551u, 27581u, 27583u, 27611u, 27617u, + 27631u, 27647u, 27653u, 27673u, 27689u, 27691u, 27697u, 27701u, 27733u, + 27737u, 27739u, 27743u, 27749u, 27751u, 27763u, 27767u, 27773u, 27779u, + 27791u, 27793u, 27799u, 27803u, 27809u, 27817u, 27823u, 27827u, 27847u, + 27851u, 27883u, 27893u, 27901u, 27917u, 27919u, 27941u, 27943u, 27947u, + 27953u, 27961u, 27967u, 27983u, 27997u, 28001u, 28019u, 28027u, 28031u, + 28051u, 28057u, 28069u, 28081u, 28087u, 28097u, 28099u, 28109u, 28111u, + 28123u, 28151u, 28163u, 28181u, 28183u, 28201u, 28211u, 28219u, 28229u, + 28277u, 28279u, 28283u, 28289u, 28297u, 28307u, 28309u, 28319u, 28349u, + 28351u, 28387u, 28393u, 28403u, 28409u, 28411u, 28429u, 28433u, 28439u, + 28447u, 28463u, 28477u, 28493u, 28499u, 28513u, 28517u, 28537u, 28541u, + 28547u, 28549u, 28559u, 28571u, 28573u, 28579u, 28591u, 28597u, 28603u, + 28607u, 28619u, 28621u, 28627u, 28631u, 28643u, 28649u, 28657u, 28661u, + 28663u, 28669u, 28687u, 28697u, 28703u, 28711u, 28723u, 28729u, 28751u, + 28753u, 28759u, 28771u, 28789u, 28793u, 28807u, 28813u, 28817u, 28837u, + 28843u, 28859u, 28867u, 28871u, 28879u, 28901u, 28909u, 28921u, 28927u, + 28933u, 28949u, 28961u, 28979u, 29009u, 29017u, 29021u, 29023u, 29027u, + 29033u, 29059u, 29063u, 29077u, 29101u, 29123u, 29129u, 29131u, 29137u, + 29147u, 29153u, 29167u, 29173u, 29179u, 29191u, 29201u, 29207u, 29209u, + 29221u, 29231u, 29243u, 29251u, 29269u, 29287u, 29297u, 29303u, 29311u, + 29327u, 29333u, 29339u, 29347u, 29363u, 29383u, 29387u, 29389u, 29399u, + 29401u, 29411u, 29423u, 29429u, 29437u, 29443u, 29453u, 29473u, 29483u, + 29501u, 29527u, 29531u, 29537u, 29567u, 29569u, 29573u, 29581u, 29587u, + 29599u, 29611u, 29629u, 29633u, 29641u, 29663u, 29669u, 29671u, 29683u, + 29717u, 29723u, 29741u, 29753u, 29759u, 29761u, 29789u, 29803u, 29819u, + 29833u, 29837u, 29851u, 29863u, 29867u, 29873u, 29879u, 29881u, 29917u, + 29921u, 29927u, 29947u, 29959u, 29983u, 29989u, 30011u, 30013u, 30029u, + 30047u, 30059u, 30071u, 30089u, 30091u, 30097u, 30103u, 30109u, 30113u, + 30119u, 30133u, 30137u, 30139u, 30161u, 30169u, 30181u, 30187u, 30197u, + 30203u, 30211u, 30223u, 30241u, 30253u, 30259u, 30269u, 30271u, 30293u, + 30307u, 30313u, 30319u, 30323u, 30341u, 30347u, 30367u, 30389u, 30391u, + 30403u, 30427u, 30431u, 30449u, 30467u, 30469u, 30491u, 30493u, 30497u, + 30509u, 30517u, 30529u, 30539u, 30553u, 30557u, 30559u, 30577u, 30593u, + 30631u, 30637u, 30643u, 30649u, 30661u, 30671u, 30677u, 30689u, 30697u, + 30703u, 30707u, 30713u, 30727u, 30757u, 30763u, 30773u, 30781u, 30803u, + 30809u, 30817u, 30829u, 30839u, 30841u, 30851u, 30853u, 30859u, 30869u, + 30871u, 30881u, 30893u, 30911u, 30931u, 30937u, 30941u, 30949u, 30971u, + 30977u, 30983u, 31013u, 31019u, 31033u, 31039u, 31051u, 31063u, 31069u, + 31079u, 31081u, 31091u, 31121u, 31123u, 31139u, 31147u, 31151u, 31153u, + 31159u, 31177u, 31181u, 31183u, 31189u, 31193u, 31219u, 31223u, 31231u, + 31237u, 31247u, 31249u, 31253u, 31259u, 31267u, 31271u, 31277u, 31307u, + 31319u, 31321u, 31327u, 31333u, 31337u, 31357u, 31379u, 31387u, 31391u, + 31393u, 31397u, 31469u, 31477u, 31481u, 31489u, 31511u, 31513u, 31517u, + 31531u, 31541u, 31543u, 31547u, 31567u, 31573u, 31583u, 31601u, 31607u, + 31627u, 31643u, 31649u, 31657u, 31663u, 31667u, 31687u, 31699u, 31721u, + 31723u, 31727u, 31729u, 31741u, 31751u, 31769u, 31771u, 31793u, 31799u, + 31817u, 31847u, 31849u, 31859u, 31873u, 31883u, 31891u, 31907u, 31957u, + 31963u, 31973u, 31981u, 31991u, 32003u, 32009u, 32027u, 32029u, 32051u, + 32057u, 32059u, 32063u, 32069u, 32077u, 32083u, 32089u, 32099u, 32117u, + 32119u, 32141u, 32143u, 32159u, 32173u, 32183u, 32189u, 32191u, 32203u, + 32213u, 32233u, 32237u, 32251u, 32257u, 32261u, 32297u, 32299u, 32303u, + 32309u, 32321u, 32323u, 32327u, 32341u, 32353u, 32359u, 32363u, 32369u, + 32371u, 32377u, 32381u, 32401u, 32411u, 32413u, 32423u, 32429u, 32441u, + 32443u, 32467u, 32479u, 32491u, 32497u, 32503u, 32507u, 32531u, 32533u, + 32537u, 32561u, 32563u, 32569u, 32573u, 32579u, 32587u, 32603u, 32609u, + 32611u, 32621u, 32633u, 32647u, 32653u, 32687u, 32693u, 32707u, 32713u, + 32717u, 32719u, 32749u, 32771u, 32779u, 32783u, 32789u, 32797u, 32801u, + 32803u, 32831u, 32833u, 32839u, 32843u, 32869u, 32887u, 32909u, 32911u, + 32917u, 32933u, 32939u, 32941u, 32957u, 32969u, 32971u, 32983u, 32987u, + 32993u, 32999u, 33013u, 33023u, 33029u, 33037u, 33049u, 33053u, 33071u, + 33073u, 33083u, 33091u, 33107u, 33113u, 33119u, 33149u, 33151u, 33161u, + 33179u, 33181u, 33191u, 33199u, 33203u, 33211u, 33223u, 33247u, 33287u, + 33289u, 33301u, 33311u, 33317u, 33329u, 33331u, 33343u, 33347u, 33349u, + 33353u, 33359u, 33377u, 33391u, 33403u, 33409u, 33413u, 33427u, 33457u, + 33461u, 33469u, 33479u, 33487u, 33493u, 33503u, 33521u, 33529u, 33533u, + 33547u, 33563u, 33569u, 33577u, 33581u, 33587u, 33589u, 33599u, 33601u, + 33613u, 33617u, 33619u, 33623u, 33629u, 33637u, 33641u, 33647u, 33679u, + 33703u, 33713u, 33721u, 33739u, 33749u, 33751u, 33757u, 33767u, 33769u, + 33773u, 33791u, 33797u, 33809u, 33811u, 33827u, 33829u, 33851u, 33857u, + 33863u, 33871u, 33889u, 33893u, 33911u, 33923u, 33931u, 33937u, 33941u, + 33961u, 33967u, 33997u, 34019u, 34031u, 34033u, 34039u, 34057u, 34061u, + 34123u, 34127u, 34129u, 34141u, 34147u, 34157u, 34159u, 34171u, 34183u, + 34211u, 34213u, 34217u, 34231u, 34253u, 34259u, 34261u, 34267u, 34273u, + 34283u, 34297u, 34301u, 34303u, 34313u, 34319u, 34327u, 34337u, 34351u, + 34361u, 34367u, 34369u, 34381u, 34403u, 34421u, 34429u, 34439u, 34457u, + 34469u, 34471u, 34483u, 34487u, 34499u, 34501u, 34511u, 34513u, 34519u, + 34537u, 34543u, 34549u, 34583u, 34589u, 34591u, 34603u, 34607u, 34613u, + 34631u, 34649u, 34651u, 34667u, 34673u, 34679u, 34687u, 34693u, 34703u, + 34721u, 34729u, 34739u, 34747u, 34757u, 34759u, 34763u, 34781u, 34807u, + 34819u, 34841u, 34843u, 34847u, 34849u, 34871u, 34877u, 34883u, 34897u, + 34913u, 34919u, 34939u, 34949u, 34961u, 34963u, 34981u, 35023u, 35027u, + 35051u, 35053u, 35059u, 35069u, 35081u, 35083u, 35089u, 35099u, 35107u, + 35111u, 35117u, 35129u, 35141u, 35149u, 35153u, 35159u, 35171u, 35201u, + 35221u, 35227u, 35251u, 35257u, 35267u, 35279u, 35281u, 35291u, 35311u, + 35317u, 35323u, 35327u, 35339u, 35353u, 35363u, 35381u, 35393u, 35401u, + 35407u, 35419u, 35423u, 35437u, 35447u, 35449u, 35461u, 35491u, 35507u, + 35509u, 35521u, 35527u, 35531u, 35533u, 35537u, 35543u, 35569u, 35573u, + 35591u, 35593u, 35597u, 35603u, 35617u, 35671u, 35677u, 35729u, 35731u, + 35747u, 35753u, 35759u, 35771u, 35797u, 35801u, 35803u, 35809u, 35831u, + 35837u, 35839u, 35851u, 35863u, 35869u, 35879u, 35897u, 35899u, 35911u, + 35923u, 35933u, 35951u, 35963u, 35969u, 35977u, 35983u, 35993u, 35999u, + 36007u, 36011u, 36013u, 36017u, 36037u, 36061u, 36067u, 36073u, 36083u, + 36097u, 36107u, 36109u, 36131u, 36137u, 36151u, 36161u, 36187u, 36191u, + 36209u, 36217u, 36229u, 36241u, 36251u, 36263u, 36269u, 36277u, 36293u, + 36299u, 36307u, 36313u, 36319u, 36341u, 36343u, 36353u, 36373u, 36383u, + 36389u, 36433u, 36451u, 36457u, 36467u, 36469u, 36473u, 36479u, 36493u, + 36497u, 36523u, 36527u, 36529u, 36541u, 36551u, 36559u, 36563u, 36571u, + 36583u, 36587u, 36599u, 36607u, 36629u, 36637u, 36643u, 36653u, 36671u, + 36677u, 36683u, 36691u, 36697u, 36709u, 36713u, 36721u, 36739u, 36749u, + 36761u, 36767u, 36779u, 36781u, 36787u, 36791u, 36793u, 36809u, 36821u, + 36833u, 36847u, 36857u, 36871u, 36877u, 36887u, 36899u, 36901u, 36913u, + 36919u, 36923u, 36929u, 36931u, 36943u, 36947u, 36973u, 36979u, 36997u, + 37003u, 37013u, 37019u, 37021u, 37039u, 37049u, 37057u, 37061u, 37087u, + 37097u, 37117u, 37123u, 37139u, 37159u, 37171u, 37181u, 37189u, 37199u, + 37201u, 37217u, 37223u, 37243u, 37253u, 37273u, 37277u, 37307u, 37309u, + 37313u, 37321u, 37337u, 37339u, 37357u, 37361u, 37363u, 37369u, 37379u, + 37397u, 37409u, 37423u, 37441u, 37447u, 37463u, 37483u, 37489u, 37493u, + 37501u, 37507u, 37511u, 37517u, 37529u, 37537u, 37547u, 37549u, 37561u, + 37567u, 37571u, 37573u, 37579u, 37589u, 37591u, 37607u, 37619u, 37633u, + 37643u, 37649u, 37657u, 37663u, 37691u, 37693u, 37699u, 37717u, 37747u, + 37781u, 37783u, 37799u, 37811u, 37813u, 37831u, 37847u, 37853u, 37861u, + 37871u, 37879u, 37889u, 37897u, 37907u, 37951u, 37957u, 37963u, 37967u, + 37987u, 37991u, 37993u, 37997u, 38011u, 38039u, 38047u, 38053u, 38069u, + 38083u, 38113u, 38119u, 38149u, 38153u, 38167u, 38177u, 38183u, 38189u, + 38197u, 38201u, 38219u, 38231u, 38237u, 38239u, 38261u, 38273u, 38281u, + 38287u, 38299u, 38303u, 38317u, 38321u, 38327u, 38329u, 38333u, 38351u, + 38371u, 38377u, 38393u, 38431u, 38447u, 38449u, 38453u, 38459u, 38461u, + 38501u, 38543u, 38557u, 38561u, 38567u, 38569u, 38593u, 38603u, 38609u, + 38611u, 38629u, 38639u, 38651u, 38653u, 38669u, 38671u, 38677u, 38693u, + 38699u, 38707u, 38711u, 38713u, 38723u, 38729u, 38737u, 38747u, 38749u, + 38767u, 38783u, 38791u, 38803u, 38821u, 38833u, 38839u, 38851u, 38861u, + 38867u, 38873u, 38891u, 38903u, 38917u, 38921u, 38923u, 38933u, 38953u, + 38959u, 38971u, 38977u, 38993u, 39019u, 39023u, 39041u, 39043u, 39047u, + 39079u, 39089u, 39097u, 39103u, 39107u, 39113u, 39119u, 39133u, 39139u, + 39157u, 39161u, 39163u, 39181u, 39191u, 39199u, 39209u, 39217u, 39227u, + 39229u, 39233u, 39239u, 39241u, 39251u, 39293u, 39301u, 39313u, 39317u, + 39323u, 39341u, 39343u, 39359u, 39367u, 39371u, 39373u, 39383u, 39397u, + 39409u, 39419u, 39439u, 39443u, 39451u, 39461u, 39499u, 39503u, 39509u, + 39511u, 39521u, 39541u, 39551u, 39563u, 39569u, 39581u, 39607u, 39619u, + 39623u, 39631u, 39659u, 39667u, 39671u, 39679u, 39703u, 39709u, 39719u, + 39727u, 39733u, 39749u, 39761u, 39769u, 39779u, 39791u, 39799u, 39821u, + 39827u, 39829u, 39839u, 39841u, 39847u, 39857u, 39863u, 39869u, 39877u, + 39883u, 39887u, 39901u, 39929u, 39937u, 39953u, 39971u, 39979u, 39983u, + 39989u, 40009u, 40013u, 40031u, 40037u, 40039u, 40063u, 40087u, 40093u, + 40099u, 40111u, 40123u, 40127u, 40129u, 40151u, 40153u, 40163u, 40169u, + 40177u, 40189u, 40193u, 40213u, 40231u, 40237u, 40241u, 40253u, 40277u, + 40283u, 40289u, 40343u, 40351u, 40357u, 40361u, 40387u, 40423u, 40427u, + 40429u, 40433u, 40459u, 40471u, 40483u, 40487u, 40493u, 40499u, 40507u, + 40519u, 40529u, 40531u, 40543u, 40559u, 40577u, 40583u, 40591u, 40597u, + 40609u, 40627u, 40637u, 40639u, 40693u, 40697u, 40699u, 40709u, 40739u, + 40751u, 40759u, 40763u, 40771u, 40787u, 40801u, 40813u, 40819u, 40823u, + 40829u, 40841u, 40847u, 40849u, 40853u, 40867u, 40879u, 40883u, 40897u, + 40903u, 40927u, 40933u, 40939u, 40949u, 40961u, 40973u, 40993u, 41011u, + 41017u, 41023u, 41039u, 41047u, 41051u, 41057u, 41077u, 41081u, 41113u, + 41117u, 41131u, 41141u, 41143u, 41149u, 41161u, 41177u, 41179u, 41183u, + 41189u, 41201u, 41203u, 41213u, 41221u, 41227u, 41231u, 41233u, 41243u, + 41257u, 41263u, 41269u, 41281u, 41299u, 41333u, 41341u, 41351u, 41357u, + 41381u, 41387u, 41389u, 41399u, 41411u, 41413u, 41443u, 41453u, 41467u, + 41479u, 41491u, 41507u, 41513u, 41519u, 41521u, 41539u, 41543u, 41549u, + 41579u, 41593u, 41597u, 41603u, 41609u, 41611u, 41617u, 41621u, 41627u, + 41641u, 41647u, 41651u, 41659u, 41669u, 41681u, 41687u, 41719u, 41729u, + 41737u, 41759u, 41761u, 41771u, 41777u, 41801u, 41809u, 41813u, 41843u, + 41849u, 41851u, 41863u, 41879u, 41887u, 41893u, 41897u, 41903u, 41911u, + 41927u, 41941u, 41947u, 41953u, 41957u, 41959u, 41969u, 41981u, 41983u, + 41999u, 42013u, 42017u, 42019u, 42023u, 42043u, 42061u, 42071u, 42073u, + 42083u, 42089u, 42101u, 42131u, 42139u, 42157u, 42169u, 42179u, 42181u, + 42187u, 42193u, 42197u, 42209u, 42221u, 42223u, 42227u, 42239u, 42257u, + 42281u, 42283u, 42293u, 42299u, 42307u, 42323u, 42331u, 42337u, 42349u, + 42359u, 42373u, 42379u, 42391u, 42397u, 42403u, 42407u, 42409u, 42433u, + 42437u, 42443u, 42451u, 42457u, 42461u, 42463u, 42467u, 42473u, 42487u, + 42491u, 42499u, 42509u, 42533u, 42557u, 42569u, 42571u, 42577u, 42589u, + 42611u, 42641u, 42643u, 42649u, 42667u, 42677u, 42683u, 42689u, 42697u, + 42701u, 42703u, 42709u, 42719u, 42727u, 42737u, 42743u, 42751u, 42767u, + 42773u, 42787u, 42793u, 42797u, 42821u, 42829u, 42839u, 42841u, 42853u, + 42859u, 42863u, 42899u, 42901u, 42923u, 42929u, 42937u, 42943u, 42953u, + 42961u, 42967u, 42979u, 42989u, 43003u, 43013u, 43019u, 43037u, 43049u, + 43051u, 43063u, 43067u, 43093u, 43103u, 43117u, 43133u, 43151u, 43159u, + 43177u, 43189u, 43201u, 43207u, 43223u, 43237u, 43261u, 43271u, 43283u, + 43291u, 43313u, 43319u, 43321u, 43331u, 43391u, 43397u, 43399u, 43403u, + 43411u, 43427u, 43441u, 43451u, 43457u, 43481u, 43487u, 43499u, 43517u, + 43541u, 43543u, 43573u, 43577u, 43579u, 43591u, 43597u, 43607u, 43609u, + 43613u, 43627u, 43633u, 43649u, 43651u, 43661u, 43669u, 43691u, 43711u, + 43717u, 43721u, 43753u, 43759u, 43777u, 43781u, 43783u, 43787u, 43789u, + 43793u, 43801u, 43853u, 43867u, 43889u, 43891u, 43913u, 43933u, 43943u, + 43951u, 43961u, 43963u, 43969u, 43973u, 43987u, 43991u, 43997u, 44017u, + 44021u, 44027u, 44029u, 44041u, 44053u, 44059u, 44071u, 44087u, 44089u, + 44101u, 44111u, 44119u, 44123u, 44129u, 44131u, 44159u, 44171u, 44179u, + 44189u, 44201u, 44203u, 44207u, 44221u, 44249u, 44257u, 44263u, 44267u, + 44269u, 44273u, 44279u, 44281u, 44293u, 44351u, 44357u, 44371u, 44381u, + 44383u, 44389u, 44417u, 44449u, 44453u, 44483u, 44491u, 44497u, 44501u, + 44507u, 44519u, 44531u, 44533u, 44537u, 44543u, 44549u, 44563u, 44579u, + 44587u, 44617u, 44621u, 44623u, 44633u, 44641u, 44647u, 44651u, 44657u, + 44683u, 44687u, 44699u, 44701u, 44711u, 44729u, 44741u, 44753u, 44771u, + 44773u, 44777u, 44789u, 44797u, 44809u, 44819u, 44839u, 44843u, 44851u, + 44867u, 44879u, 44887u, 44893u, 44909u, 44917u, 44927u, 44939u, 44953u, + 44959u, 44963u, 44971u, 44983u, 44987u, 45007u, 45013u, 45053u, 45061u, + 45077u, 45083u, 45119u, 45121u, 45127u, 45131u, 45137u, 45139u, 45161u, + 45179u, 45181u, 45191u, 45197u, 45233u, 45247u, 45259u, 45263u, 45281u, + 45289u, 45293u, 45307u, 45317u, 45319u, 45329u, 45337u, 45341u, 45343u, + 45361u, 45377u, 45389u, 45403u, 45413u, 45427u, 45433u, 45439u, 45481u, + 45491u, 45497u, 45503u, 45523u, 45533u, 45541u, 45553u, 45557u, 45569u, + 45587u, 45589u, 45599u, 45613u, 45631u, 45641u, 45659u, 45667u, 45673u, + 45677u, 45691u, 45697u, 45707u, 45737u, 45751u, 45757u, 45763u, 45767u, + 45779u, 45817u, 45821u, 45823u, 45827u, 45833u, 45841u, 45853u, 45863u, + 45869u, 45887u, 45893u, 45943u, 45949u, 45953u, 45959u, 45971u, 45979u, + 45989u, 46021u, 46027u, 46049u, 46051u, 46061u, 46073u, 46091u, 46093u, + 46099u, 46103u, 46133u, 46141u, 46147u, 46153u, 46171u, 46181u, 46183u, + 46187u, 46199u, 46219u, 46229u, 46237u, 46261u, 46271u, 46273u, 46279u, + 46301u, 46307u, 46309u, 46327u, 46337u, 46349u, 46351u, 46381u, 46399u, + 46411u, 46439u, 46441u, 46447u, 46451u, 46457u, 46471u, 46477u, 46489u, + 46499u, 46507u, 46511u, 46523u, 46549u, 46559u, 46567u, 46573u, 46589u, + 46591u, 46601u, 46619u, 46633u, 46639u, 46643u, 46649u, 46663u, 46679u, + 46681u, 46687u, 46691u, 46703u, 46723u, 46727u, 46747u, 46751u, 46757u, + 46769u, 46771u, 46807u, 46811u, 46817u, 46819u, 46829u, 46831u, 46853u, + 46861u, 46867u, 46877u, 46889u, 46901u, 46919u, 46933u, 46957u, 46993u, + 46997u, 47017u, 47041u, 47051u, 47057u, 47059u, 47087u, 47093u, 47111u, + 47119u, 47123u, 47129u, 47137u, 47143u, 47147u, 47149u, 47161u, 47189u, + 47207u, 47221u, 47237u, 47251u, 47269u, 47279u, 47287u, 47293u, 47297u, + 47303u, 47309u, 47317u, 47339u, 47351u, 47353u, 47363u, 47381u, 47387u, + 47389u, 47407u, 47417u, 47419u, 47431u, 47441u, 47459u, 47491u, 47497u, + 47501u, 47507u, 47513u, 47521u, 47527u, 47533u, 47543u, 47563u, 47569u, + 47581u, 47591u, 47599u, 47609u, 47623u, 47629u, 47639u, 47653u, 47657u, + 47659u, 47681u, 47699u, 47701u, 47711u, 47713u, 47717u, 47737u, 47741u, + 47743u, 47777u, 47779u, 47791u, 47797u, 47807u, 47809u, 47819u, 47837u, + 47843u, 47857u, 47869u, 47881u, 47903u, 47911u, 47917u, 47933u, 47939u, + 47947u, 47951u, 47963u, 47969u, 47977u, 47981u, 48017u, 48023u, 48029u, + 48049u, 48073u, 48079u, 48091u, 48109u, 48119u, 48121u, 48131u, 48157u, + 48163u, 48179u, 48187u, 48193u, 48197u, 48221u, 48239u, 48247u, 48259u, + 48271u, 48281u, 48299u, 48311u, 48313u, 48337u, 48341u, 48353u, 48371u, + 48383u, 48397u, 48407u, 48409u, 48413u, 48437u, 48449u, 48463u, 48473u, + 48479u, 48481u, 48487u, 48491u, 48497u, 48523u, 48527u, 48533u, 48539u, + 48541u, 48563u, 48571u, 48589u, 48593u, 48611u, 48619u, 48623u, 48647u, + 48649u, 48661u, 48673u, 48677u, 48679u, 48731u, 48733u, 48751u, 48757u, + 48761u, 48767u, 48779u, 48781u, 48787u, 48799u, 48809u, 48817u, 48821u, + 48823u, 48847u, 48857u, 48859u, 48869u, 48871u, 48883u, 48889u, 48907u, + 48947u, 48953u, 48973u, 48989u, 48991u, 49003u, 49009u, 49019u, 49031u, + 49033u, 49037u, 49043u, 49057u, 49069u, 49081u, 49103u, 49109u, 49117u, + 49121u, 49123u, 49139u, 49157u, 49169u, 49171u, 49177u, 49193u, 49199u, + 49201u, 49207u, 49211u, 49223u, 49253u, 49261u, 49277u, 49279u, 49297u, + 49307u, 49331u, 49333u, 49339u, 49363u, 49367u, 49369u, 49391u, 49393u, + 49409u, 49411u, 49417u, 49429u, 49433u, 49451u, 49459u, 49463u, 49477u, + 49481u, 49499u, 49523u, 49529u, 49531u, 49537u, 49547u, 49549u, 49559u, + 49597u, 49603u, 49613u, 49627u, 49633u, 49639u, 49663u, 49667u, 49669u, + 49681u, 49697u, 49711u, 49727u, 49739u, 49741u, 49747u, 49757u, 49783u, + 49787u, 49789u, 49801u, 49807u, 49811u, 49823u, 49831u, 49843u, 49853u, + 49871u, 49877u, 49891u, 49919u, 49921u, 49927u, 49937u, 49939u, 49943u, + 49957u, 49991u, 49993u, 49999u, 50021u, 50023u, 50033u, 50047u, 50051u, + 50053u, 50069u, 50077u, 50087u, 50093u, 50101u, 50111u, 50119u, 50123u, + 50129u, 50131u, 50147u, 50153u, 50159u, 50177u, 50207u, 50221u, 50227u, + 50231u, 50261u, 50263u, 50273u, 50287u, 50291u, 50311u, 50321u, 50329u, + 50333u, 50341u, 50359u, 50363u, 50377u, 50383u, 50387u, 50411u, 50417u, + 50423u, 50441u, 50459u, 50461u, 50497u, 50503u, 50513u, 50527u, 50539u, + 50543u, 50549u, 50551u, 50581u, 50587u, 50591u, 50593u, 50599u, 50627u, + 50647u, 50651u, 50671u, 50683u, 50707u, 50723u, 50741u, 50753u, 50767u, + 50773u, 50777u, 50789u, 50821u, 50833u, 50839u, 50849u, 50857u, 50867u, + 50873u, 50891u, 50893u, 50909u, 50923u, 50929u, 50951u, 50957u, 50969u, + 50971u, 50989u, 50993u, 51001u, 51031u, 51043u, 51047u, 51059u, 51061u, + 51071u, 51109u, 51131u, 51133u, 51137u, 51151u, 51157u, 51169u, 51193u, + 51197u, 51199u, 51203u, 51217u, 51229u, 51239u, 51241u, 51257u, 51263u, + 51283u, 51287u, 51307u, 51329u, 51341u, 51343u, 51347u, 51349u, 51361u, + 51383u, 51407u, 51413u, 51419u, 51421u, 51427u, 51431u, 51437u, 51439u, + 51449u, 51461u, 51473u, 51479u, 51481u, 51487u, 51503u, 51511u, 51517u, + 51521u, 51539u, 51551u, 51563u, 51577u, 51581u, 51593u, 51599u, 51607u, + 51613u, 51631u, 51637u, 51647u, 51659u, 51673u, 51679u, 51683u, 51691u, + 51713u, 51719u, 51721u, 51749u, 51767u, 51769u, 51787u, 51797u, 51803u, + 51817u, 51827u, 51829u, 51839u, 51853u, 51859u, 51869u, 51871u, 51893u, + 51899u, 51907u, 51913u, 51929u, 51941u, 51949u, 51971u, 51973u, 51977u, + 51991u, 52009u, 52021u, 52027u, 52051u, 52057u, 52067u, 52069u, 52081u, + 52103u, 52121u, 52127u, 52147u, 52153u, 52163u, 52177u, 52181u, 52183u, + 52189u, 52201u, 52223u, 52237u, 52249u, 52253u, 52259u, 52267u, 52289u, + 52291u, 52301u, 52313u, 52321u, 52361u, 52363u, 52369u, 52379u, 52387u, + 52391u, 52433u, 52453u, 52457u, 52489u, 52501u, 52511u, 52517u, 52529u, + 52541u, 52543u, 52553u, 52561u, 52567u, 52571u, 52579u, 52583u, 52609u, + 52627u, 52631u, 52639u, 52667u, 52673u, 52691u, 52697u, 52709u, 52711u, + 52721u, 52727u, 52733u, 52747u, 52757u, 52769u, 52783u, 52807u, 52813u, + 52817u, 52837u, 52859u, 52861u, 52879u, 52883u, 52889u, 52901u, 52903u, + 52919u, 52937u, 52951u, 52957u, 52963u, 52967u, 52973u, 52981u, 52999u, + 53003u, 53017u, 53047u, 53051u, 53069u, 53077u, 53087u, 53089u, 53093u, + 53101u, 53113u, 53117u, 53129u, 53147u, 53149u, 53161u, 53171u, 53173u, + 53189u, 53197u, 53201u, 53231u, 53233u, 53239u, 53267u, 53269u, 53279u, + 53281u, 53299u, 53309u, 53323u, 53327u, 53353u, 53359u, 53377u, 53381u, + 53401u, 53407u, 53411u, 53419u, 53437u, 53441u, 53453u, 53479u, 53503u, + 53507u, 53527u, 53549u, 53551u, 53569u, 53591u, 53593u, 53597u, 53609u, + 53611u, 53617u, 53623u, 53629u, 53633u, 53639u, 53653u, 53657u, 53681u, + 53693u, 53699u, 53717u, 53719u, 53731u, 53759u, 53773u, 53777u, 53783u, + 53791u, 53813u, 53819u, 53831u, 53849u, 53857u, 53861u, 53881u, 53887u, + 53891u, 53897u, 53899u, 53917u, 53923u, 53927u, 53939u, 53951u, 53959u, + 53987u, 53993u, 54001u, 54011u, 54013u, 54037u, 54049u, 54059u, 54083u, + 54091u, 54101u, 54121u, 54133u, 54139u, 54151u, 54163u, 54167u, 54181u, + 54193u, 54217u, 54251u, 54269u, 54277u, 54287u, 54293u, 54311u, 54319u, + 54323u, 54331u, 54347u, 54361u, 54367u, 54371u, 54377u, 54401u, 54403u, + 54409u, 54413u, 54419u, 54421u, 54437u, 54443u, 54449u, 54469u, 54493u, + 54497u, 54499u, 54503u, 54517u, 54521u, 54539u, 54541u, 54547u, 54559u, + 54563u, 54577u, 54581u, 54583u, 54601u, 54617u, 54623u, 54629u, 54631u, + 54647u, 54667u, 54673u, 54679u, 54709u, 54713u, 54721u, 54727u, 54751u, + 54767u, 54773u, 54779u, 54787u, 54799u, 54829u, 54833u, 54851u, 54869u, + 54877u, 54881u, 54907u, 54917u, 54919u, 54941u, 54949u, 54959u, 54973u, + 54979u, 54983u, 55001u, 55009u, 55021u, 55049u, 55051u, 55057u, 55061u, + 55073u, 55079u, 55103u, 55109u, 55117u, 55127u, 55147u, 55163u, 55171u, + 55201u, 55207u, 55213u, 55217u, 55219u, 55229u, 55243u, 55249u, 55259u, + 55291u, 55313u, 55331u, 55333u, 55337u, 55339u, 55343u, 55351u, 55373u, + 55381u, 55399u, 55411u, 55439u, 55441u, 55457u, 55469u, 55487u, 55501u, + 55511u, 55529u, 55541u, 55547u, 55579u, 55589u, 55603u, 55609u, 55619u, + 55621u, 55631u, 55633u, 55639u, 55661u, 55663u, 55667u, 55673u, 55681u, + 55691u, 55697u, 55711u, 55717u, 55721u, 55733u, 55763u, 55787u, 55793u, + 55799u, 55807u, 55813u, 55817u, 55819u, 55823u, 55829u, 55837u, 55843u, + 55849u, 55871u, 55889u, 55897u, 55901u, 55903u, 55921u, 55927u, 55931u, + 55933u, 55949u, 55967u, 55987u, 55997u, 56003u, 56009u, 56039u, 56041u, + 56053u, 56081u, 56087u, 56093u, 56099u, 56101u, 56113u, 56123u, 56131u, + 56149u, 56167u, 56171u, 56179u, 56197u, 56207u, 56209u, 56237u, 56239u, + 56249u, 56263u, 56267u, 56269u, 56299u, 56311u, 56333u, 56359u, 56369u, + 56377u, 56383u, 56393u, 56401u, 56417u, 56431u, 56437u, 56443u, 56453u, + 56467u, 56473u, 56477u, 56479u, 56489u, 56501u, 56503u, 56509u, 56519u, + 56527u, 56531u, 56533u, 56543u, 56569u, 56591u, 56597u, 56599u, 56611u, + 56629u, 56633u, 56659u, 56663u, 56671u, 56681u, 56687u, 56701u, 56711u, + 56713u, 56731u, 56737u, 56747u, 56767u, 56773u, 56779u, 56783u, 56807u, + 56809u, 56813u, 56821u, 56827u, 56843u, 56857u, 56873u, 56891u, 56893u, + 56897u, 56909u, 56911u, 56921u, 56923u, 56929u, 56941u, 56951u, 56957u, + 56963u, 56983u, 56989u, 56993u, 56999u, 57037u, 57041u, 57047u, 57059u, + 57073u, 57077u, 57089u, 57097u, 57107u, 57119u, 57131u, 57139u, 57143u, + 57149u, 57163u, 57173u, 57179u, 57191u, 57193u, 57203u, 57221u, 57223u, + 57241u, 57251u, 57259u, 57269u, 57271u, 57283u, 57287u, 57301u, 57329u, + 57331u, 57347u, 57349u, 57367u, 57373u, 57383u, 57389u, 57397u, 57413u, + 57427u, 57457u, 57467u, 57487u, 57493u, 57503u, 57527u, 57529u, 57557u, + 57559u, 57571u, 57587u, 57593u, 57601u, 57637u, 57641u, 57649u, 57653u, + 57667u, 57679u, 57689u, 57697u, 57709u, 57713u, 57719u, 57727u, 57731u, + 57737u, 57751u, 57773u, 57781u, 57787u, 57791u, 57793u, 57803u, 57809u, + 57829u, 57839u, 57847u, 57853u, 57859u, 57881u, 57899u, 57901u, 57917u, + 57923u, 57943u, 57947u, 57973u, 57977u, 57991u, 58013u, 58027u, 58031u, + 58043u, 58049u, 58057u, 58061u, 58067u, 58073u, 58099u, 58109u, 58111u, + 58129u, 58147u, 58151u, 58153u, 58169u, 58171u, 58189u, 58193u, 58199u, + 58207u, 58211u, 58217u, 58229u, 58231u, 58237u, 58243u, 58271u, 58309u, + 58313u, 58321u, 58337u, 58363u, 58367u, 58369u, 58379u, 58391u, 58393u, + 58403u, 58411u, 58417u, 58427u, 58439u, 58441u, 58451u, 58453u, 58477u, + 58481u, 58511u, 58537u, 58543u, 58549u, 58567u, 58573u, 58579u, 58601u, + 58603u, 58613u, 58631u, 58657u, 58661u, 58679u, 58687u, 58693u, 58699u, + 58711u, 58727u, 58733u, 58741u, 58757u, 58763u, 58771u, 58787u, 58789u, + 58831u, 58889u, 58897u, 58901u, 58907u, 58909u, 58913u, 58921u, 58937u, + 58943u, 58963u, 58967u, 58979u, 58991u, 58997u, 59009u, 59011u, 59021u, + 59023u, 59029u, 59051u, 59053u, 59063u, 59069u, 59077u, 59083u, 59093u, + 59107u, 59113u, 59119u, 59123u, 59141u, 59149u, 59159u, 59167u, 59183u, + 59197u, 59207u, 59209u, 59219u, 59221u, 59233u, 59239u, 59243u, 59263u, + 59273u, 59281u, 59333u, 59341u, 59351u, 59357u, 59359u, 59369u, 59377u, + 59387u, 59393u, 59399u, 59407u, 59417u, 59419u, 59441u, 59443u, 59447u, + 59453u, 59467u, 59471u, 59473u, 59497u, 59509u, 59513u, 59539u, 59557u, + 59561u, 59567u, 59581u, 59611u, 59617u, 59621u, 59627u, 59629u, 59651u, + 59659u, 59663u, 59669u, 59671u, 59693u, 59699u, 59707u, 59723u, 59729u, + 59743u, 59747u, 59753u, 59771u, 59779u, 59791u, 59797u, 59809u, 59833u, + 59863u, 59879u, 59887u, 59921u, 59929u, 59951u, 59957u, 59971u, 59981u, + 59999u, 60013u, 60017u, 60029u, 60037u, 60041u, 60077u, 60083u, 60089u, + 60091u, 60101u, 60103u, 60107u, 60127u, 60133u, 60139u, 60149u, 60161u, + 60167u, 60169u, 60209u, 60217u, 60223u, 60251u, 60257u, 60259u, 60271u, + 60289u, 60293u, 60317u, 60331u, 60337u, 60343u, 60353u, 60373u, 60383u, + 60397u, 60413u, 60427u, 60443u, 60449u, 60457u, 60493u, 60497u, 60509u, + 60521u, 60527u, 60539u, 60589u, 60601u, 60607u, 60611u, 60617u, 60623u, + 60631u, 60637u, 60647u, 60649u, 60659u, 60661u, 60679u, 60689u, 60703u, + 60719u, 60727u, 60733u, 60737u, 60757u, 60761u, 60763u, 60773u, 60779u, + 60793u, 60811u, 60821u, 60859u, 60869u, 60887u, 60889u, 60899u, 60901u, + 60913u, 60917u, 60919u, 60923u, 60937u, 60943u, 60953u, 60961u, 61001u, + 61007u, 61027u, 61031u, 61043u, 61051u, 61057u, 61091u, 61099u, 61121u, + 61129u, 61141u, 61151u, 61153u, 61169u, 61211u, 61223u, 61231u, 61253u, + 61261u, 61283u, 61291u, 61297u, 61331u, 61333u, 61339u, 61343u, 61357u, + 61363u, 61379u, 61381u, 61403u, 61409u, 61417u, 61441u, 61463u, 61469u, + 61471u, 61483u, 61487u, 61493u, 61507u, 61511u, 61519u, 61543u, 61547u, + 61553u, 61559u, 61561u, 61583u, 61603u, 61609u, 61613u, 61627u, 61631u, + 61637u, 61643u, 61651u, 61657u, 61667u, 61673u, 61681u, 61687u, 61703u, + 61717u, 61723u, 61729u, 61751u, 61757u, 61781u, 61813u, 61819u, 61837u, + 61843u, 61861u, 61871u, 61879u, 61909u, 61927u, 61933u, 61949u, 61961u, + 61967u, 61979u, 61981u, 61987u, 61991u, 62003u, 62011u, 62017u, 62039u, + 62047u, 62053u, 62057u, 62071u, 62081u, 62099u, 62119u, 62129u, 62131u, + 62137u, 62141u, 62143u, 62171u, 62189u, 62191u, 62201u, 62207u, 62213u, + 62219u, 62233u, 62273u, 62297u, 62299u, 62303u, 62311u, 62323u, 62327u, + 62347u, 62351u, 62383u, 62401u, 62417u, 62423u, 62459u, 62467u, 62473u, + 62477u, 62483u, 62497u, 62501u, 62507u, 62533u, 62539u, 62549u, 62563u, + 62581u, 62591u, 62597u, 62603u, 62617u, 62627u, 62633u, 62639u, 62653u, + 62659u, 62683u, 62687u, 62701u, 62723u, 62731u, 62743u, 62753u, 62761u, + 62773u, 62791u, 62801u, 62819u, 62827u, 62851u, 62861u, 62869u, 62873u, + 62897u, 62903u, 62921u, 62927u, 62929u, 62939u, 62969u, 62971u, 62981u, + 62983u, 62987u, 62989u, 63029u, 63031u, 63059u, 63067u, 63073u, 63079u, + 63097u, 63103u, 63113u, 63127u, 63131u, 63149u, 63179u, 63197u, 63199u, + 63211u, 63241u, 63247u, 63277u, 63281u, 63299u, 63311u, 63313u, 63317u, + 63331u, 63337u, 63347u, 63353u, 63361u, 63367u, 63377u, 63389u, 63391u, + 63397u, 63409u, 63419u, 63421u, 63439u, 63443u, 63463u, 63467u, 63473u, + 63487u, 63493u, 63499u, 63521u, 63527u, 63533u, 63541u, 63559u, 63577u, + 63587u, 63589u, 63599u, 63601u, 63607u, 63611u, 63617u, 63629u, 63647u, + 63649u, 63659u, 63667u, 63671u, 63689u, 63691u, 63697u, 63703u, 63709u, + 63719u, 63727u, 63737u, 63743u, 63761u, 63773u, 63781u, 63793u, 63799u, + 63803u, 63809u, 63823u, 63839u, 63841u, 63853u, 63857u, 63863u, 63901u, + 63907u, 63913u, 63929u, 63949u, 63977u, 63997u, 64007u, 64013u, 64019u, + 64033u, 64037u, 64063u, 64067u, 64081u, 64091u, 64109u, 64123u, 64151u, + 64153u, 64157u, 64171u, 64187u, 64189u, 64217u, 64223u, 64231u, 64237u, + 64271u, 64279u, 64283u, 64301u, 64303u, 64319u, 64327u, 64333u, 64373u, + 64381u, 64399u, 64403u, 64433u, 64439u, 64451u, 64453u, 64483u, 64489u, + 64499u, 64513u, 64553u, 64567u, 64577u, 64579u, 64591u, 64601u, 64609u, + 64613u, 64621u, 64627u, 64633u, 64661u, 64663u, 64667u, 64679u, 64693u, + 64709u, 64717u, 64747u, 64763u, 64781u, 64783u, 64793u, 64811u, 64817u, + 64849u, 64853u, 64871u, 64877u, 64879u, 64891u, 64901u, 64919u, 64921u, + 64927u, 64937u, 64951u, 64969u, 64997u, 65003u, 65011u, 65027u, 65029u, + 65033u, 65053u, 65063u, 65071u, 65089u, 65099u, 65101u, 65111u, 65119u, + 65123u, 65129u, 65141u, 65147u, 65167u, 65171u, 65173u, 65179u, 65183u, + 65203u, 65213u, 65239u, 65257u, 65267u, 65269u, 65287u, 65293u, 65309u, + 65323u, 65327u, 65353u, 65357u, 65371u, 65381u, 65393u, 65407u, 65413u, + 65419u, 65423u, 65437u, 65447u, 65449u, 65479u, 65497u, 65519u, 65521u + }; + static const boost::array<boost::uint16_t, 3458> a3 = { + 2u, 4u, 8u, 16u, 22u, 28u, 44u, + 46u, 52u, 64u, 74u, 82u, 94u, 98u, 112u, + 116u, 122u, 142u, 152u, 164u, 166u, 172u, 178u, + 182u, 184u, 194u, 196u, 226u, 242u, 254u, 274u, + 292u, 296u, 302u, 304u, 308u, 316u, 332u, 346u, + 364u, 386u, 392u, 394u, 416u, 422u, 428u, 446u, + 448u, 458u, 494u, 502u, 506u, 512u, 532u, 536u, + 548u, 554u, 568u, 572u, 574u, 602u, 626u, 634u, + 638u, 644u, 656u, 686u, 704u, 736u, 758u, 766u, + 802u, 808u, 812u, 824u, 826u, 838u, 842u, 848u, + 868u, 878u, 896u, 914u, 922u, 928u, 932u, 956u, + 964u, 974u, 988u, 994u, 998u, 1006u, 1018u, 1034u, + 1036u, 1052u, 1058u, 1066u, 1082u, 1094u, 1108u, 1118u, + 1148u, 1162u, 1166u, 1178u, 1186u, 1198u, 1204u, 1214u, + 1216u, 1228u, 1256u, 1262u, 1274u, 1286u, 1306u, 1316u, + 1318u, 1328u, 1342u, 1348u, 1354u, 1384u, 1388u, 1396u, + 1408u, 1412u, 1414u, 1424u, 1438u, 1442u, 1468u, 1486u, + 1498u, 1508u, 1514u, 1522u, 1526u, 1538u, 1544u, 1568u, + 1586u, 1594u, 1604u, 1606u, 1618u, 1622u, 1634u, 1646u, + 1652u, 1654u, 1676u, 1678u, 1682u, 1684u, 1696u, 1712u, + 1726u, 1736u, 1738u, 1754u, 1772u, 1804u, 1808u, 1814u, + 1834u, 1856u, 1864u, 1874u, 1876u, 1886u, 1892u, 1894u, + 1898u, 1912u, 1918u, 1942u, 1946u, 1954u, 1958u, 1964u, + 1976u, 1988u, 1996u, 2002u, 2012u, 2024u, 2032u, 2042u, + 2044u, 2054u, 2066u, 2072u, 2084u, 2096u, 2116u, 2144u, + 2164u, 2174u, 2188u, 2198u, 2206u, 2216u, 2222u, 2224u, + 2228u, 2242u, 2248u, 2254u, 2266u, 2272u, 2284u, 2294u, + 2308u, 2318u, 2332u, 2348u, 2356u, 2366u, 2392u, 2396u, + 2398u, 2404u, 2408u, 2422u, 2426u, 2432u, 2444u, 2452u, + 2458u, 2488u, 2506u, 2518u, 2524u, 2536u, 2552u, 2564u, + 2576u, 2578u, 2606u, 2612u, 2626u, 2636u, 2672u, 2674u, + 2678u, 2684u, 2692u, 2704u, 2726u, 2744u, 2746u, 2776u, + 2794u, 2816u, 2836u, 2854u, 2864u, 2902u, 2908u, 2912u, + 2914u, 2938u, 2942u, 2948u, 2954u, 2956u, 2966u, 2972u, + 2986u, 2996u, 3004u, 3008u, 3032u, 3046u, 3062u, 3076u, + 3098u, 3104u, 3124u, 3134u, 3148u, 3152u, 3164u, 3176u, + 3178u, 3194u, 3202u, 3208u, 3214u, 3232u, 3236u, 3242u, + 3256u, 3278u, 3284u, 3286u, 3328u, 3344u, 3346u, 3356u, + 3362u, 3364u, 3368u, 3374u, 3382u, 3392u, 3412u, 3428u, + 3458u, 3466u, 3476u, 3484u, 3494u, 3496u, 3526u, 3532u, + 3538u, 3574u, 3584u, 3592u, 3608u, 3614u, 3616u, 3628u, + 3656u, 3658u, 3662u, 3668u, 3686u, 3698u, 3704u, 3712u, + 3722u, 3724u, 3728u, 3778u, 3782u, 3802u, 3806u, 3836u, + 3844u, 3848u, 3854u, 3866u, 3868u, 3892u, 3896u, 3904u, + 3922u, 3928u, 3932u, 3938u, 3946u, 3956u, 3958u, 3962u, + 3964u, 4004u, 4022u, 4058u, 4088u, 4118u, 4126u, 4142u, + 4156u, 4162u, 4174u, 4202u, 4204u, 4226u, 4228u, 4232u, + 4244u, 4274u, 4286u, 4292u, 4294u, 4298u, 4312u, 4322u, + 4324u, 4342u, 4364u, 4376u, 4394u, 4396u, 4406u, 4424u, + 4456u, 4462u, 4466u, 4468u, 4474u, 4484u, 4504u, 4516u, + 4526u, 4532u, 4544u, 4564u, 4576u, 4582u, 4586u, 4588u, + 4604u, 4606u, 4622u, 4628u, 4642u, 4646u, 4648u, 4664u, + 4666u, 4672u, 4688u, 4694u, 4702u, 4706u, 4714u, 4736u, + 4754u, 4762u, 4774u, 4778u, 4786u, 4792u, 4816u, 4838u, + 4844u, 4846u, 4858u, 4888u, 4894u, 4904u, 4916u, 4922u, + 4924u, 4946u, 4952u, 4954u, 4966u, 4972u, 4994u, 5002u, + 5014u, 5036u, 5038u, 5048u, 5054u, 5072u, 5084u, 5086u, + 5092u, 5104u, 5122u, 5128u, 5132u, 5152u, 5174u, 5182u, + 5194u, 5218u, 5234u, 5248u, 5258u, 5288u, 5306u, 5308u, + 5314u, 5318u, 5332u, 5342u, 5344u, 5356u, 5366u, 5378u, + 5384u, 5386u, 5402u, 5414u, 5416u, 5422u, 5434u, 5444u, + 5446u, 5456u, 5462u, 5464u, 5476u, 5488u, 5504u, 5524u, + 5534u, 5546u, 5554u, 5584u, 5594u, 5608u, 5612u, 5618u, + 5626u, 5632u, 5636u, 5656u, 5674u, 5698u, 5702u, 5714u, + 5722u, 5726u, 5728u, 5752u, 5758u, 5782u, 5792u, 5794u, + 5798u, 5804u, 5806u, 5812u, 5818u, 5824u, 5828u, 5852u, + 5854u, 5864u, 5876u, 5878u, 5884u, 5894u, 5902u, 5908u, + 5918u, 5936u, 5938u, 5944u, 5948u, 5968u, 5992u, 6002u, + 6014u, 6016u, 6028u, 6034u, 6058u, 6062u, 6098u, 6112u, + 6128u, 6136u, 6158u, 6164u, 6172u, 6176u, 6178u, 6184u, + 6206u, 6226u, 6242u, 6254u, 6272u, 6274u, 6286u, 6302u, + 6308u, 6314u, 6326u, 6332u, 6344u, 6346u, 6352u, 6364u, + 6374u, 6382u, 6398u, 6406u, 6412u, 6428u, 6436u, 6448u, + 6452u, 6458u, 6464u, 6484u, 6496u, 6508u, 6512u, 6518u, + 6538u, 6542u, 6554u, 6556u, 6566u, 6568u, 6574u, 6604u, + 6626u, 6632u, 6634u, 6638u, 6676u, 6686u, 6688u, 6692u, + 6694u, 6716u, 6718u, 6734u, 6736u, 6742u, 6752u, 6772u, + 6778u, 6802u, 6806u, 6818u, 6832u, 6844u, 6848u, 6886u, + 6896u, 6926u, 6932u, 6934u, 6946u, 6958u, 6962u, 6968u, + 6998u, 7012u, 7016u, 7024u, 7042u, 7078u, 7082u, 7088u, + 7108u, 7112u, 7114u, 7126u, 7136u, 7138u, 7144u, 7154u, + 7166u, 7172u, 7184u, 7192u, 7198u, 7204u, 7228u, 7232u, + 7262u, 7282u, 7288u, 7324u, 7334u, 7336u, 7348u, 7354u, + 7358u, 7366u, 7372u, 7376u, 7388u, 7396u, 7402u, 7414u, + 7418u, 7424u, 7438u, 7442u, 7462u, 7474u, 7478u, 7484u, + 7502u, 7504u, 7508u, 7526u, 7528u, 7544u, 7556u, 7586u, + 7592u, 7598u, 7606u, 7646u, 7654u, 7702u, 7708u, 7724u, + 7742u, 7756u, 7768u, 7774u, 7792u, 7796u, 7816u, 7826u, + 7828u, 7834u, 7844u, 7852u, 7882u, 7886u, 7898u, 7918u, + 7924u, 7936u, 7942u, 7948u, 7982u, 7988u, 7994u, 8012u, + 8018u, 8026u, 8036u, 8048u, 8054u, 8062u, 8072u, 8074u, + 8078u, 8102u, 8108u, 8116u, 8138u, 8144u, 8146u, 8158u, + 8164u, 8174u, 8186u, 8192u, 8216u, 8222u, 8236u, 8248u, + 8284u, 8288u, 8312u, 8314u, 8324u, 8332u, 8342u, 8348u, + 8362u, 8372u, 8404u, 8408u, 8416u, 8426u, 8438u, 8464u, + 8482u, 8486u, 8492u, 8512u, 8516u, 8536u, 8542u, 8558u, + 8564u, 8566u, 8596u, 8608u, 8614u, 8624u, 8626u, 8632u, + 8642u, 8654u, 8662u, 8666u, 8668u, 8674u, 8684u, 8696u, + 8722u, 8744u, 8752u, 8758u, 8762u, 8776u, 8782u, 8788u, + 8818u, 8822u, 8828u, 8842u, 8846u, 8848u, 8876u, 8878u, + 8884u, 8906u, 8914u, 8918u, 8936u, 8954u, 8972u, 8974u, + 8986u, 8992u, 8996u, 9016u, 9026u, 9032u, 9038u, 9052u, + 9062u, 9074u, 9076u, 9088u, 9118u, 9152u, 9164u, 9172u, + 9178u, 9182u, 9184u, 9194u, 9196u, 9212u, 9224u, 9226u, + 9236u, 9244u, 9262u, 9286u, 9292u, 9296u, 9308u, 9322u, + 9326u, 9334u, 9338u, 9352u, 9356u, 9362u, 9368u, 9388u, + 9394u, 9398u, 9406u, 9424u, 9476u, 9478u, 9482u, 9494u, + 9502u, 9506u, 9544u, 9548u, 9574u, 9598u, 9614u, 9626u, + 9632u, 9634u, 9646u, 9658u, 9674u, 9676u, 9682u, 9688u, + 9692u, 9704u, 9718u, 9734u, 9742u, 9754u, 9772u, 9788u, + 9794u, 9802u, 9812u, 9818u, 9832u, 9842u, 9854u, 9856u, + 9866u, 9868u, 9872u, 9896u, 9902u, 9944u, 9968u, 9976u, + 9986u, 9992u, 9998u, 10004u, 10006u, 10018u, 10022u, 10036u, + 10042u, 10048u, 10076u, 10082u, 10084u, 10094u, 10106u, 10118u, + 10124u, 10144u, 10148u, 10154u, 10168u, 10172u, 10174u, 10186u, + 10196u, 10208u, 10232u, 10238u, 10246u, 10252u, 10258u, 10262u, + 10286u, 10298u, 10318u, 10334u, 10348u, 10378u, 10396u, 10402u, + 10406u, 10432u, 10444u, 10448u, 10454u, 10456u, 10462u, 10466u, + 10468u, 10496u, 10504u, 10544u, 10546u, 10556u, 10564u, 10568u, + 10588u, 10594u, 10612u, 10622u, 10624u, 10628u, 10672u, 10678u, + 10696u, 10708u, 10714u, 10718u, 10724u, 10726u, 10748u, 10754u, + 10768u, 10798u, 10808u, 10832u, 10834u, 10844u, 10852u, 10868u, + 10886u, 10888u, 10906u, 10928u, 10936u, 10946u, 10952u, 10958u, + 10972u, 10976u, 10984u, 11002u, 11006u, 11008u, 11026u, 11044u, + 11062u, 11068u, 11072u, 11096u, 11114u, 11116u, 11132u, 11138u, + 11144u, 11162u, 11182u, 11198u, 11218u, 11222u, 11236u, 11242u, + 11246u, 11266u, 11284u, 11294u, 11296u, 11302u, 11312u, 11336u, + 11338u, 11348u, 11372u, 11378u, 11384u, 11408u, 11414u, 11426u, + 11428u, 11456u, 11468u, 11482u, 11488u, 11494u, 11506u, 11512u, + 11534u, 11546u, 11558u, 11566u, 11602u, 11606u, 11618u, 11632u, + 11636u, 11656u, 11666u, 11678u, 11702u, 11704u, 11708u, 11714u, + 11726u, 11728u, 11732u, 11734u, 11744u, 11756u, 11782u, 11788u, + 11804u, 11812u, 11816u, 11824u, 11834u, 11842u, 11848u, 11882u, + 11884u, 11896u, 11912u, 11936u, 11942u, 11944u, 11954u, 11956u, + 11974u, 11978u, 11986u, 11992u, 12008u, 12014u, 12016u, 12022u, + 12028u, 12034u, 12038u, 12052u, 12056u, 12076u, 12082u, 12086u, + 12106u, 12112u, 12124u, 12146u, 12152u, 12154u, 12164u, 12176u, + 12178u, 12184u, 12188u, 12196u, 12208u, 12212u, 12226u, 12238u, + 12248u, 12262u, 12266u, 12278u, 12304u, 12314u, 12328u, 12332u, + 12358u, 12364u, 12394u, 12398u, 12416u, 12434u, 12442u, 12448u, + 12464u, 12472u, 12482u, 12496u, 12506u, 12514u, 12524u, 12544u, + 12566u, 12586u, 12602u, 12604u, 12622u, 12628u, 12632u, 12638u, + 12644u, 12656u, 12658u, 12668u, 12694u, 12698u, 12706u, 12724u, + 12742u, 12748u, 12766u, 12772u, 12776u, 12782u, 12806u, 12812u, + 12832u, 12866u, 12892u, 12902u, 12904u, 12932u, 12944u, 12952u, + 12962u, 12974u, 12976u, 12982u, 13004u, 13006u, 13018u, 13034u, + 13036u, 13042u, 13048u, 13058u, 13072u, 13088u, 13108u, 13114u, + 13118u, 13156u, 13162u, 13172u, 13178u, 13186u, 13202u, 13244u, + 13246u, 13252u, 13256u, 13262u, 13268u, 13274u, 13288u, 13304u, + 13318u, 13322u, 13342u, 13352u, 13354u, 13358u, 13366u, 13384u, + 13394u, 13406u, 13442u, 13444u, 13454u, 13496u, 13504u, 13508u, + 13528u, 13552u, 13568u, 13576u, 13598u, 13604u, 13612u, 13616u, + 13618u, 13624u, 13646u, 13652u, 13658u, 13666u, 13694u, 13696u, + 13706u, 13724u, 13738u, 13744u, 13748u, 13766u, 13774u, 13784u, + 13798u, 13802u, 13814u, 13822u, 13832u, 13844u, 13858u, 13862u, + 13864u, 13876u, 13888u, 13892u, 13898u, 13916u, 13946u, 13958u, + 13996u, 14002u, 14014u, 14024u, 14026u, 14044u, 14054u, 14066u, + 14074u, 14078u, 14086u, 14092u, 14096u, 14098u, 14122u, 14134u, + 14152u, 14156u, 14158u, 14162u, 14164u, 14222u, 14234u, 14242u, + 14266u, 14276u, 14278u, 14282u, 14288u, 14294u, 14306u, 14308u, + 14312u, 14326u, 14332u, 14338u, 14354u, 14366u, 14368u, 14372u, + 14404u, 14408u, 14432u, 14438u, 14444u, 14452u, 14462u, 14464u, + 14486u, 14504u, 14516u, 14536u, 14542u, 14572u, 14576u, 14606u, + 14612u, 14614u, 14618u, 14632u, 14638u, 14642u, 14656u, 14672u, + 14674u, 14686u, 14696u, 14698u, 14704u, 14716u, 14728u, 14738u, + 14744u, 14752u, 14774u, 14782u, 14794u, 14806u, 14812u, 14828u, + 14834u, 14852u, 14872u, 14894u, 14912u, 14914u, 14936u, 14938u, + 14954u, 14956u, 14978u, 14992u, 15002u, 15022u, 15032u, 15064u, + 15068u, 15076u, 15086u, 15092u, 15094u, 15116u, 15122u, 15134u, + 15136u, 15142u, 15146u, 15148u, 15152u, 15166u, 15178u, 15202u, + 15212u, 15214u, 15226u, 15242u, 15244u, 15248u, 15254u, 15268u, + 15274u, 15284u, 15296u, 15298u, 15314u, 15328u, 15362u, 15374u, + 15376u, 15382u, 15388u, 15394u, 15398u, 15418u, 15428u, 15454u, + 15466u, 15478u, 15482u, 15484u, 15488u, 15496u, 15506u, 15508u, + 15512u, 15514u, 15536u, 15542u, 15548u, 15562u, 15566u, 15584u, + 15596u, 15622u, 15628u, 15638u, 15646u, 15662u, 15664u, 15668u, + 15688u, 15698u, 15704u, 15746u, 15748u, 15758u, 15764u, 15772u, + 15796u, 15808u, 15814u, 15818u, 15824u, 15836u, 15838u, 15866u, + 15874u, 15886u, 15904u, 15922u, 15928u, 15974u, 15982u, 15992u, + 15998u, 16012u, 16016u, 16018u, 16024u, 16028u, 16034u, 16076u, + 16084u, 16094u, 16102u, 16112u, 16114u, 16132u, 16136u, 16142u, + 16154u, 16166u, 16168u, 16172u, 16192u, 16202u, 16214u, 16226u, + 16234u, 16238u, 16264u, 16282u, 16304u, 16312u, 16318u, 16334u, + 16348u, 16364u, 16366u, 16384u, 16394u, 16396u, 16402u, 16408u, + 16418u, 16432u, 16436u, 16438u, 16468u, 16472u, 16474u, 16478u, + 16486u, 16496u, 16502u, 16504u, 16516u, 16532u, 16538u, 16594u, + 16604u, 16606u, 16618u, 16628u, 16636u, 16648u, 16654u, 16658u, + 16672u, 16682u, 16684u, 16688u, 16696u, 16702u, 16706u, 16726u, + 16732u, 16744u, 16766u, 16772u, 16804u, 16814u, 16816u, 16826u, + 16838u, 16852u, 16858u, 16886u, 16922u, 16928u, 16934u, 16936u, + 16948u, 16952u, 16958u, 16964u, 16972u, 16994u, 16996u, 17014u, + 17024u, 17026u, 17032u, 17036u, 17056u, 17066u, 17074u, 17078u, + 17084u, 17098u, 17116u, 17122u, 17164u, 17186u, 17188u, 17192u, + 17194u, 17222u, 17224u, 17228u, 17246u, 17252u, 17258u, 17264u, + 17276u, 17278u, 17302u, 17312u, 17348u, 17354u, 17356u, 17368u, + 17378u, 17404u, 17428u, 17446u, 17462u, 17468u, 17474u, 17488u, + 17512u, 17524u, 17528u, 17536u, 17542u, 17554u, 17558u, 17566u, + 17582u, 17602u, 17642u, 17668u, 17672u, 17684u, 17686u, 17692u, + 17696u, 17698u, 17708u, 17722u, 17732u, 17734u, 17738u, 17764u, + 17776u, 17804u, 17806u, 17822u, 17848u, 17854u, 17864u, 17866u, + 17872u, 17882u, 17888u, 17896u, 17902u, 17908u, 17914u, 17924u, + 17936u, 17942u, 17962u, 18002u, 18022u, 18026u, 18028u, 18044u, + 18056u, 18062u, 18074u, 18082u, 18086u, 18104u, 18106u, 18118u, + 18128u, 18154u, 18166u, 18182u, 18184u, 18202u, 18226u, 18238u, + 18242u, 18256u, 18278u, 18298u, 18308u, 18322u, 18334u, 18338u, + 18356u, 18368u, 18376u, 18386u, 18398u, 18404u, 18434u, 18448u, + 18452u, 18476u, 18482u, 18512u, 18518u, 18524u, 18526u, 18532u, + 18554u, 18586u, 18592u, 18596u, 18602u, 18608u, 18628u, 18644u, + 18646u, 18656u, 18664u, 18676u, 18686u, 18688u, 18694u, 18704u, + 18712u, 18728u, 18764u, 18772u, 18778u, 18782u, 18784u, 18812u, + 18814u, 18842u, 18854u, 18856u, 18866u, 18872u, 18886u, 18896u, + 18902u, 18908u, 18914u, 18922u, 18928u, 18932u, 18946u, 18964u, + 18968u, 18974u, 18986u, 18988u, 18998u, 19016u, 19024u, 19054u, + 19094u, 19096u, 19114u, 19118u, 19124u, 19138u, 19156u, 19162u, + 19166u, 19178u, 19184u, 19196u, 19202u, 19216u, 19226u, 19252u, + 19258u, 19274u, 19276u, 19292u, 19322u, 19324u, 19334u, 19336u, + 19378u, 19384u, 19412u, 19426u, 19432u, 19442u, 19444u, 19456u, + 19474u, 19486u, 19492u, 19502u, 19514u, 19526u, 19546u, 19552u, + 19556u, 19558u, 19568u, 19574u, 19586u, 19598u, 19612u, 19624u, + 19658u, 19664u, 19666u, 19678u, 19688u, 19694u, 19702u, 19708u, + 19712u, 19724u, 19762u, 19768u, 19778u, 19796u, 19798u, 19826u, + 19828u, 19834u, 19846u, 19876u, 19892u, 19894u, 19904u, 19912u, + 19916u, 19918u, 19934u, 19952u, 19978u, 19982u, 19988u, 19996u, + 20014u, 20036u, 20042u, 20062u, 20066u, 20072u, 20084u, 20086u, + 20092u, 20104u, 20108u, 20126u, 20132u, 20134u, 20156u, 20168u, + 20176u, 20182u, 20198u, 20216u, 20246u, 20258u, 20282u, 20284u, + 20294u, 20296u, 20302u, 20308u, 20312u, 20318u, 20354u, 20368u, + 20374u, 20396u, 20398u, 20456u, 20464u, 20476u, 20482u, 20492u, + 20494u, 20534u, 20542u, 20548u, 20576u, 20578u, 20582u, 20596u, + 20602u, 20608u, 20626u, 20636u, 20644u, 20648u, 20662u, 20666u, + 20674u, 20704u, 20708u, 20714u, 20722u, 20728u, 20734u, 20752u, + 20756u, 20758u, 20762u, 20776u, 20788u, 20806u, 20816u, 20818u, + 20822u, 20834u, 20836u, 20846u, 20854u, 20864u, 20878u, 20888u, + 20906u, 20918u, 20926u, 20932u, 20942u, 20956u, 20966u, 20974u, + 20996u, 20998u, 21004u, 21026u, 21038u, 21044u, 21052u, 21064u, + 21092u, 21094u, 21142u, 21154u, 21158u, 21176u, 21184u, 21194u, + 21208u, 21218u, 21232u, 21236u, 21248u, 21278u, 21302u, 21308u, + 21316u, 21322u, 21326u, 21334u, 21388u, 21392u, 21394u, 21404u, + 21416u, 21424u, 21434u, 21446u, 21458u, 21476u, 21478u, 21502u, + 21506u, 21514u, 21536u, 21548u, 21568u, 21572u, 21584u, 21586u, + 21598u, 21614u, 21616u, 21644u, 21646u, 21652u, 21676u, 21686u, + 21688u, 21716u, 21718u, 21722u, 21742u, 21746u, 21758u, 21764u, + 21778u, 21782u, 21788u, 21802u, 21824u, 21848u, 21868u, 21872u, + 21886u, 21892u, 21898u, 21908u, 21938u, 21946u, 21956u, 21974u, + 21976u, 21982u, 21988u, 22004u, 22006u, 22012u, 22018u, 22022u, + 22024u, 22048u, 22052u, 22054u, 22078u, 22088u, 22094u, 22096u, + 22106u, 22108u, 22114u, 22136u, 22144u, 22148u, 22156u, 22162u, + 22166u, 22184u, 22186u, 22204u, 22208u, 22216u, 22232u, 22258u, + 22262u, 22268u, 22276u, 22298u, 22318u, 22334u, 22342u, 22346u, + 22352u, 22376u, 22382u, 22396u, 22408u, 22424u, 22426u, 22438u, + 22442u, 22456u, 22466u, 22468u, 22472u, 22484u, 22502u, 22534u, + 22544u, 22558u, 22582u, 22594u, 22634u, 22642u, 22676u, 22688u, + 22702u, 22706u, 22724u, 22726u, 22754u, 22766u, 22786u, 22792u, + 22802u, 22804u, 22844u, 22862u, 22876u, 22888u, 22892u, 22928u, + 22934u, 22936u, 22958u, 22964u, 22978u, 22988u, 23012u, 23054u, + 23056u, 23072u, 23074u, 23108u, 23116u, 23122u, 23126u, 23128u, + 23132u, 23146u, 23186u, 23194u, 23206u, 23212u, 23236u, 23254u, + 23258u, 23264u, 23266u, 23272u, 23276u, 23278u, 23282u, 23284u, + 23308u, 23318u, 23326u, 23332u, 23338u, 23348u, 23362u, 23368u, + 23384u, 23402u, 23416u, 23434u, 23458u, 23462u, 23468u, 23474u, + 23482u, 23486u, 23506u, 23516u, 23522u, 23534u, 23536u, 23548u, + 23552u, 23566u, 23572u, 23578u, 23584u, 23588u, 23602u, 23618u, + 23654u, 23668u, 23674u, 23678u, 23692u, 23696u, 23702u, 23726u, + 23734u, 23738u, 23758u, 23768u, 23782u, 23794u, 23828u, 23836u, + 23846u, 23852u, 23858u, 23864u, 23878u, 23882u, 23896u, 23908u, + 23914u, 23924u, 23942u, 23956u, 23966u, 23978u, 23984u, 23986u, + 23992u, 23998u, 24026u, 24028u, 24032u, 24056u, 24062u, 24064u, + 24068u, 24076u, 24092u, 24098u, 24118u, 24122u, 24124u, 24134u, + 24136u, 24146u, 24154u, 24218u, 24224u, 24232u, 24244u, 24248u, + 24262u, 24274u, 24284u, 24286u, 24298u, 24304u, 24314u, 24332u, + 24356u, 24362u, 24364u, 24374u, 24382u, 24388u, 24404u, 24424u, + 24428u, 24442u, 24448u, 24454u, 24466u, 24472u, 24476u, 24482u, + 24484u, 24488u, 24496u, 24518u, 24524u, 24532u, 24536u, 24538u, + 24554u, 24572u, 24586u, 24592u, 24614u, 24628u, 24638u, 24652u, + 24656u, 24662u, 24664u, 24668u, 24682u, 24692u, 24704u, 24712u, + 24728u, 24736u, 24746u, 24754u, 24778u, 24818u, 24824u, 24836u, + 24838u, 24844u, 24862u, 24866u, 24868u, 24872u, 24902u, 24904u, + 24934u, 24938u, 24946u, 24964u, 24976u, 24988u, 24992u, 24994u, + 24998u, 25012u, 25048u, 25064u, 25082u, 25084u, 25096u, 25106u, + 25112u, 25124u, 25142u, 25144u, 25162u, 25168u, 25174u, 25196u, + 25214u, 25252u, 25258u, 25268u, 25286u, 25288u, 25298u, 25306u, + 25312u, 25328u, 25352u, 25366u, 25372u, 25376u, 25382u, 25396u, + 25412u, 25436u, 25442u, 25454u, 25462u, 25474u, 25484u, 25498u, + 25544u, 25546u, 25562u, 25564u, 25586u, 25592u, 25594u, 25604u, + 25606u, 25616u, 25618u, 25624u, 25628u, 25648u, 25658u, 25664u, + 25694u, 25702u, 25708u, 25714u, 25718u, 25748u, 25756u, 25762u, + 25768u, 25774u, 25796u, 25832u, 25834u, 25838u, 25846u, 25852u, + 25858u, 25862u, 25876u, 25888u, 25898u, 25918u, 25922u, 25924u, + 25928u, 25958u, 25964u, 25978u, 25994u, 26006u, 26036u, 26038u, + 26042u, 26048u, 26056u, 26086u, 26096u, 26104u, 26138u, 26156u, + 26168u, 26176u, 26198u, 26218u, 26222u, 26236u, 26246u, 26266u, + 26272u, 26276u, 26278u, 26288u, 26302u, 26306u, 26332u, 26338u, + 26374u, 26386u, 26404u, 26408u, 26416u, 26422u, 26426u, 26432u, + 26434u, 26462u, 26468u, 26474u, 26498u, 26506u, 26516u, 26542u, + 26548u, 26572u, 26576u, 26584u, 26608u, 26618u, 26638u, 26642u, + 26644u, 26654u, 26668u, 26684u, 26686u, 26692u, 26698u, 26702u, + 26708u, 26716u, 26734u, 26762u, 26776u, 26782u, 26798u, 26812u, + 26818u, 26822u, 26828u, 26834u, 26842u, 26846u, 26848u, 26852u, + 26864u, 26866u, 26878u, 26884u, 26896u, 26924u, 26926u, 26932u, + 26944u, 26954u, 26968u, 26972u, 27016u, 27022u, 27032u, 27034u, + 27046u, 27058u, 27088u, 27092u, 27104u, 27106u, 27112u, 27122u, + 27134u, 27136u, 27146u, 27148u, 27158u, 27164u, 27172u, 27182u, + 27188u, 27202u, 27218u, 27226u, 27232u, 27244u, 27254u, 27256u, + 27266u, 27274u, 27286u, 27296u, 27314u, 27322u, 27326u, 27328u, + 27332u, 27358u, 27364u, 27386u, 27392u, 27406u, 27416u, 27422u, + 27424u, 27452u, 27458u, 27466u, 27512u, 27518u, 27524u, 27542u, + 27548u, 27554u, 27562u, 27568u, 27578u, 27596u, 27598u, 27604u, + 27616u, 27634u, 27644u, 27652u, 27664u, 27694u, 27704u, 27706u, + 27716u, 27718u, 27722u, 27728u, 27746u, 27748u, 27752u, 27772u, + 27784u, 27788u, 27794u, 27802u, 27836u, 27842u, 27848u, 27872u, + 27884u, 27892u, 27928u, 27944u, 27946u, 27952u, 27956u, 27958u, + 27962u, 27968u, 27988u, 27994u, 28018u, 28022u, 28024u, 28028u, + 28046u, 28066u, 28072u, 28094u, 28102u, 28148u, 28166u, 28168u, + 28184u, 28204u, 28226u, 28228u, 28252u, 28274u, 28276u, 28292u, + 28316u, 28336u, 28352u, 28354u, 28358u, 28366u, 28376u, 28378u, + 28388u, 28402u, 28406u, 28414u, 28432u, 28436u, 28444u, 28448u, + 28462u, 28472u, 28474u, 28498u, 28514u, 28522u, 28528u, 28544u, + 28564u, 28574u, 28576u, 28582u, 28586u, 28616u, 28618u, 28634u, + 28666u, 28672u, 28684u, 28694u, 28718u, 28726u, 28738u, 28756u, + 28772u, 28774u, 28786u, 28792u, 28796u, 28808u, 28814u, 28816u, + 28844u, 28862u, 28864u, 28886u, 28892u, 28898u, 28904u, 28906u, + 28912u, 28928u, 28942u, 28948u, 28978u, 28994u, 28996u, 29006u, + 29008u, 29012u, 29024u, 29026u, 29038u, 29048u, 29062u, 29068u, + 29078u, 29086u, 29114u, 29116u, 29152u, 29158u, 29174u, 29188u, + 29192u, 29212u, 29236u, 29242u, 29246u, 29254u, 29258u, 29276u, + 29284u, 29288u, 29302u, 29306u, 29312u, 29314u, 29338u, 29354u, + 29368u, 29372u, 29398u, 29414u, 29416u, 29426u, 29458u, 29464u, + 29468u, 29474u, 29486u, 29492u, 29528u, 29536u, 29548u, 29552u, + 29554u, 29558u, 29566u, 29572u, 29576u, 29596u, 29608u, 29618u, + 29642u, 29654u, 29656u, 29668u, 29678u, 29684u, 29696u, 29698u, + 29704u, 29722u, 29726u, 29732u, 29738u, 29744u, 29752u, 29776u, + 29782u, 29792u, 29804u, 29834u, 29848u, 29858u, 29866u, 29878u, + 29884u, 29894u, 29906u, 29908u, 29926u, 29932u, 29936u, 29944u, + 29948u, 29972u, 29992u, 29996u, 30004u, 30014u, 30026u, 30034u, + 30046u, 30062u, 30068u, 30082u, 30086u, 30094u, 30098u, 30116u, + 30166u, 30172u, 30178u, 30182u, 30188u, 30196u, 30202u, 30212u, + 30238u, 30248u, 30254u, 30256u, 30266u, 30268u, 30278u, 30284u, + 30322u, 30334u, 30338u, 30346u, 30356u, 30376u, 30382u, 30388u, + 30394u, 30412u, 30422u, 30424u, 30436u, 30452u, 30454u, 30466u, + 30478u, 30482u, 30508u, 30518u, 30524u, 30544u, 30562u, 30602u, + 30614u, 30622u, 30632u, 30644u, 30646u, 30664u, 30676u, 30686u, + 30688u, 30698u, 30724u, 30728u, 30734u, 30746u, 30754u, 30758u, + 30788u, 30794u, 30796u, 30802u, 30818u, 30842u, 30866u, 30884u, + 30896u, 30908u, 30916u, 30922u, 30926u, 30934u, 30944u, 30952u, + 30958u, 30962u, 30982u, 30992u, 31018u, 31022u, 31046u, 31052u, + 31054u, 31066u, 31108u, 31126u, 31132u, 31136u, 31162u, 31168u, + 31196u, 31202u, 31204u, 31214u, 31222u, 31228u, 31234u, 31244u, + 31252u, 31262u, 31264u, 31286u, 31288u, 31292u, 31312u, 31316u, + 31322u, 31358u, 31372u, 31376u, 31396u, 31418u, 31424u, 31438u, + 31444u, 31454u, 31462u, 31466u, 31468u, 31472u, 31486u, 31504u, + 31538u, 31546u, 31568u, 31582u, 31592u, 31616u, 31622u, 31624u, + 31634u, 31636u, 31642u, 31652u, 31678u, 31696u, 31706u, 31724u, + 31748u, 31766u, 31768u, 31792u, 31832u, 31834u, 31838u, 31844u, + 31846u, 31852u, 31862u, 31888u, 31894u, 31906u, 31918u, 31924u, + 31928u, 31964u, 31966u, 31976u, 31988u, 32012u, 32014u, 32018u, + 32026u, 32036u, 32042u, 32044u, 32048u, 32072u, 32074u, 32078u, + 32114u, 32116u, 32138u, 32152u, 32176u, 32194u, 32236u, 32242u, + 32252u, 32254u, 32278u, 32294u, 32306u, 32308u, 32312u, 32314u, + 32324u, 32326u, 32336u, 32344u, 32348u, 32384u, 32392u, 32396u, + 32408u, 32426u, 32432u, 32438u, 32452u, 32474u, 32476u, 32482u, + 32506u, 32512u, 32522u, 32546u, 32566u, 32588u, 32594u, 32608u, + 32644u, 32672u, 32678u, 32686u, 32692u, 32716u, 32722u, 32734u, + 32762u, 32764u, 32782u, 32786u, 32788u, 32792u, 32812u, 32834u, + 32842u, 32852u, 32854u, 32872u, 32876u, 32884u, 32894u, 32908u, + 32918u, 32924u, 32932u, 32938u, 32944u, 32956u, 32972u, 32984u, + 32998u, 33008u, 33026u, 33028u, 33038u, 33062u, 33086u, 33092u, + 33104u, 33106u, 33128u, 33134u, 33154u, 33176u, 33178u, 33182u, + 33194u, 33196u, 33202u, 33238u, 33244u, 33266u, 33272u, 33274u, + 33302u, 33314u, 33332u, 33334u, 33338u, 33352u, 33358u, 33362u, + 33364u, 33374u, 33376u, 33392u, 33394u, 33404u, 33412u, 33418u, + 33428u, 33446u, 33458u, 33464u, 33478u, 33482u, 33488u, 33506u, + 33518u, 33544u, 33548u, 33554u, 33568u, 33574u, 33584u, 33596u, + 33598u, 33602u, 33604u, 33614u, 33638u, 33646u, 33656u, 33688u, + 33698u, 33706u, 33716u, 33722u, 33724u, 33742u, 33754u, 33782u, + 33812u, 33814u, 33832u, 33836u, 33842u, 33856u, 33862u, 33866u, + 33874u, 33896u, 33904u, 33934u, 33952u, 33962u, 33988u, 33992u, + 33994u, 34016u, 34024u, 34028u, 34036u, 34042u, 34046u, 34072u, + 34076u, 34088u, 34108u, 34126u, 34132u, 34144u, 34154u, 34172u, + 34174u, 34178u, 34184u, 34186u, 34198u, 34226u, 34232u, 34252u, + 34258u, 34274u, 34282u, 34288u, 34294u, 34298u, 34304u, 34324u, + 34336u, 34342u, 34346u, 34366u, 34372u, 34388u, 34394u, 34426u, + 34436u, 34454u, 34456u, 34468u, 34484u, 34508u, 34514u, 34522u, + 34534u, 34568u, 34574u, 34594u, 34616u, 34618u, 34634u, 34648u, + 34654u, 34658u, 34672u, 34678u, 34702u, 34732u, 34736u, 34744u, + 34756u, 34762u, 34778u, 34798u, 34808u, 34822u, 34826u, 34828u, + 34844u, 34856u, 34858u, 34868u, 34876u, 34882u, 34912u, 34924u, + 34934u, 34948u, 34958u, 34966u, 34976u, 34982u, 34984u, 34988u, + 35002u, 35012u, 35014u, 35024u, 35056u, 35074u, 35078u, 35086u, + 35114u, 35134u, 35138u, 35158u, 35164u, 35168u, 35198u, 35206u, + 35212u, 35234u, 35252u, 35264u, 35266u, 35276u, 35288u, 35294u, + 35312u, 35318u, 35372u, 35378u, 35392u, 35396u, 35402u, 35408u, + 35422u, 35446u, 35452u, 35464u, 35474u, 35486u, 35492u, 35516u, + 35528u, 35546u, 35554u, 35572u, 35576u, 35578u, 35582u, 35584u, + 35606u, 35614u, 35624u, 35626u, 35638u, 35648u, 35662u, 35668u, + 35672u, 35674u, 35686u, 35732u, 35738u, 35744u, 35746u, 35752u, + 35758u, 35788u, 35798u, 35806u, 35812u, 35824u, 35828u, 35842u, + 35848u, 35864u, 35876u, 35884u, 35894u, 35914u, 35932u, 35942u, + 35948u, 35954u, 35966u, 35968u, 35978u, 35992u, 35996u, 35998u, + 36002u, 36026u, 36038u, 36046u, 36064u, 36068u, 36076u, 36092u, + 36106u, 36118u, 36128u, 36146u, 36158u, 36166u, 36184u, 36188u, + 36202u, 36206u, 36212u, 36214u, 36236u, 36254u, 36262u, 36272u, + 36298u, 36302u, 36304u, 36328u, 36334u, 36338u, 36344u, 36356u, + 36382u, 36386u, 36394u, 36404u, 36422u, 36428u, 36442u, 36452u, + 36464u, 36466u, 36478u, 36484u, 36488u, 36496u, 36508u, 36524u, + 36526u, 36536u, 36542u, 36544u, 36566u, 36568u, 36572u, 36586u, + 36604u, 36614u, 36626u, 36646u, 36656u, 36662u, 36664u, 36668u, + 36682u, 36694u, 36698u, 36706u, 36716u, 36718u, 36724u, 36758u, + 36764u, 36766u, 36782u, 36794u, 36802u, 36824u, 36832u, 36862u, + 36872u, 36874u, 36898u, 36902u, 36916u, 36926u, 36946u, 36962u, + 36964u, 36968u, 36988u, 36998u, 37004u, 37012u, 37016u, 37024u, + 37028u, 37052u, 37058u, 37072u, 37076u, 37108u, 37112u, 37118u, + 37132u, 37138u, 37142u, 37144u, 37166u, 37226u, 37228u, 37234u, + 37258u, 37262u, 37276u, 37294u, 37306u, 37324u, 37336u, 37342u, + 37346u, 37376u, 37378u, 37394u, 37396u, 37418u, 37432u, 37448u, + 37466u, 37472u, 37508u, 37514u, 37532u, 37534u, 37544u, 37552u, + 37556u, 37558u, 37564u, 37588u, 37606u, 37636u, 37642u, 37648u, + 37682u, 37696u, 37702u, 37754u, 37756u, 37772u, 37784u, 37798u, + 37814u, 37822u, 37852u, 37856u, 37858u, 37864u, 37874u, 37886u, + 37888u, 37916u, 37922u, 37936u, 37948u, 37976u, 37994u, 38014u, + 38018u, 38026u, 38032u, 38038u, 38042u, 38048u, 38056u, 38078u, + 38084u, 38108u, 38116u, 38122u, 38134u, 38146u, 38152u, 38164u, + 38168u, 38188u, 38234u, 38252u, 38266u, 38276u, 38278u, 38302u, + 38306u, 38308u, 38332u, 38354u, 38368u, 38378u, 38384u, 38416u, + 38428u, 38432u, 38434u, 38444u, 38446u, 38456u, 38458u, 38462u, + 38468u, 38474u, 38486u, 38498u, 38512u, 38518u, 38524u, 38552u, + 38554u, 38572u, 38578u, 38584u, 38588u, 38612u, 38614u, 38626u, + 38638u, 38644u, 38648u, 38672u, 38696u, 38698u, 38704u, 38708u, + 38746u, 38752u, 38762u, 38774u, 38776u, 38788u, 38792u, 38812u, + 38834u, 38846u, 38848u, 38858u, 38864u, 38882u, 38924u, 38936u, + 38938u, 38944u, 38956u, 38978u, 38992u, 39002u, 39008u, 39014u, + 39016u, 39026u, 39044u, 39058u, 39062u, 39088u, 39104u, 39116u, + 39124u, 39142u, 39146u, 39148u, 39158u, 39166u, 39172u, 39176u, + 39182u, 39188u, 39194u + }; + + if(n <= b1) + return a1[n]; + if(n <= b2) + return a2[n - b1 - 1]; + if(n >= b3) + { + return boost::math::policies::raise_domain_error<boost::uint32_t>( + "boost::math::prime<%1%>", "Argument n out of range: got %1%", n, pol); + } + return static_cast<boost::uint32_t>(a3[n - b2 - 1]) + 0xFFFFu; + } + + inline boost::uint32_t prime(unsigned n) + { + return boost::math::prime(n, boost::math::policies::policy<>()); + } + + static const unsigned max_prime = 10000; + +}} // namespace boost and math diff --git a/Utilities/BGL/boost/math/special_functions/round.hpp b/Utilities/BGL/boost/math/special_functions/round.hpp new file mode 100644 index 0000000000000000000000000000000000000000..798ed9f57472fc2b40931d7489913a1c4165bb03 --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/round.hpp @@ -0,0 +1,92 @@ +// Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_ROUND_HPP +#define BOOST_MATH_ROUND_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/math/tools/config.hpp> +#include <boost/math/policies/error_handling.hpp> +#include <boost/math/special_functions/fpclassify.hpp> + +namespace boost{ namespace math{ + +template <class T, class Policy> +inline T round(const T& v, const Policy& pol) +{ + BOOST_MATH_STD_USING + if(!(boost::math::isfinite)(v)) + return policies::raise_rounding_error("boost::math::round<%1%>(%1%)", 0, v, pol); + return floor(v + 0.5f); +} +template <class T> +inline T round(const T& v) +{ + return round(v, policies::policy<>()); +} +// +// The following functions will not compile unless T has an +// implicit convertion to the integer types. For user-defined +// number types this will likely not be the case. In that case +// these functions should either be specialized for the UDT in +// question, or else overloads should be placed in the same +// namespace as the UDT: these will then be found via argument +// dependent lookup. See our concept archetypes for examples. +// +template <class T, class Policy> +inline int iround(const T& v, const Policy& pol) +{ + BOOST_MATH_STD_USING + T r = boost::math::round(v, pol); + if(fabs(r) > (std::numeric_limits<int>::max)()) + return static_cast<int>(policies::raise_rounding_error("boost::math::iround<%1%>(%1%)", 0, v, pol)); + return static_cast<int>(r); +} +template <class T> +inline int iround(const T& v) +{ + return iround(v, policies::policy<>()); +} + +template <class T, class Policy> +inline long lround(const T& v, const Policy& pol) +{ + BOOST_MATH_STD_USING + T r = boost::math::round(v, pol); + if(fabs(r) > (std::numeric_limits<long>::max)()) + return static_cast<long int>(policies::raise_rounding_error("boost::math::lround<%1%>(%1%)", 0, v, pol)); + return static_cast<long int>(r); +} +template <class T> +inline long lround(const T& v) +{ + return lround(v, policies::policy<>()); +} + +#ifdef BOOST_HAS_LONG_LONG + +template <class T, class Policy> +inline boost::long_long_type llround(const T& v, const Policy& pol) +{ + BOOST_MATH_STD_USING + T r = boost::math::round(v, pol); + if(fabs(r) > (std::numeric_limits<boost::long_long_type>::max)()) + return static_cast<boost::long_long_type>(policies::raise_rounding_error("boost::math::llround<%1%>(%1%)", 0, v, pol)); + return static_cast<boost::long_long_type>(r); +} +template <class T> +inline boost::long_long_type llround(const T& v) +{ + return llround(v, policies::policy<>()); +} + +#endif + +}} // namespaces + +#endif // BOOST_MATH_ROUND_HPP diff --git a/Utilities/BGL/boost/math/special_functions/sign.hpp b/Utilities/BGL/boost/math/special_functions/sign.hpp new file mode 100644 index 0000000000000000000000000000000000000000..1f224d23b4f752d190887ccad1824521d17da68a --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/sign.hpp @@ -0,0 +1,90 @@ +// (C) Copyright John Maddock 2006. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_TOOLS_SIGN_HPP +#define BOOST_MATH_TOOLS_SIGN_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/math/tools/config.hpp> +#include <boost/math/special_functions/math_fwd.hpp> +#include <boost/math/special_functions/detail/fp_traits.hpp> + +namespace boost{ namespace math{ + +namespace detail { + +#ifdef BOOST_MATH_USE_STD_FPCLASSIFY + template<class T> + inline int signbit_impl(T x, native_tag const&) + { + return (std::signbit)(x); + } +#endif + + template<class T> + inline int signbit_impl(T x, generic_tag<true> const&) + { + return x < 0; + } + + template<class T> + inline int signbit_impl(T x, generic_tag<false> const&) + { + return x < 0; + } + + template<class T> + inline int signbit_impl(T x, ieee_copy_all_bits_tag const&) + { + typedef BOOST_DEDUCED_TYPENAME fp_traits<T>::type traits; + + BOOST_DEDUCED_TYPENAME traits::bits a; + traits::get_bits(x,a); + return a & traits::sign ? 1 : 0; + } + + template<class T> + inline int signbit_impl(T x, ieee_copy_leading_bits_tag const&) + { + typedef BOOST_DEDUCED_TYPENAME fp_traits<T>::type traits; + + BOOST_DEDUCED_TYPENAME traits::bits a; + traits::get_bits(x,a); + + return a & traits::sign ? 1 : 0; + } +} // namespace detail + +template<class T> int (signbit)(T x) +{ //!< \brief return true if floating-point type t is NaN (Not A Number). + typedef typename detail::fp_traits<T>::type traits; + typedef typename traits::method method; + typedef typename boost::is_floating_point<T>::type fp_tag; + return detail::signbit_impl(x, method()); +} + +template <class T> +inline int sign BOOST_NO_MACRO_EXPAND(const T& z) +{ + return (z == 0) ? 0 : (boost::math::signbit)(z) ? -1 : 1; +} + +template <class T> +inline T copysign BOOST_NO_MACRO_EXPAND(const T& x, const T& y) +{ + BOOST_MATH_STD_USING + return fabs(x) * ((boost::math::signbit)(y) ? -1 : 1); +} + +} // namespace math +} // namespace boost + + +#endif // BOOST_MATH_TOOLS_SIGN_HPP + + diff --git a/Utilities/BGL/boost/math/special_functions/sin_pi.hpp b/Utilities/BGL/boost/math/special_functions/sin_pi.hpp new file mode 100644 index 0000000000000000000000000000000000000000..b8e9b0d055326a8d20bb377237124a691cb0f33d --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/sin_pi.hpp @@ -0,0 +1,70 @@ +// Copyright (c) 2007 John Maddock +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_SIN_PI_HPP +#define BOOST_MATH_SIN_PI_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/config/no_tr1/cmath.hpp> +#include <boost/math/tools/config.hpp> +#include <boost/math/special_functions/trunc.hpp> +#include <boost/math/tools/promotion.hpp> +#include <boost/math/constants/constants.hpp> + +namespace boost{ namespace math{ namespace detail{ + +template <class T, class Policy> +T sin_pi_imp(T x, const Policy& pol) +{ + BOOST_MATH_STD_USING // ADL of std names + if(x < 0) + return -sin_pi(-x); + // sin of pi*x: + bool invert; + if(x < 0.5) + return sin(constants::pi<T>() * x); + if(x < 1) + { + invert = true; + x = -x; + } + else + invert = false; + + T rem = floor(x); + if(itrunc(rem, pol) & 1) + invert = !invert; + rem = x - rem; + if(rem > 0.5f) + rem = 1 - rem; + if(rem == 0.5f) + return static_cast<T>(invert ? -1 : 1); + + rem = sin(constants::pi<T>() * rem); + return invert ? T(-rem) : rem; +} + +} // namespace detail + +template <class T, class Policy> +inline typename tools::promote_args<T>::type sin_pi(T x, const Policy& pol) +{ + typedef typename tools::promote_args<T>::type result_type; + return boost::math::detail::sin_pi_imp<result_type>(x, pol); +} + +template <class T> +inline typename tools::promote_args<T>::type sin_pi(T x) +{ + return boost::math::sin_pi(x, policies::policy<>()); +} + +} // namespace math +} // namespace boost +#endif + diff --git a/Utilities/BGL/boost/math/special_functions/sinc.hpp b/Utilities/BGL/boost/math/special_functions/sinc.hpp new file mode 100644 index 0000000000000000000000000000000000000000..a8a04fbb62939e61686e5a4b40f06c6be88ef17c --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/sinc.hpp @@ -0,0 +1,177 @@ +// boost sinc.hpp header file + +// (C) Copyright Hubert Holin 2001. +// 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) + +// See http://www.boost.org for updates, documentation, and revision history. + +#ifndef BOOST_SINC_HPP +#define BOOST_SINC_HPP + + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/math/tools/config.hpp> +#include <boost/math/tools/precision.hpp> +#include <boost/math/policies/policy.hpp> +#include <boost/math/special_functions/math_fwd.hpp> +#include <boost/config/no_tr1/cmath.hpp> +#include <boost/limits.hpp> +#include <string> +#include <stdexcept> + + +#include <boost/config.hpp> + + +// These are the the "Sinus Cardinal" functions. + +namespace boost +{ + namespace math + { + namespace detail + { +#if defined(__GNUC__) && (__GNUC__ < 3) + // gcc 2.x ignores function scope using declarations, + // put them in the scope of the enclosing namespace instead: + + using ::std::abs; + using ::std::sqrt; + using ::std::sin; + + using ::std::numeric_limits; +#endif /* defined(__GNUC__) && (__GNUC__ < 3) */ + + // This is the "Sinus Cardinal" of index Pi. + + template<typename T> + inline T sinc_pi_imp(const T x) + { +#if defined(BOOST_NO_STDC_NAMESPACE) && !defined(__SUNPRO_CC) + using ::abs; + using ::sin; + using ::sqrt; +#else /* BOOST_NO_STDC_NAMESPACE */ + using ::std::abs; + using ::std::sin; + using ::std::sqrt; +#endif /* BOOST_NO_STDC_NAMESPACE */ + + // Note: this code is *not* thread safe! + static T const taylor_0_bound = tools::epsilon<T>(); + static T const taylor_2_bound = sqrt(taylor_0_bound); + static T const taylor_n_bound = sqrt(taylor_2_bound); + + if (abs(x) >= taylor_n_bound) + { + return(sin(x)/x); + } + else + { + // approximation by taylor series in x at 0 up to order 0 + T result = static_cast<T>(1); + + if (abs(x) >= taylor_0_bound) + { + T x2 = x*x; + + // approximation by taylor series in x at 0 up to order 2 + result -= x2/static_cast<T>(6); + + if (abs(x) >= taylor_2_bound) + { + // approximation by taylor series in x at 0 up to order 4 + result += (x2*x2)/static_cast<T>(120); + } + } + + return(result); + } + } + + } // namespace detail + + template <class T> + inline typename tools::promote_args<T>::type sinc_pi(T x) + { + typedef typename tools::promote_args<T>::type result_type; + return detail::sinc_pi_imp(static_cast<result_type>(x)); + } + + template <class T, class Policy> + inline typename tools::promote_args<T>::type sinc_pi(T x, const Policy&) + { + typedef typename tools::promote_args<T>::type result_type; + return detail::sinc_pi_imp(static_cast<result_type>(x)); + } + +#ifdef BOOST_NO_TEMPLATE_TEMPLATES +#else /* BOOST_NO_TEMPLATE_TEMPLATES */ + template<typename T, template<typename> class U> + inline U<T> sinc_pi(const U<T> x) + { +#if defined(BOOST_FUNCTION_SCOPE_USING_DECLARATION_BREAKS_ADL) || defined(__GNUC__) + using namespace std; +#elif defined(BOOST_NO_STDC_NAMESPACE) && !defined(__SUNPRO_CC) + using ::abs; + using ::sin; + using ::sqrt; +#else /* BOOST_NO_STDC_NAMESPACE */ + using ::std::abs; + using ::std::sin; + using ::std::sqrt; +#endif /* BOOST_NO_STDC_NAMESPACE */ + + using ::std::numeric_limits; + + static T const taylor_0_bound = tools::epsilon<T>(); + static T const taylor_2_bound = sqrt(taylor_0_bound); + static T const taylor_n_bound = sqrt(taylor_2_bound); + + if (abs(x) >= taylor_n_bound) + { + return(sin(x)/x); + } + else + { + // approximation by taylor series in x at 0 up to order 0 +#ifdef __MWERKS__ + U<T> result = static_cast<U<T> >(1); +#else + U<T> result = U<T>(1); +#endif + + if (abs(x) >= taylor_0_bound) + { + U<T> x2 = x*x; + + // approximation by taylor series in x at 0 up to order 2 + result -= x2/static_cast<T>(6); + + if (abs(x) >= taylor_2_bound) + { + // approximation by taylor series in x at 0 up to order 4 + result += (x2*x2)/static_cast<T>(120); + } + } + + return(result); + } + } + + template<typename T, template<typename> class U, class Policy> + inline U<T> sinc_pi(const U<T> x, const Policy&) + { + return sinc_pi(x); + } +#endif /* BOOST_NO_TEMPLATE_TEMPLATES */ + } +} + +#endif /* BOOST_SINC_HPP */ + diff --git a/Utilities/BGL/boost/math/special_functions/sinhc.hpp b/Utilities/BGL/boost/math/special_functions/sinhc.hpp new file mode 100644 index 0000000000000000000000000000000000000000..197cd69999e1fd67bed9b12e9975755d46f16619 --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/sinhc.hpp @@ -0,0 +1,167 @@ +// boost sinhc.hpp header file + +// (C) Copyright Hubert Holin 2001. +// 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) + +// See http://www.boost.org for updates, documentation, and revision history. + +#ifndef BOOST_SINHC_HPP +#define BOOST_SINHC_HPP + + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/math/tools/config.hpp> +#include <boost/math/tools/precision.hpp> +#include <boost/math/special_functions/math_fwd.hpp> +#include <boost/config/no_tr1/cmath.hpp> +#include <boost/limits.hpp> +#include <string> +#include <stdexcept> + +#include <boost/config.hpp> + + +// These are the the "Hyperbolic Sinus Cardinal" functions. + +namespace boost +{ + namespace math + { + namespace detail + { +#if defined(__GNUC__) && (__GNUC__ < 3) + // gcc 2.x ignores function scope using declarations, + // put them in the scope of the enclosing namespace instead: + + using ::std::abs; + using ::std::sqrt; + using ::std::sinh; + + using ::std::numeric_limits; +#endif /* defined(__GNUC__) && (__GNUC__ < 3) */ + + // This is the "Hyperbolic Sinus Cardinal" of index Pi. + + template<typename T> + inline T sinhc_pi_imp(const T x) + { +#if defined(BOOST_NO_STDC_NAMESPACE) && !defined(__SUNPRO_CC) + using ::abs; + using ::sinh; + using ::sqrt; +#else /* BOOST_NO_STDC_NAMESPACE */ + using ::std::abs; + using ::std::sinh; + using ::std::sqrt; +#endif /* BOOST_NO_STDC_NAMESPACE */ + + static T const taylor_0_bound = tools::epsilon<T>(); + static T const taylor_2_bound = sqrt(taylor_0_bound); + static T const taylor_n_bound = sqrt(taylor_2_bound); + + if (abs(x) >= taylor_n_bound) + { + return(sinh(x)/x); + } + else + { + // approximation by taylor series in x at 0 up to order 0 + T result = static_cast<T>(1); + + if (abs(x) >= taylor_0_bound) + { + T x2 = x*x; + + // approximation by taylor series in x at 0 up to order 2 + result += x2/static_cast<T>(6); + + if (abs(x) >= taylor_2_bound) + { + // approximation by taylor series in x at 0 up to order 4 + result += (x2*x2)/static_cast<T>(120); + } + } + + return(result); + } + } + + } // namespace detail + + template <class T> + inline typename tools::promote_args<T>::type sinhc_pi(T x) + { + typedef typename tools::promote_args<T>::type result_type; + return detail::sinhc_pi_imp(static_cast<result_type>(x)); + } + + template <class T, class Policy> + inline typename tools::promote_args<T>::type sinhc_pi(T x, const Policy&) + { + return boost::math::sinhc_pi(x); + } + +#ifdef BOOST_NO_TEMPLATE_TEMPLATES +#else /* BOOST_NO_TEMPLATE_TEMPLATES */ + template<typename T, template<typename> class U> + inline U<T> sinhc_pi(const U<T> x) + { +#if defined(BOOST_FUNCTION_SCOPE_USING_DECLARATION_BREAKS_ADL) || defined(__GNUC__) + using namespace std; +#elif defined(BOOST_NO_STDC_NAMESPACE) && !defined(__SUNPRO_CC) + using ::abs; + using ::sinh; + using ::sqrt; +#else /* BOOST_NO_STDC_NAMESPACE */ + using ::std::abs; + using ::std::sinh; + using ::std::sqrt; +#endif /* BOOST_NO_STDC_NAMESPACE */ + + using ::std::numeric_limits; + + static T const taylor_0_bound = tools::epsilon<T>(); + static T const taylor_2_bound = sqrt(taylor_0_bound); + static T const taylor_n_bound = sqrt(taylor_2_bound); + + if (abs(x) >= taylor_n_bound) + { + return(sinh(x)/x); + } + else + { + // approximation by taylor series in x at 0 up to order 0 +#ifdef __MWERKS__ + U<T> result = static_cast<U<T> >(1); +#else + U<T> result = U<T>(1); +#endif + + if (abs(x) >= taylor_0_bound) + { + U<T> x2 = x*x; + + // approximation by taylor series in x at 0 up to order 2 + result += x2/static_cast<T>(6); + + if (abs(x) >= taylor_2_bound) + { + // approximation by taylor series in x at 0 up to order 4 + result += (x2*x2)/static_cast<T>(120); + } + } + + return(result); + } + } +#endif /* BOOST_NO_TEMPLATE_TEMPLATES */ + } +} + +#endif /* BOOST_SINHC_HPP */ + diff --git a/Utilities/BGL/boost/math/special_functions/spherical_harmonic.hpp b/Utilities/BGL/boost/math/special_functions/spherical_harmonic.hpp new file mode 100644 index 0000000000000000000000000000000000000000..394eb5359836a123d4b2530ead79f3fb3ecc1cd6 --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/spherical_harmonic.hpp @@ -0,0 +1,204 @@ + +// (C) Copyright John Maddock 2006. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_SPECIAL_SPHERICAL_HARMONIC_HPP +#define BOOST_MATH_SPECIAL_SPHERICAL_HARMONIC_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/math/special_functions/legendre.hpp> +#include <boost/math/tools/workaround.hpp> +#include <complex> + +namespace boost{ +namespace math{ + +namespace detail{ + +// +// Calculates the prefix term that's common to the real +// and imaginary parts. Does *not* fix up the sign of the result +// though. +// +template <class T, class Policy> +inline T spherical_harmonic_prefix(unsigned n, unsigned m, T theta, const Policy& pol) +{ + BOOST_MATH_STD_USING + + if(m > n) + return 0; + + T sin_theta = sin(theta); + T x = cos(theta); + + T leg = detail::legendre_p_imp(n, m, x, pow(fabs(sin_theta), T(m)), pol); + + T prefix = boost::math::tgamma_delta_ratio(static_cast<T>(n - m + 1), static_cast<T>(2 * m), pol); + prefix *= (2 * n + 1) / (4 * constants::pi<T>()); + prefix = sqrt(prefix); + return prefix * leg; +} +// +// Real Part: +// +template <class T, class Policy> +T spherical_harmonic_r(unsigned n, int m, T theta, T phi, const Policy& pol) +{ + BOOST_MATH_STD_USING // ADL of std functions + + bool sign = false; + if(m < 0) + { + // Reflect and adjust sign if m < 0: + sign = m&1; + m = abs(m); + } + if(m&1) + { + // Check phase if theta is outside [0, PI]: + T mod = boost::math::tools::fmod_workaround(theta, T(2 * constants::pi<T>())); + if(mod < 0) + mod += 2 * constants::pi<T>(); + if(mod > constants::pi<T>()) + sign = !sign; + } + // Get the value and adjust sign as required: + T prefix = spherical_harmonic_prefix(n, m, theta, pol); + prefix *= cos(m * phi); + return sign ? T(-prefix) : prefix; +} + +template <class T, class Policy> +T spherical_harmonic_i(unsigned n, int m, T theta, T phi, const Policy& pol) +{ + BOOST_MATH_STD_USING // ADL of std functions + + bool sign = false; + if(m < 0) + { + // Reflect and adjust sign if m < 0: + sign = !(m&1); + m = abs(m); + } + if(m&1) + { + // Check phase if theta is outside [0, PI]: + T mod = boost::math::tools::fmod_workaround(theta, T(2 * constants::pi<T>())); + if(mod < 0) + mod += 2 * constants::pi<T>(); + if(mod > constants::pi<T>()) + sign = !sign; + } + // Get the value and adjust sign as required: + T prefix = spherical_harmonic_prefix(n, m, theta, pol); + prefix *= sin(m * phi); + return sign ? T(-prefix) : prefix; +} + +template <class T, class U, class Policy> +std::complex<T> spherical_harmonic(unsigned n, int m, U theta, U phi, const Policy& pol) +{ + BOOST_MATH_STD_USING + // + // Sort out the signs: + // + bool r_sign = false; + bool i_sign = false; + if(m < 0) + { + // Reflect and adjust sign if m < 0: + r_sign = m&1; + i_sign = !(m&1); + m = abs(m); + } + if(m&1) + { + // Check phase if theta is outside [0, PI]: + U mod = boost::math::tools::fmod_workaround(theta, 2 * constants::pi<U>()); + if(mod < 0) + mod += 2 * constants::pi<U>(); + if(mod > constants::pi<U>()) + { + r_sign = !r_sign; + i_sign = !i_sign; + } + } + // + // Calculate the value: + // + U prefix = spherical_harmonic_prefix(n, m, theta, pol); + U r = prefix * cos(m * phi); + U i = prefix * sin(m * phi); + // + // Add in the signs: + // + if(r_sign) + r = -r; + if(i_sign) + i = -i; + static const char* function = "boost::math::spherical_harmonic<%1%>(int, int, %1%, %1%)"; + return std::complex<T>(policies::checked_narrowing_cast<T, Policy>(r, function), policies::checked_narrowing_cast<T, Policy>(i, function)); +} + +} // namespace detail + +template <class T1, class T2, class Policy> +inline std::complex<typename tools::promote_args<T1, T2>::type> + spherical_harmonic(unsigned n, int m, T1 theta, T2 phi, const Policy& pol) +{ + typedef typename tools::promote_args<T1, T2>::type result_type; + typedef typename policies::evaluation<result_type, Policy>::type value_type; + return detail::spherical_harmonic<result_type, value_type>(n, m, static_cast<value_type>(theta), static_cast<value_type>(phi), pol); +} + +template <class T1, class T2> +inline std::complex<typename tools::promote_args<T1, T2>::type> + spherical_harmonic(unsigned n, int m, T1 theta, T2 phi) +{ + return boost::math::spherical_harmonic(n, m, theta, phi, policies::policy<>()); +} + +template <class T1, class T2, class Policy> +inline typename tools::promote_args<T1, T2>::type + spherical_harmonic_r(unsigned n, int m, T1 theta, T2 phi, const Policy& pol) +{ + typedef typename tools::promote_args<T1, T2>::type result_type; + typedef typename policies::evaluation<result_type, Policy>::type value_type; + return policies::checked_narrowing_cast<result_type, Policy>(detail::spherical_harmonic_r(n, m, static_cast<value_type>(theta), static_cast<value_type>(phi), pol), "bost::math::spherical_harmonic_r<%1%>(unsigned, int, %1%, %1%)"); +} + +template <class T1, class T2> +inline typename tools::promote_args<T1, T2>::type + spherical_harmonic_r(unsigned n, int m, T1 theta, T2 phi) +{ + return boost::math::spherical_harmonic_r(n, m, theta, phi, policies::policy<>()); +} + +template <class T1, class T2, class Policy> +inline typename tools::promote_args<T1, T2>::type + spherical_harmonic_i(unsigned n, int m, T1 theta, T2 phi, const Policy& pol) +{ + typedef typename tools::promote_args<T1, T2>::type result_type; + typedef typename policies::evaluation<result_type, Policy>::type value_type; + return policies::checked_narrowing_cast<result_type, Policy>(detail::spherical_harmonic_i(n, m, static_cast<value_type>(theta), static_cast<value_type>(phi), pol), "boost::math::spherical_harmonic_i<%1%>(unsigned, int, %1%, %1%)"); +} + +template <class T1, class T2> +inline typename tools::promote_args<T1, T2>::type + spherical_harmonic_i(unsigned n, int m, T1 theta, T2 phi) +{ + return boost::math::spherical_harmonic_i(n, m, theta, phi, policies::policy<>()); +} + +} // namespace math +} // namespace boost + +#endif // BOOST_MATH_SPECIAL_SPHERICAL_HARMONIC_HPP + + + diff --git a/Utilities/BGL/boost/math/special_functions/sqrt1pm1.hpp b/Utilities/BGL/boost/math/special_functions/sqrt1pm1.hpp new file mode 100644 index 0000000000000000000000000000000000000000..f0046958d86d4c78357d2556a7488f9f5399d4f9 --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/sqrt1pm1.hpp @@ -0,0 +1,48 @@ +// (C) Copyright John Maddock 2006. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_SQRT1PM1 +#define BOOST_MATH_SQRT1PM1 + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/math/special_functions/log1p.hpp> +#include <boost/math/special_functions/expm1.hpp> +#include <boost/math/special_functions/math_fwd.hpp> + +// +// This algorithm computes sqrt(1+x)-1 for small x: +// + +namespace boost{ namespace math{ + +template <class T, class Policy> +inline typename tools::promote_args<T>::type sqrt1pm1(const T& val, const Policy& pol) +{ + typedef typename tools::promote_args<T>::type result_type; + BOOST_MATH_STD_USING + + if(fabs(result_type(val)) > 0.75) + return sqrt(1 + result_type(val)) - 1; + return boost::math::expm1(boost::math::log1p(val, pol) / 2, pol); +} + +template <class T> +inline typename tools::promote_args<T>::type sqrt1pm1(const T& val) +{ + return sqrt1pm1(val, policies::policy<>()); +} + +} // namespace math +} // namespace boost + +#endif // BOOST_MATH_SQRT1PM1 + + + + + diff --git a/Utilities/BGL/boost/math/special_functions/trunc.hpp b/Utilities/BGL/boost/math/special_functions/trunc.hpp new file mode 100644 index 0000000000000000000000000000000000000000..c5c6da5124940930063e89d0385e855d604f30f3 --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/trunc.hpp @@ -0,0 +1,92 @@ +// Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_TRUNC_HPP +#define BOOST_MATH_TRUNC_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/math/tools/config.hpp> +#include <boost/math/policies/error_handling.hpp> +#include <boost/math/special_functions/fpclassify.hpp> + +namespace boost{ namespace math{ + +template <class T, class Policy> +inline T trunc(const T& v, const Policy& pol) +{ + BOOST_MATH_STD_USING + if(!(boost::math::isfinite)(v)) + return policies::raise_rounding_error("boost::math::trunc<%1%>(%1%)", 0, v, pol); + return (v >= 0) ? static_cast<T>(floor(v)) : static_cast<T>(ceil(v)); +} +template <class T> +inline T trunc(const T& v) +{ + return trunc(v, policies::policy<>()); +} +// +// The following functions will not compile unless T has an +// implicit convertion to the integer types. For user-defined +// number types this will likely not be the case. In that case +// these functions should either be specialized for the UDT in +// question, or else overloads should be placed in the same +// namespace as the UDT: these will then be found via argument +// dependent lookup. See our concept archetypes for examples. +// +template <class T, class Policy> +inline int itrunc(const T& v, const Policy& pol) +{ + BOOST_MATH_STD_USING + T r = boost::math::trunc(v, pol); + if(fabs(r) > (std::numeric_limits<int>::max)()) + return static_cast<int>(policies::raise_rounding_error("boost::math::itrunc<%1%>(%1%)", 0, v, pol)); + return static_cast<int>(r); +} +template <class T> +inline int itrunc(const T& v) +{ + return itrunc(v, policies::policy<>()); +} + +template <class T, class Policy> +inline long ltrunc(const T& v, const Policy& pol) +{ + BOOST_MATH_STD_USING + T r = boost::math::trunc(v, pol); + if(fabs(r) > (std::numeric_limits<long>::max)()) + return static_cast<long>(policies::raise_rounding_error("boost::math::ltrunc<%1%>(%1%)", 0, v, pol)); + return static_cast<long>(r); +} +template <class T> +inline long ltrunc(const T& v) +{ + return ltrunc(v, policies::policy<>()); +} + +#ifdef BOOST_HAS_LONG_LONG + +template <class T, class Policy> +inline boost::long_long_type lltrunc(const T& v, const Policy& pol) +{ + BOOST_MATH_STD_USING + T r = boost::math::trunc(v, pol); + if(fabs(r) > (std::numeric_limits<boost::long_long_type>::max)()) + return static_cast<boost::long_long_type>(policies::raise_rounding_error("boost::math::lltrunc<%1%>(%1%)", 0, v, pol)); + return static_cast<boost::long_long_type>(r); +} +template <class T> +inline boost::long_long_type lltrunc(const T& v) +{ + return lltrunc(v, policies::policy<>()); +} + +#endif + +}} // namespaces + +#endif // BOOST_MATH_TRUNC_HPP diff --git a/Utilities/BGL/boost/math/special_functions/zeta.hpp b/Utilities/BGL/boost/math/special_functions/zeta.hpp new file mode 100644 index 0000000000000000000000000000000000000000..40e7ff2d4b364f87e5e62b8b9ce2adfedbd17049 --- /dev/null +++ b/Utilities/BGL/boost/math/special_functions/zeta.hpp @@ -0,0 +1,903 @@ +// Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_ZETA_HPP +#define BOOST_MATH_ZETA_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/math/tools/precision.hpp> +#include <boost/math/tools/series.hpp> +#include <boost/math/policies/error_handling.hpp> +#include <boost/math/special_functions/gamma.hpp> +#include <boost/math/special_functions/sin_pi.hpp> + +namespace boost{ namespace math{ namespace detail{ + +template <class T, class Policy> +struct zeta_series_cache_size +{ + // + // Work how large to make our cache size when evaluating the series + // evaluation: normally this is just large enough for the series + // to have converged, but for arbitrary precision types we need a + // really large cache to achieve reasonable precision in a reasonable + // time. This is important when constructing rational approximations + // to zeta for example. + // + typedef typename boost::math::policies::precision<T,Policy>::type precision_type; + typedef typename mpl::if_< + mpl::less_equal<precision_type, mpl::int_<0> >, + mpl::int_<5000>, + typename mpl::if_< + mpl::less_equal<precision_type, mpl::int_<64> >, + mpl::int_<70>, + typename mpl::if_< + mpl::less_equal<precision_type, mpl::int_<113> >, + mpl::int_<100>, + mpl::int_<5000> + >::type + >::type + >::type type; +}; + +template <class T, class Policy> +T zeta_series_imp(T s, T sc, const Policy&) +{ + // + // Series evaluation from: + // Havil, J. Gamma: Exploring Euler's Constant. + // Princeton, NJ: Princeton University Press, 2003. + // + // See also http://mathworld.wolfram.com/RiemannZetaFunction.html + // + BOOST_MATH_STD_USING + T sum = 0; + T mult = 0.5; + T change; + typedef typename zeta_series_cache_size<T,Policy>::type cache_size; + T powers[cache_size::value] = { 0, }; + unsigned n = 0; + do{ + T binom = -static_cast<T>(n); + T nested_sum = 1; + if(n < sizeof(powers) / sizeof(powers[0])) + powers[n] = pow(static_cast<T>(n + 1), -s); + for(unsigned k = 1; k <= n; ++k) + { + T p; + if(k < sizeof(powers) / sizeof(powers[0])) + { + p = powers[k]; + //p = pow(k + 1, -s); + } + else + p = pow(static_cast<T>(k + 1), -s); + nested_sum += binom * p; + binom *= (k - static_cast<T>(n)) / (k + 1); + } + change = mult * nested_sum; + sum += change; + mult /= 2; + ++n; + }while(fabs(change / sum) > tools::epsilon<T>()); + + return sum * 1 / -boost::math::powm1(T(2), sc); +} +// +// Classical p-series: +// +template <class T> +struct zeta_series2 +{ + typedef T result_type; + zeta_series2(T _s) : s(-_s), k(1){} + T operator()() + { + BOOST_MATH_STD_USING + return pow(static_cast<T>(k++), s); + } +private: + T s; + unsigned k; +}; + +template <class T, class Policy> +inline T zeta_series2_imp(T s, const Policy& pol) +{ + boost::uintmax_t max_iter = policies::get_max_series_iterations<Policy>();; + zeta_series2<T> f(s); + T result = tools::sum_series( + f, + policies::get_epsilon<T, Policy>(), + max_iter); + policies::check_series_iterations("boost::math::zeta_series2<%1%>(%1%)", max_iter, pol); + return result; +} + +template <class T, class Policy> +T zeta_imp_prec(T s, T sc, const Policy& pol, const mpl::int_<0>&) +{ + BOOST_MATH_STD_USING + T result; + // + // Only use power series if it will converge in 100 + // iterations or less: the more iterations it consumes + // the slower convergence becomes so we have to be very + // careful in it's usage. + // + if (s > -log(tools::epsilon<T>()) / 4.5) + result = detail::zeta_series2_imp(s, pol); + else + result = detail::zeta_series_imp(s, sc, pol); + return result; +} + +template <class T, class Policy> +inline T zeta_imp_prec(T s, T sc, const Policy&, const mpl::int_<53>&) +{ + BOOST_MATH_STD_USING + T result; + if(s < 1) + { + // Rational Approximation + // Maximum Deviation Found: 2.020e-18 + // Expected Error Term: -2.020e-18 + // Max error found at double precision: 3.994987e-17 + static const T P[6] = { + 0.24339294433593750202L, + -0.49092470516353571651L, + 0.0557616214776046784287L, + -0.00320912498879085894856L, + 0.000451534528645796438704L, + -0.933241270357061460782e-5L, + }; + static const T Q[6] = { + 1L, + -0.279960334310344432495L, + 0.0419676223309986037706L, + -0.00413421406552171059003L, + 0.00024978985622317935355L, + -0.101855788418564031874e-4L, + }; + result = tools::evaluate_polynomial(P, sc) / tools::evaluate_polynomial(Q, sc); + result -= 1.2433929443359375F; + result += (sc); + result /= (sc); + } + else if(s <= 2) + { + // Maximum Deviation Found: 9.007e-20 + // Expected Error Term: 9.007e-20 + static const T P[6] = { + 0.577215664901532860516, + 0.243210646940107164097, + 0.0417364673988216497593, + 0.00390252087072843288378, + 0.000249606367151877175456, + 0.110108440976732897969e-4, + }; + static const T Q[6] = { + 1, + 0.295201277126631761737, + 0.043460910607305495864, + 0.00434930582085826330659, + 0.000255784226140488490982, + 0.10991819782396112081e-4, + }; + result = tools::evaluate_polynomial(P, -sc) / tools::evaluate_polynomial(Q, -sc); + result += 1 / (-sc); + } + else if(s <= 4) + { + // Maximum Deviation Found: 5.946e-22 + // Expected Error Term: -5.946e-22 + static const float Y = 0.6986598968505859375; + static const T P[6] = { + -0.0537258300023595030676, + 0.0445163473292365591906, + 0.0128677673534519952905, + 0.00097541770457391752726, + 0.769875101573654070925e-4, + 0.328032510000383084155e-5, + }; + static const T Q[7] = { + 1, + 0.33383194553034051422, + 0.0487798431291407621462, + 0.00479039708573558490716, + 0.000270776703956336357707, + 0.106951867532057341359e-4, + 0.236276623974978646399e-7, + }; + result = tools::evaluate_polynomial(P, s - 2) / tools::evaluate_polynomial(Q, s - 2); + result += Y + 1 / (-sc); + } + else if(s <= 7) + { + // Maximum Deviation Found: 2.955e-17 + // Expected Error Term: 2.955e-17 + // Max error found at double precision: 2.009135e-16 + + static const T P[6] = { + -2.49710190602259410021, + -2.60013301809475665334, + -0.939260435377109939261, + -0.138448617995741530935, + -0.00701721240549802377623, + -0.229257310594893932383e-4, + }; + static const T Q[9] = { + 1, + 0.706039025937745133628, + 0.15739599649558626358, + 0.0106117950976845084417, + -0.36910273311764618902e-4, + 0.493409563927590008943e-5, + -0.234055487025287216506e-6, + 0.718833729365459760664e-8, + -0.1129200113474947419e-9, + }; + result = tools::evaluate_polynomial(P, s - 4) / tools::evaluate_polynomial(Q, s - 4); + result = 1 + exp(result); + } + else if(s < 15) + { + // Maximum Deviation Found: 7.117e-16 + // Expected Error Term: 7.117e-16 + // Max error found at double precision: 9.387771e-16 + static const T P[7] = { + -4.78558028495135619286, + -1.89197364881972536382, + -0.211407134874412820099, + -0.000189204758260076688518, + 0.00115140923889178742086, + 0.639949204213164496988e-4, + 0.139348932445324888343e-5, + }; + static const T Q[9] = { + 1, + 0.244345337378188557777, + 0.00873370754492288653669, + -0.00117592765334434471562, + -0.743743682899933180415e-4, + -0.21750464515767984778e-5, + 0.471001264003076486547e-8, + -0.833378440625385520576e-10, + 0.699841545204845636531e-12, + }; + result = tools::evaluate_polynomial(P, s - 7) / tools::evaluate_polynomial(Q, s - 7); + result = 1 + exp(result); + } + else if(s < 36) + { + // Max error in interpolated form: 1.668e-17 + // Max error found at long double precision: 1.669714e-17 + static const T P[8] = { + -10.3948950573308896825, + -2.85827219671106697179, + -0.347728266539245787271, + -0.0251156064655346341766, + -0.00119459173416968685689, + -0.382529323507967522614e-4, + -0.785523633796723466968e-6, + -0.821465709095465524192e-8, + }; + static const T Q[10] = { + 1, + 0.208196333572671890965, + 0.0195687657317205033485, + 0.00111079638102485921877, + 0.408507746266039256231e-4, + 0.955561123065693483991e-6, + 0.118507153474022900583e-7, + 0.222609483627352615142e-14, + }; + result = tools::evaluate_polynomial(P, s - 15) / tools::evaluate_polynomial(Q, s - 15); + result = 1 + exp(result); + } + else if(s < 56) + { + result = 1 + pow(T(2), -s); + } + else + { + result = 1; + } + return result; +} + +template <class T, class Policy> +T zeta_imp_prec(T s, T sc, const Policy&, const mpl::int_<64>&) +{ + BOOST_MATH_STD_USING + T result; + if(s < 1) + { + // Rational Approximation + // Maximum Deviation Found: 3.099e-20 + // Expected Error Term: 3.099e-20 + // Max error found at long double precision: 5.890498e-20 + static const T P[6] = { + 0.243392944335937499969L, + -0.496837806864865688082L, + 0.0680008039723709987107L, + -0.00511620413006619942112L, + 0.000455369899250053003335L, + -0.279496685273033761927e-4L, + }; + static const T Q[7] = { + 1L, + -0.30425480068225790522L, + 0.050052748580371598736L, + -0.00519355671064700627862L, + 0.000360623385771198350257L, + -0.159600883054550987633e-4L, + 0.339770279812410586032e-6L, + }; + result = tools::evaluate_polynomial(P, sc) / tools::evaluate_polynomial(Q, sc); + result -= 1.2433929443359375F; + result += (sc); + result /= (sc); + } + else if(s <= 2) + { + // Maximum Deviation Found: 1.059e-21 + // Expected Error Term: 1.059e-21 + // Max error found at long double precision: 1.626303e-19 + + static const T P[6] = { + 0.577215664901532860605L, + 0.222537368917162139445L, + 0.0356286324033215682729L, + 0.00304465292366350081446L, + 0.000178102511649069421904L, + 0.700867470265983665042e-5L, + }; + static const T Q[7] = { + 1L, + 0.259385759149531030085L, + 0.0373974962106091316854L, + 0.00332735159183332820617L, + 0.000188690420706998606469L, + 0.635994377921861930071e-5L, + 0.226583954978371199405e-7L, + }; + result = tools::evaluate_polynomial(P, -sc) / tools::evaluate_polynomial(Q, -sc); + result += 1 / (-sc); + } + else if(s <= 4) + { + // Maximum Deviation Found: 5.946e-22 + // Expected Error Term: -5.946e-22 + static const float Y = 0.6986598968505859375; + static const T P[7] = { + -0.053725830002359501027L, + 0.0470551187571475844778L, + 0.0101339410415759517471L, + 0.00100240326666092854528L, + 0.685027119098122814867e-4L, + 0.390972820219765942117e-5L, + 0.540319769113543934483e-7L, + }; + static const T Q[8] = { + 1, + 0.286577739726542730421L, + 0.0447355811517733225843L, + 0.00430125107610252363302L, + 0.000284956969089786662045L, + 0.116188101609848411329e-4L, + 0.278090318191657278204e-6L, + -0.19683620233222028478e-8L, + }; + result = tools::evaluate_polynomial(P, s - 2) / tools::evaluate_polynomial(Q, s - 2); + result += Y + 1 / (-sc); + } + else if(s <= 7) + { + // Max error found at long double precision: 8.132216e-19 + static const T P[8] = { + -2.49710190602259407065L, + -3.36664913245960625334L, + -1.77180020623777595452L, + -0.464717885249654313933L, + -0.0643694921293579472583L, + -0.00464265386202805715487L, + -0.000165556579779704340166L, + -0.252884970740994069582e-5L, + }; + static const T Q[9] = { + 1, + 1.01300131390690459085L, + 0.387898115758643503827L, + 0.0695071490045701135188L, + 0.00586908595251442839291L, + 0.000217752974064612188616L, + 0.397626583349419011731e-5L, + -0.927884739284359700764e-8L, + 0.119810501805618894381e-9L, + }; + result = tools::evaluate_polynomial(P, s - 4) / tools::evaluate_polynomial(Q, s - 4); + result = 1 + exp(result); + } + else if(s < 15) + { + // Max error in interpolated form: 1.133e-18 + // Max error found at long double precision: 2.183198e-18 + static const T P[9] = { + -4.78558028495135548083L, + -3.23873322238609358947L, + -0.892338582881021799922L, + -0.131326296217965913809L, + -0.0115651591773783712996L, + -0.000657728968362695775205L, + -0.252051328129449973047e-4L, + -0.626503445372641798925e-6L, + -0.815696314790853893484e-8L, + }; + static const T Q[9] = { + 1, + 0.525765665400123515036L, + 0.10852641753657122787L, + 0.0115669945375362045249L, + 0.000732896513858274091966L, + 0.30683952282420248448e-4L, + 0.819649214609633126119e-6L, + 0.117957556472335968146e-7L, + -0.193432300973017671137e-12L, + }; + result = tools::evaluate_polynomial(P, s - 7) / tools::evaluate_polynomial(Q, s - 7); + result = 1 + exp(result); + } + else if(s < 42) + { + // Max error in interpolated form: 1.668e-17 + // Max error found at long double precision: 1.669714e-17 + static const T P[9] = { + -10.3948950573308861781L, + -2.82646012777913950108L, + -0.342144362739570333665L, + -0.0249285145498722647472L, + -0.00122493108848097114118L, + -0.423055371192592850196e-4L, + -0.1025215577185967488e-5L, + -0.165096762663509467061e-7L, + -0.145392555873022044329e-9L, + }; + static const T Q[10] = { + 1, + 0.205135978585281988052L, + 0.0192359357875879453602L, + 0.00111496452029715514119L, + 0.434928449016693986857e-4L, + 0.116911068726610725891e-5L, + 0.206704342290235237475e-7L, + 0.209772836100827647474e-9L, + -0.939798249922234703384e-16L, + 0.264584017421245080294e-18L, + }; + result = tools::evaluate_polynomial(P, s - 15) / tools::evaluate_polynomial(Q, s - 15); + result = 1 + exp(result); + } + else if(s < 63) + { + result = 1 + pow(T(2), -s); + } + else + { + result = 1; + } + return result; +} + +template <class T, class Policy> +T zeta_imp_prec(T s, T sc, const Policy& pol, const mpl::int_<113>&) +{ + BOOST_MATH_STD_USING + T result; + if(s < 1) + { + // Rational Approximation + // Maximum Deviation Found: 9.493e-37 + // Expected Error Term: 9.492e-37 + // Max error found at long double precision: 7.281332e-31 + + static const T P[10] = { + -1L, + -0.0353008629988648122808504280990313668L, + 0.0107795651204927743049369868548706909L, + 0.000523961870530500751114866884685172975L, + -0.661805838304910731947595897966487515e-4L, + -0.658932670403818558510656304189164638e-5L, + -0.103437265642266106533814021041010453e-6L, + 0.116818787212666457105375746642927737e-7L, + 0.660690993901506912123512551294239036e-9L, + 0.113103113698388531428914333768142527e-10L, + }; + static const T Q[11] = { + 1L, + -0.387483472099602327112637481818565459L, + 0.0802265315091063135271497708694776875L, + -0.0110727276164171919280036408995078164L, + 0.00112552716946286252000434849173787243L, + -0.874554160748626916455655180296834352e-4L, + 0.530097847491828379568636739662278322e-5L, + -0.248461553590496154705565904497247452e-6L, + 0.881834921354014787309644951507523899e-8L, + -0.217062446168217797598596496310953025e-9L, + 0.315823200002384492377987848307151168e-11L, + }; + result = tools::evaluate_polynomial(P, sc) / tools::evaluate_polynomial(Q, sc); + result += (sc); + result /= (sc); + } + else if(s <= 2) + { + // Maximum Deviation Found: 1.616e-37 + // Expected Error Term: -1.615e-37 + + static const T P[10] = { + 0.577215664901532860606512090082402431L, + 0.255597968739771510415479842335906308L, + 0.0494056503552807274142218876983542205L, + 0.00551372778611700965268920983472292325L, + 0.00043667616723970574871427830895192731L, + 0.268562259154821957743669387915239528e-4L, + 0.109249633923016310141743084480436612e-5L, + 0.273895554345300227466534378753023924e-7L, + 0.583103205551702720149237384027795038e-9L, + -0.835774625259919268768735944711219256e-11L, + }; + static const T Q[11] = { + 1L, + 0.316661751179735502065583176348292881L, + 0.0540401806533507064453851182728635272L, + 0.00598621274107420237785899476374043797L, + 0.000474907812321704156213038740142079615L, + 0.272125421722314389581695715835862418e-4L, + 0.112649552156479800925522445229212933e-5L, + 0.301838975502992622733000078063330461e-7L, + 0.422960728687211282539769943184270106e-9L, + -0.377105263588822468076813329270698909e-11L, + -0.581926559304525152432462127383600681e-13L, + }; + result = tools::evaluate_polynomial(P, -sc) / tools::evaluate_polynomial(Q, -sc); + result += 1 / (-sc); + } + else if(s <= 4) + { + // Maximum Deviation Found: 1.891e-36 + // Expected Error Term: -1.891e-36 + // Max error found: 2.171527e-35 + + static const float Y = 0.6986598968505859375; + static const T P[11] = { + -0.0537258300023595010275848333539748089L, + 0.0429086930802630159457448174466342553L, + 0.0136148228754303412510213395034056857L, + 0.00190231601036042925183751238033763915L, + 0.000186880390916311438818302549192456581L, + 0.145347370745893262394287982691323657e-4L, + 0.805843276446813106414036600485884885e-6L, + 0.340818159286739137503297172091882574e-7L, + 0.115762357488748996526167305116837246e-8L, + 0.231904754577648077579913403645767214e-10L, + 0.340169592866058506675897646629036044e-12L, + }; + static const T Q[12] = { + 1L, + 0.363755247765087100018556983050520554L, + 0.0696581979014242539385695131258321598L, + 0.00882208914484611029571547753782014817L, + 0.000815405623261946661762236085660996718L, + 0.571366167062457197282642344940445452e-4L, + 0.309278269271853502353954062051797838e-5L, + 0.12822982083479010834070516053794262e-6L, + 0.397876357325018976733953479182110033e-8L, + 0.8484432107648683277598472295289279e-10L, + 0.105677416606909614301995218444080615e-11L, + 0.547223964564003701979951154093005354e-15L, + }; + result = tools::evaluate_polynomial(P, s - 2) / tools::evaluate_polynomial(Q, s - 2); + result += Y + 1 / (-sc); + } + else if(s <= 6) + { + // Max error in interpolated form: 1.510e-37 + // Max error found at long double precision: 2.769266e-34 + + static const T Y = 3.28348541259765625F; + + static const T P[13] = { + 0.786383506575062179339611614117697622L, + 0.495766593395271370974685959652073976L, + -0.409116737851754766422360889037532228L, + -0.57340744006238263817895456842655987L, + -0.280479899797421910694892949057963111L, + -0.0753148409447590257157585696212649869L, + -0.0122934003684672788499099362823748632L, + -0.00126148398446193639247961370266962927L, + -0.828465038179772939844657040917364896e-4L, + -0.361008916706050977143208468690645684e-5L, + -0.109879825497910544424797771195928112e-6L, + -0.214539416789686920918063075528797059e-8L, + -0.15090220092460596872172844424267351e-10L, + }; + static const T Q[14] = { + 1L, + 1.69490865837142338462982225731926485L, + 1.22697696630994080733321401255942464L, + 0.495409420862526540074366618006341533L, + 0.122368084916843823462872905024259633L, + 0.0191412993625268971656513890888208623L, + 0.00191401538628980617753082598351559642L, + 0.000123318142456272424148930280876444459L, + 0.531945488232526067889835342277595709e-5L, + 0.161843184071894368337068779669116236e-6L, + 0.305796079600152506743828859577462778e-8L, + 0.233582592298450202680170811044408894e-10L, + -0.275363878344548055574209713637734269e-13L, + 0.221564186807357535475441900517843892e-15L, + }; + result = tools::evaluate_polynomial(P, s - 4) / tools::evaluate_polynomial(Q, s - 4); + result -= Y; + result = 1 + exp(result); + } + else if(s < 10) + { + // Max error in interpolated form: 1.999e-34 + // Max error found at long double precision: 2.156186e-33 + + static const T P[13] = { + -4.0545627381873738086704293881227365L, + -4.70088348734699134347906176097717782L, + -2.36921550900925512951976617607678789L, + -0.684322583796369508367726293719322866L, + -0.126026534540165129870721937592996324L, + -0.015636903921778316147260572008619549L, + -0.00135442294754728549644376325814460807L, + -0.842793965853572134365031384646117061e-4L, + -0.385602133791111663372015460784978351e-5L, + -0.130458500394692067189883214401478539e-6L, + -0.315861074947230418778143153383660035e-8L, + -0.500334720512030826996373077844707164e-10L, + -0.420204769185233365849253969097184005e-12L, + }; + static const T Q[14] = { + 1L, + 0.97663511666410096104783358493318814L, + 0.40878780231201806504987368939673249L, + 0.0963890666609396058945084107597727252L, + 0.0142207619090854604824116070866614505L, + 0.00139010220902667918476773423995750877L, + 0.940669540194694997889636696089994734e-4L, + 0.458220848507517004399292480807026602e-5L, + 0.16345521617741789012782420625435495e-6L, + 0.414007452533083304371566316901024114e-8L, + 0.68701473543366328016953742622661377e-10L, + 0.603461891080716585087883971886075863e-12L, + 0.294670713571839023181857795866134957e-16L, + -0.147003914536437243143096875069813451e-18L, + }; + result = tools::evaluate_polynomial(P, s - 6) / tools::evaluate_polynomial(Q, s - 6); + result = 1 + exp(result); + } + else if(s < 17) + { + // Max error in interpolated form: 1.641e-32 + // Max error found at long double precision: 1.696121e-32 + static const T P[13] = { + -6.91319491921722925920883787894829678L, + -3.65491257639481960248690596951049048L, + -0.813557553449954526442644544105257881L, + -0.0994317301685870959473658713841138083L, + -0.00726896610245676520248617014211734906L, + -0.000317253318715075854811266230916762929L, + -0.66851422826636750855184211580127133e-5L, + 0.879464154730985406003332577806849971e-7L, + 0.113838903158254250631678791998294628e-7L, + 0.379184410304927316385211327537817583e-9L, + 0.612992858643904887150527613446403867e-11L, + 0.347873737198164757035457841688594788e-13L, + -0.289187187441625868404494665572279364e-15L, + }; + static const T Q[14] = { + 1L, + 0.427310044448071818775721584949868806L, + 0.074602514873055756201435421385243062L, + 0.00688651562174480772901425121653945942L, + 0.000360174847635115036351323894321880445L, + 0.973556847713307543918865405758248777e-5L, + -0.853455848314516117964634714780874197e-8L, + -0.118203513654855112421673192194622826e-7L, + -0.462521662511754117095006543363328159e-9L, + -0.834212591919475633107355719369463143e-11L, + -0.5354594751002702935740220218582929e-13L, + 0.406451690742991192964889603000756203e-15L, + 0.887948682401000153828241615760146728e-19L, + -0.34980761098820347103967203948619072e-21L, + }; + result = tools::evaluate_polynomial(P, s - 10) / tools::evaluate_polynomial(Q, s - 10); + result = 1 + exp(result); + } + else if(s < 30) + { + // Max error in interpolated form: 1.563e-31 + // Max error found at long double precision: 1.562725e-31 + + static const T P[13] = { + -11.7824798233959252791987402769438322L, + -4.36131215284987731928174218354118102L, + -0.732260980060982349410898496846972204L, + -0.0744985185694913074484248803015717388L, + -0.00517228281320594683022294996292250527L, + -0.000260897206152101522569969046299309939L, + -0.989553462123121764865178453128769948e-5L, + -0.286916799741891410827712096608826167e-6L, + -0.637262477796046963617949532211619729e-8L, + -0.106796831465628373325491288787760494e-9L, + -0.129343095511091870860498356205376823e-11L, + -0.102397936697965977221267881716672084e-13L, + -0.402663128248642002351627980255756363e-16L, + }; + static const T Q[14] = { + 1L, + 0.311288325355705609096155335186466508L, + 0.0438318468940415543546769437752132748L, + 0.00374396349183199548610264222242269536L, + 0.000218707451200585197339671707189281302L, + 0.927578767487930747532953583797351219e-5L, + 0.294145760625753561951137473484889639e-6L, + 0.704618586690874460082739479535985395e-8L, + 0.126333332872897336219649130062221257e-9L, + 0.16317315713773503718315435769352765e-11L, + 0.137846712823719515148344938160275695e-13L, + 0.580975420554224366450994232723910583e-16L, + -0.291354445847552426900293580511392459e-22L, + 0.73614324724785855925025452085443636e-25L, + }; + result = tools::evaluate_polynomial(P, s - 17) / tools::evaluate_polynomial(Q, s - 17); + result = 1 + exp(result); + } + else if(s < 74) + { + // Max error in interpolated form: 2.311e-27 + // Max error found at long double precision: 2.297544e-27 + static const T P[14] = { + -20.7944102007844314586649688802236072L, + -4.95759941987499442499908748130192187L, + -0.563290752832461751889194629200298688L, + -0.0406197001137935911912457120706122877L, + -0.0020846534789473022216888863613422293L, + -0.808095978462109173749395599401375667e-4L, + -0.244706022206249301640890603610060959e-5L, + -0.589477682919645930544382616501666572e-7L, + -0.113699573675553496343617442433027672e-8L, + -0.174767860183598149649901223128011828e-10L, + -0.210051620306761367764549971980026474e-12L, + -0.189187969537370950337212675466400599e-14L, + -0.116313253429564048145641663778121898e-16L, + -0.376708747782400769427057630528578187e-19L, + }; + static const T Q[16] = { + 1L, + 0.205076752981410805177554569784219717L, + 0.0202526722696670378999575738524540269L, + 0.001278305290005994980069466658219057L, + 0.576404779858501791742255670403304787e-4L, + 0.196477049872253010859712483984252067e-5L, + 0.521863830500876189501054079974475762e-7L, + 0.109524209196868135198775445228552059e-8L, + 0.181698713448644481083966260949267825e-10L, + 0.234793316975091282090312036524695562e-12L, + 0.227490441461460571047545264251399048e-14L, + 0.151500292036937400913870642638520668e-16L, + 0.543475775154780935815530649335936121e-19L, + 0.241647013434111434636554455083309352e-28L, + -0.557103423021951053707162364713587374e-31L, + 0.618708773442584843384712258199645166e-34L, + }; + result = tools::evaluate_polynomial(P, s - 30) / tools::evaluate_polynomial(Q, s - 30); + result = 1 + exp(result); + } + else if(s < 117) + { + result = 1 + pow(T(2), -s); + } + else + { + result = 1; + } + return result; +} + +template <class T, class Policy, class Tag> +T zeta_imp(T s, T sc, const Policy& pol, const Tag& tag) +{ + BOOST_MATH_STD_USING + if(s == 1) + return policies::raise_pole_error<T>( + "boost::math::zeta<%1%>", + "Evaluation of zeta function at pole %1%", + s, pol); + T result; + if(s == 0) + { + result = -0.5; + } + else if(s < 0) + { + std::swap(s, sc); + if(floor(sc/2) == sc/2) + result = 0; + else + { + result = boost::math::sin_pi(0.5f * sc, pol) + * 2 * pow(2 * constants::pi<T>(), -s) + * boost::math::tgamma(s, pol) + * zeta_imp(s, sc, pol, tag); + } + } + else + { + result = zeta_imp_prec(s, sc, pol, tag); + } + return result; +} + +} // detail + +template <class T, class Policy> +inline typename tools::promote_args<T>::type zeta(T s, const Policy&) +{ + typedef typename tools::promote_args<T>::type result_type; + typedef typename policies::evaluation<result_type, Policy>::type value_type; + typedef typename policies::precision<result_type, Policy>::type precision_type; + typedef typename policies::normalise< + Policy, + policies::promote_float<false>, + policies::promote_double<false>, + policies::discrete_quantile<>, + policies::assert_undefined<> >::type forwarding_policy; + typedef typename mpl::if_< + mpl::less_equal<precision_type, mpl::int_<0> >, + mpl::int_<0>, + typename mpl::if_< + mpl::less_equal<precision_type, mpl::int_<53> >, + mpl::int_<53>, // double + typename mpl::if_< + mpl::less_equal<precision_type, mpl::int_<64> >, + mpl::int_<64>, // 80-bit long double + typename mpl::if_< + mpl::less_equal<precision_type, mpl::int_<113> >, + mpl::int_<113>, // 128-bit long double + mpl::int_<0> // too many bits, use generic version. + >::type + >::type + >::type + >::type tag_type; + //typedef mpl::int_<0> tag_type; + + return policies::checked_narrowing_cast<result_type, forwarding_policy>(detail::zeta_imp( + static_cast<value_type>(s), + static_cast<value_type>(1 - static_cast<value_type>(s)), + forwarding_policy(), + tag_type()), "boost::math::zeta<%1%>(%1%)"); +} + +template <class T> +inline typename tools::promote_args<T>::type zeta(T s) +{ + return zeta(s, policies::policy<>()); +} + +}} // namespaces + +#endif // BOOST_MATH_ZETA_HPP + + + diff --git a/Utilities/BGL/boost/math/tools/config.hpp b/Utilities/BGL/boost/math/tools/config.hpp new file mode 100644 index 0000000000000000000000000000000000000000..3fbf288bca887261beb5f22742d20e3172695863 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/config.hpp @@ -0,0 +1,304 @@ +// Copyright (c) 2006-7 John Maddock +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_TOOLS_CONFIG_HPP +#define BOOST_MATH_TOOLS_CONFIG_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/cstdint.hpp> // for boost::uintmax_t +#include <boost/config.hpp> +#include <boost/detail/workaround.hpp> +#include <algorithm> // for min and max +#include <boost/config/no_tr1/cmath.hpp> +#include <climits> +#if (defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__)) +# include <math.h> +#endif + +#include <boost/math/tools/user.hpp> +#include <boost/math/special_functions/detail/round_fwd.hpp> + +#if defined(__CYGWIN__) || defined(__FreeBSD__) || defined(__NetBSD__) \ + || defined(__hppa) || defined(__NO_LONG_DOUBLE_MATH) +# define BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS +#endif +#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582)) +// +// Borland post 5.8.2 uses Dinkumware's std C lib which +// doesn't have true long double precision. Earlier +// versions are problematic too: +// +# define BOOST_MATH_NO_REAL_CONCEPT_TESTS +# define BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS +# define BOOST_MATH_CONTROL_FP _control87(MCW_EM,MCW_EM) +# include <float.h> +#endif +#if (defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__)) && ((LDBL_MANT_DIG == 106) || (__LDBL_MANT_DIG__ == 106)) +// +// Darwin's rather strange "double double" is rather hard to +// support, it should be possible given enough effort though... +// +# define BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS +#endif +#if defined(unix) && defined(__INTEL_COMPILER) && (__INTEL_COMPILER <= 1000) +// +// Intel compiler prior to version 10 has sporadic problems +// calling the long double overloads of the std lib math functions: +// calling ::powl is OK, but std::pow(long double, long double) +// may segfault depending upon the value of the arguments passed +// and the specific Linux distribution. +// +// We'll be conservative and disable long double support for this compiler. +// +// Comment out this #define and try building the tests to determine whether +// your Intel compiler version has this issue or not. +// +# define BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS +#endif +#if defined(unix) && defined(__INTEL_COMPILER) +// +// Intel compiler has sporadic issues compiling std::fpclassify depending on +// the exact OS version used. Use our own code for this as we know it works +// well on Intel processors: +// +#define BOOST_MATH_DISABLE_STD_FPCLASSIFY +#endif + +#if defined(BOOST_MSVC) && !defined(_WIN32_WCE) + // Better safe than sorry, our tests don't support hardware exceptions: +# define BOOST_MATH_CONTROL_FP _control87(MCW_EM,MCW_EM) +#endif + +#ifdef __IBMCPP__ +# define BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS +#endif + +#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901)) +# define BOOST_MATH_USE_C99 +#endif + +#if (defined(__hpux) && !defined(__hppa)) +# define BOOST_MATH_USE_C99 +#endif + +#if defined(__GNUC__) && defined(_GLIBCXX_USE_C99) +# define BOOST_MATH_USE_C99 +#endif + +#if defined(__CYGWIN__) || defined(__HP_aCC) || defined(BOOST_INTEL) \ + || defined(BOOST_NO_NATIVE_LONG_DOUBLE_FP_CLASSIFY) \ + || (defined(__GNUC__) && !defined(BOOST_MATH_USE_C99)) +# define BOOST_MATH_NO_NATIVE_LONG_DOUBLE_FP_CLASSIFY +#endif + +#if defined(BOOST_NO_EXPLICIT_FUNCTION_TEMPLATE_ARGUMENTS) || BOOST_WORKAROUND(__SUNPRO_CC, <= 0x590) + +# include "boost/type.hpp" +# include "boost/non_type.hpp" + +# define BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(t) boost::type<t>* = 0 +# define BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(t) boost::type<t>* +# define BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE(t, v) boost::non_type<t, v>* = 0 +# define BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v) boost::non_type<t, v>* + +# define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE(t) \ + , BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(t) +# define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE_SPEC(t) \ + , BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(t) +# define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_NON_TYPE(t, v) \ + , BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE(t, v) +# define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v) \ + , BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v) + +#else + +// no workaround needed: expand to nothing + +# define BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(t) +# define BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(t) +# define BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE(t, v) +# define BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v) + +# define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE(t) +# define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE_SPEC(t) +# define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_NON_TYPE(t, v) +# define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v) + + +#endif // defined BOOST_NO_EXPLICIT_FUNCTION_TEMPLATE_ARGUMENTS + +#if defined(__SUNPRO_CC) || defined(__hppa) || defined(__GNUC__) +// Sun's compiler emits a hard error if a constant underflows, +// as does aCC on PA-RISC, while gcc issues a large number of warnings: +# define BOOST_MATH_SMALL_CONSTANT(x) 0 +#else +# define BOOST_MATH_SMALL_CONSTANT(x) x +#endif + + +#if BOOST_WORKAROUND(BOOST_MSVC, < 1400) +// +// Define if constants too large for a float cause "bad" +// values to be stored in the data, rather than infinity +// or a suitably large value. +// +# define BOOST_MATH_BUGGY_LARGE_FLOAT_CONSTANTS +#endif +// +// Tune performance options for specific compilers: +// +#ifdef BOOST_MSVC +# define BOOST_MATH_POLY_METHOD 3 +#elif defined(BOOST_INTEL) +# define BOOST_MATH_POLY_METHOD 2 +# define BOOST_MATH_RATIONAL_METHOD 2 +#elif defined(__GNUC__) +# define BOOST_MATH_POLY_METHOD 3 +# define BOOST_MATH_RATIONAL_METHOD 3 +# define BOOST_MATH_INT_TABLE_TYPE(RT, IT) RT +# define BOOST_MATH_INT_VALUE_SUFFIX(RV, SUF) RV##.0L +#endif + +#if defined(BOOST_NO_LONG_LONG) && !defined(BOOST_MATH_INT_TABLE_TYPE) +# define BOOST_MATH_INT_TABLE_TYPE(RT, IT) RT +# define BOOST_MATH_INT_VALUE_SUFFIX(RV, SUF) RV##.0L +#endif + +// +// The maximum order of polynomial that will be evaluated +// via an unrolled specialisation: +// +#ifndef BOOST_MATH_MAX_POLY_ORDER +# define BOOST_MATH_MAX_POLY_ORDER 17 +#endif +// +// Set the method used to evaluate polynomials and rationals: +// +#ifndef BOOST_MATH_POLY_METHOD +# define BOOST_MATH_POLY_METHOD 1 +#endif +#ifndef BOOST_MATH_RATIONAL_METHOD +# define BOOST_MATH_RATIONAL_METHOD 0 +#endif +// +// decide whether to store constants as integers or reals: +// +#ifndef BOOST_MATH_INT_TABLE_TYPE +# define BOOST_MATH_INT_TABLE_TYPE(RT, IT) IT +#endif +#ifndef BOOST_MATH_INT_VALUE_SUFFIX +# define BOOST_MATH_INT_VALUE_SUFFIX(RV, SUF) RV##SUF +#endif + +// +// Helper macro for controlling the FP behaviour: +// +#ifndef BOOST_MATH_CONTROL_FP +# define BOOST_MATH_CONTROL_FP +#endif +// +// Helper macro for using statements: +// +#define BOOST_MATH_STD_USING \ + using std::abs;\ + using std::acos;\ + using std::cos;\ + using std::fmod;\ + using std::modf;\ + using std::tan;\ + using std::asin;\ + using std::cosh;\ + using std::frexp;\ + using std::pow;\ + using std::tanh;\ + using std::atan;\ + using std::exp;\ + using std::ldexp;\ + using std::sin;\ + using std::atan2;\ + using std::fabs;\ + using std::log;\ + using std::sinh;\ + using std::ceil;\ + using std::floor;\ + using std::log10;\ + using std::sqrt;\ + using boost::math::round;\ + using boost::math::iround;\ + using boost::math::lround;\ + using boost::math::trunc;\ + using boost::math::itrunc;\ + using boost::math::ltrunc;\ + using boost::math::modf; + + +namespace boost{ namespace math{ +namespace tools +{ + +template <class T> +inline T max BOOST_PREVENT_MACRO_SUBSTITUTION(T a, T b, T c) +{ + return (std::max)((std::max)(a, b), c); +} + +template <class T> +inline T max BOOST_PREVENT_MACRO_SUBSTITUTION(T a, T b, T c, T d) +{ + return (std::max)((std::max)(a, b), (std::max)(c, d)); +} +} // namespace tools +}} // namespace boost namespace math + +#if (defined(__linux__) && !defined(__UCLIBC__)) || defined(__QNX__) || defined(__IBMCPP__) + + #include <fenv.h> + + namespace boost{ namespace math{ + namespace detail + { + struct fpu_guard + { + fpu_guard() + { + fegetexceptflag(&m_flags, FE_ALL_EXCEPT); + feclearexcept(FE_ALL_EXCEPT); + } + ~fpu_guard() + { + fesetexceptflag(&m_flags, FE_ALL_EXCEPT); + } + private: + fexcept_t m_flags; + }; + + } // namespace detail + }} // namespaces + +# define BOOST_FPU_EXCEPTION_GUARD boost::math::detail::fpu_guard local_guard_object; +# define BOOST_MATH_INSTRUMENT_FPU do{ fexcept_t cpu_flags; fegetexceptflag(&cpu_flags, FE_ALL_EXCEPT); BOOST_MATH_INSTRUMENT_VARIABLE(cpu_flags); } while(0); +#else // All other platforms. +# define BOOST_FPU_EXCEPTION_GUARD +# define BOOST_MATH_INSTRUMENT_FPU +#endif + +#ifdef BOOST_MATH_INSTRUMENT +#define BOOST_MATH_INSTRUMENT_CODE(x) \ + std::cout << std::setprecision(35) << __FILE__ << ":" << __LINE__ << " " << x << std::endl; +#define BOOST_MATH_INSTRUMENT_VARIABLE(name) BOOST_MATH_INSTRUMENT_CODE(BOOST_STRINGIZE(name) << " = " << name) +#else +#define BOOST_MATH_INSTRUMENT_CODE(x) +#define BOOST_MATH_INSTRUMENT_VARIABLE(name) +#endif + +#endif // BOOST_MATH_TOOLS_CONFIG_HPP + + + + + diff --git a/Utilities/BGL/boost/math/tools/detail/polynomial_horner1_10.hpp b/Utilities/BGL/boost/math/tools/detail/polynomial_horner1_10.hpp new file mode 100644 index 0000000000000000000000000000000000000000..014259759a21c06223c8d9a6e8b9ab4f7096e4ac --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/polynomial_horner1_10.hpp @@ -0,0 +1,84 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_EVAL_10_HPP +#define BOOST_MATH_TOOLS_POLY_EVAL_10_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>(a[1] * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>((a[2] * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>(((a[3] * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<5>*) +{ + return static_cast<V>((((a[4] * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<6>*) +{ + return static_cast<V>(((((a[5] * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<7>*) +{ + return static_cast<V>((((((a[6] * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<8>*) +{ + return static_cast<V>(((((((a[7] * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<9>*) +{ + return static_cast<V>((((((((a[8] * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<10>*) +{ + return static_cast<V>(((((((((a[9] * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/polynomial_horner1_11.hpp b/Utilities/BGL/boost/math/tools/detail/polynomial_horner1_11.hpp new file mode 100644 index 0000000000000000000000000000000000000000..2471952caaa8bd434f498d6aefe344440913f888 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/polynomial_horner1_11.hpp @@ -0,0 +1,90 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_EVAL_11_HPP +#define BOOST_MATH_TOOLS_POLY_EVAL_11_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>(a[1] * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>((a[2] * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>(((a[3] * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<5>*) +{ + return static_cast<V>((((a[4] * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<6>*) +{ + return static_cast<V>(((((a[5] * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<7>*) +{ + return static_cast<V>((((((a[6] * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<8>*) +{ + return static_cast<V>(((((((a[7] * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<9>*) +{ + return static_cast<V>((((((((a[8] * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<10>*) +{ + return static_cast<V>(((((((((a[9] * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<11>*) +{ + return static_cast<V>((((((((((a[10] * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/polynomial_horner1_12.hpp b/Utilities/BGL/boost/math/tools/detail/polynomial_horner1_12.hpp new file mode 100644 index 0000000000000000000000000000000000000000..9704c1b15c4cb0a4a3857ebfea044c7dd018bd63 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/polynomial_horner1_12.hpp @@ -0,0 +1,96 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_EVAL_12_HPP +#define BOOST_MATH_TOOLS_POLY_EVAL_12_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>(a[1] * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>((a[2] * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>(((a[3] * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<5>*) +{ + return static_cast<V>((((a[4] * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<6>*) +{ + return static_cast<V>(((((a[5] * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<7>*) +{ + return static_cast<V>((((((a[6] * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<8>*) +{ + return static_cast<V>(((((((a[7] * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<9>*) +{ + return static_cast<V>((((((((a[8] * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<10>*) +{ + return static_cast<V>(((((((((a[9] * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<11>*) +{ + return static_cast<V>((((((((((a[10] * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<12>*) +{ + return static_cast<V>(((((((((((a[11] * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/polynomial_horner1_13.hpp b/Utilities/BGL/boost/math/tools/detail/polynomial_horner1_13.hpp new file mode 100644 index 0000000000000000000000000000000000000000..a2553a8277834b64a451d8bff682657e4ad9eaf6 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/polynomial_horner1_13.hpp @@ -0,0 +1,102 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_EVAL_13_HPP +#define BOOST_MATH_TOOLS_POLY_EVAL_13_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>(a[1] * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>((a[2] * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>(((a[3] * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<5>*) +{ + return static_cast<V>((((a[4] * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<6>*) +{ + return static_cast<V>(((((a[5] * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<7>*) +{ + return static_cast<V>((((((a[6] * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<8>*) +{ + return static_cast<V>(((((((a[7] * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<9>*) +{ + return static_cast<V>((((((((a[8] * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<10>*) +{ + return static_cast<V>(((((((((a[9] * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<11>*) +{ + return static_cast<V>((((((((((a[10] * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<12>*) +{ + return static_cast<V>(((((((((((a[11] * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<13>*) +{ + return static_cast<V>((((((((((((a[12] * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/polynomial_horner1_14.hpp b/Utilities/BGL/boost/math/tools/detail/polynomial_horner1_14.hpp new file mode 100644 index 0000000000000000000000000000000000000000..f9931f76224ece3dce03bc9e4d4347b60da22989 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/polynomial_horner1_14.hpp @@ -0,0 +1,108 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_EVAL_14_HPP +#define BOOST_MATH_TOOLS_POLY_EVAL_14_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>(a[1] * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>((a[2] * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>(((a[3] * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<5>*) +{ + return static_cast<V>((((a[4] * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<6>*) +{ + return static_cast<V>(((((a[5] * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<7>*) +{ + return static_cast<V>((((((a[6] * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<8>*) +{ + return static_cast<V>(((((((a[7] * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<9>*) +{ + return static_cast<V>((((((((a[8] * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<10>*) +{ + return static_cast<V>(((((((((a[9] * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<11>*) +{ + return static_cast<V>((((((((((a[10] * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<12>*) +{ + return static_cast<V>(((((((((((a[11] * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<13>*) +{ + return static_cast<V>((((((((((((a[12] * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<14>*) +{ + return static_cast<V>(((((((((((((a[13] * x + a[12]) * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/polynomial_horner1_15.hpp b/Utilities/BGL/boost/math/tools/detail/polynomial_horner1_15.hpp new file mode 100644 index 0000000000000000000000000000000000000000..9189da868ae95f82523fe3c2325a8409445ae18f --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/polynomial_horner1_15.hpp @@ -0,0 +1,114 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_EVAL_15_HPP +#define BOOST_MATH_TOOLS_POLY_EVAL_15_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>(a[1] * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>((a[2] * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>(((a[3] * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<5>*) +{ + return static_cast<V>((((a[4] * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<6>*) +{ + return static_cast<V>(((((a[5] * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<7>*) +{ + return static_cast<V>((((((a[6] * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<8>*) +{ + return static_cast<V>(((((((a[7] * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<9>*) +{ + return static_cast<V>((((((((a[8] * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<10>*) +{ + return static_cast<V>(((((((((a[9] * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<11>*) +{ + return static_cast<V>((((((((((a[10] * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<12>*) +{ + return static_cast<V>(((((((((((a[11] * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<13>*) +{ + return static_cast<V>((((((((((((a[12] * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<14>*) +{ + return static_cast<V>(((((((((((((a[13] * x + a[12]) * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<15>*) +{ + return static_cast<V>((((((((((((((a[14] * x + a[13]) * x + a[12]) * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/polynomial_horner1_16.hpp b/Utilities/BGL/boost/math/tools/detail/polynomial_horner1_16.hpp new file mode 100644 index 0000000000000000000000000000000000000000..cede018590eb1d1dabed654e48807ca573589205 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/polynomial_horner1_16.hpp @@ -0,0 +1,120 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_EVAL_16_HPP +#define BOOST_MATH_TOOLS_POLY_EVAL_16_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>(a[1] * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>((a[2] * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>(((a[3] * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<5>*) +{ + return static_cast<V>((((a[4] * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<6>*) +{ + return static_cast<V>(((((a[5] * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<7>*) +{ + return static_cast<V>((((((a[6] * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<8>*) +{ + return static_cast<V>(((((((a[7] * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<9>*) +{ + return static_cast<V>((((((((a[8] * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<10>*) +{ + return static_cast<V>(((((((((a[9] * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<11>*) +{ + return static_cast<V>((((((((((a[10] * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<12>*) +{ + return static_cast<V>(((((((((((a[11] * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<13>*) +{ + return static_cast<V>((((((((((((a[12] * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<14>*) +{ + return static_cast<V>(((((((((((((a[13] * x + a[12]) * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<15>*) +{ + return static_cast<V>((((((((((((((a[14] * x + a[13]) * x + a[12]) * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<16>*) +{ + return static_cast<V>(((((((((((((((a[15] * x + a[14]) * x + a[13]) * x + a[12]) * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/polynomial_horner1_17.hpp b/Utilities/BGL/boost/math/tools/detail/polynomial_horner1_17.hpp new file mode 100644 index 0000000000000000000000000000000000000000..a2d81133a09a26cc3027957e44b09ee9e469f635 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/polynomial_horner1_17.hpp @@ -0,0 +1,126 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_EVAL_17_HPP +#define BOOST_MATH_TOOLS_POLY_EVAL_17_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>(a[1] * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>((a[2] * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>(((a[3] * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<5>*) +{ + return static_cast<V>((((a[4] * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<6>*) +{ + return static_cast<V>(((((a[5] * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<7>*) +{ + return static_cast<V>((((((a[6] * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<8>*) +{ + return static_cast<V>(((((((a[7] * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<9>*) +{ + return static_cast<V>((((((((a[8] * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<10>*) +{ + return static_cast<V>(((((((((a[9] * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<11>*) +{ + return static_cast<V>((((((((((a[10] * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<12>*) +{ + return static_cast<V>(((((((((((a[11] * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<13>*) +{ + return static_cast<V>((((((((((((a[12] * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<14>*) +{ + return static_cast<V>(((((((((((((a[13] * x + a[12]) * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<15>*) +{ + return static_cast<V>((((((((((((((a[14] * x + a[13]) * x + a[12]) * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<16>*) +{ + return static_cast<V>(((((((((((((((a[15] * x + a[14]) * x + a[13]) * x + a[12]) * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<17>*) +{ + return static_cast<V>((((((((((((((((a[16] * x + a[15]) * x + a[14]) * x + a[13]) * x + a[12]) * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/polynomial_horner1_18.hpp b/Utilities/BGL/boost/math/tools/detail/polynomial_horner1_18.hpp new file mode 100644 index 0000000000000000000000000000000000000000..44bcd0f1b1f6e55acc86cc5779c54f3380a8f4fb --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/polynomial_horner1_18.hpp @@ -0,0 +1,132 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_EVAL_18_HPP +#define BOOST_MATH_TOOLS_POLY_EVAL_18_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>(a[1] * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>((a[2] * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>(((a[3] * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<5>*) +{ + return static_cast<V>((((a[4] * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<6>*) +{ + return static_cast<V>(((((a[5] * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<7>*) +{ + return static_cast<V>((((((a[6] * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<8>*) +{ + return static_cast<V>(((((((a[7] * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<9>*) +{ + return static_cast<V>((((((((a[8] * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<10>*) +{ + return static_cast<V>(((((((((a[9] * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<11>*) +{ + return static_cast<V>((((((((((a[10] * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<12>*) +{ + return static_cast<V>(((((((((((a[11] * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<13>*) +{ + return static_cast<V>((((((((((((a[12] * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<14>*) +{ + return static_cast<V>(((((((((((((a[13] * x + a[12]) * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<15>*) +{ + return static_cast<V>((((((((((((((a[14] * x + a[13]) * x + a[12]) * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<16>*) +{ + return static_cast<V>(((((((((((((((a[15] * x + a[14]) * x + a[13]) * x + a[12]) * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<17>*) +{ + return static_cast<V>((((((((((((((((a[16] * x + a[15]) * x + a[14]) * x + a[13]) * x + a[12]) * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<18>*) +{ + return static_cast<V>(((((((((((((((((a[17] * x + a[16]) * x + a[15]) * x + a[14]) * x + a[13]) * x + a[12]) * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/polynomial_horner1_19.hpp b/Utilities/BGL/boost/math/tools/detail/polynomial_horner1_19.hpp new file mode 100644 index 0000000000000000000000000000000000000000..b002b090eea99b3e9df545718f61e87b35d437f7 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/polynomial_horner1_19.hpp @@ -0,0 +1,138 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_EVAL_19_HPP +#define BOOST_MATH_TOOLS_POLY_EVAL_19_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>(a[1] * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>((a[2] * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>(((a[3] * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<5>*) +{ + return static_cast<V>((((a[4] * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<6>*) +{ + return static_cast<V>(((((a[5] * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<7>*) +{ + return static_cast<V>((((((a[6] * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<8>*) +{ + return static_cast<V>(((((((a[7] * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<9>*) +{ + return static_cast<V>((((((((a[8] * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<10>*) +{ + return static_cast<V>(((((((((a[9] * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<11>*) +{ + return static_cast<V>((((((((((a[10] * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<12>*) +{ + return static_cast<V>(((((((((((a[11] * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<13>*) +{ + return static_cast<V>((((((((((((a[12] * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<14>*) +{ + return static_cast<V>(((((((((((((a[13] * x + a[12]) * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<15>*) +{ + return static_cast<V>((((((((((((((a[14] * x + a[13]) * x + a[12]) * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<16>*) +{ + return static_cast<V>(((((((((((((((a[15] * x + a[14]) * x + a[13]) * x + a[12]) * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<17>*) +{ + return static_cast<V>((((((((((((((((a[16] * x + a[15]) * x + a[14]) * x + a[13]) * x + a[12]) * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<18>*) +{ + return static_cast<V>(((((((((((((((((a[17] * x + a[16]) * x + a[15]) * x + a[14]) * x + a[13]) * x + a[12]) * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<19>*) +{ + return static_cast<V>((((((((((((((((((a[18] * x + a[17]) * x + a[16]) * x + a[15]) * x + a[14]) * x + a[13]) * x + a[12]) * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/polynomial_horner1_2.hpp b/Utilities/BGL/boost/math/tools/detail/polynomial_horner1_2.hpp new file mode 100644 index 0000000000000000000000000000000000000000..2ef35e1d5e08c4eff4836d3a0388c0673c013c84 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/polynomial_horner1_2.hpp @@ -0,0 +1,36 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_EVAL_2_HPP +#define BOOST_MATH_TOOLS_POLY_EVAL_2_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>(a[1] * x + a[0]); +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/polynomial_horner1_20.hpp b/Utilities/BGL/boost/math/tools/detail/polynomial_horner1_20.hpp new file mode 100644 index 0000000000000000000000000000000000000000..5525500322d7d877bd33c468e44d5c635e0fa0a2 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/polynomial_horner1_20.hpp @@ -0,0 +1,144 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_EVAL_20_HPP +#define BOOST_MATH_TOOLS_POLY_EVAL_20_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>(a[1] * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>((a[2] * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>(((a[3] * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<5>*) +{ + return static_cast<V>((((a[4] * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<6>*) +{ + return static_cast<V>(((((a[5] * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<7>*) +{ + return static_cast<V>((((((a[6] * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<8>*) +{ + return static_cast<V>(((((((a[7] * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<9>*) +{ + return static_cast<V>((((((((a[8] * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<10>*) +{ + return static_cast<V>(((((((((a[9] * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<11>*) +{ + return static_cast<V>((((((((((a[10] * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<12>*) +{ + return static_cast<V>(((((((((((a[11] * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<13>*) +{ + return static_cast<V>((((((((((((a[12] * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<14>*) +{ + return static_cast<V>(((((((((((((a[13] * x + a[12]) * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<15>*) +{ + return static_cast<V>((((((((((((((a[14] * x + a[13]) * x + a[12]) * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<16>*) +{ + return static_cast<V>(((((((((((((((a[15] * x + a[14]) * x + a[13]) * x + a[12]) * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<17>*) +{ + return static_cast<V>((((((((((((((((a[16] * x + a[15]) * x + a[14]) * x + a[13]) * x + a[12]) * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<18>*) +{ + return static_cast<V>(((((((((((((((((a[17] * x + a[16]) * x + a[15]) * x + a[14]) * x + a[13]) * x + a[12]) * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<19>*) +{ + return static_cast<V>((((((((((((((((((a[18] * x + a[17]) * x + a[16]) * x + a[15]) * x + a[14]) * x + a[13]) * x + a[12]) * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<20>*) +{ + return static_cast<V>(((((((((((((((((((a[19] * x + a[18]) * x + a[17]) * x + a[16]) * x + a[15]) * x + a[14]) * x + a[13]) * x + a[12]) * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/polynomial_horner1_3.hpp b/Utilities/BGL/boost/math/tools/detail/polynomial_horner1_3.hpp new file mode 100644 index 0000000000000000000000000000000000000000..bf1036d0ad9ab75c8fea2ca326911203a21ab84d --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/polynomial_horner1_3.hpp @@ -0,0 +1,42 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_EVAL_3_HPP +#define BOOST_MATH_TOOLS_POLY_EVAL_3_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>(a[1] * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>((a[2] * x + a[1]) * x + a[0]); +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/polynomial_horner1_4.hpp b/Utilities/BGL/boost/math/tools/detail/polynomial_horner1_4.hpp new file mode 100644 index 0000000000000000000000000000000000000000..81340ebb722266006d347fd1c38ced09a4c3c559 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/polynomial_horner1_4.hpp @@ -0,0 +1,48 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_EVAL_4_HPP +#define BOOST_MATH_TOOLS_POLY_EVAL_4_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>(a[1] * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>((a[2] * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>(((a[3] * x + a[2]) * x + a[1]) * x + a[0]); +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/polynomial_horner1_5.hpp b/Utilities/BGL/boost/math/tools/detail/polynomial_horner1_5.hpp new file mode 100644 index 0000000000000000000000000000000000000000..50ba7bd76bb42a66502075c391989dc46d21ab97 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/polynomial_horner1_5.hpp @@ -0,0 +1,54 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_EVAL_5_HPP +#define BOOST_MATH_TOOLS_POLY_EVAL_5_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>(a[1] * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>((a[2] * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>(((a[3] * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<5>*) +{ + return static_cast<V>((((a[4] * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/polynomial_horner1_6.hpp b/Utilities/BGL/boost/math/tools/detail/polynomial_horner1_6.hpp new file mode 100644 index 0000000000000000000000000000000000000000..3f6d7e92876f2b0dfc4ee1ec0a956da54bd37aa5 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/polynomial_horner1_6.hpp @@ -0,0 +1,60 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_EVAL_6_HPP +#define BOOST_MATH_TOOLS_POLY_EVAL_6_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>(a[1] * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>((a[2] * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>(((a[3] * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<5>*) +{ + return static_cast<V>((((a[4] * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<6>*) +{ + return static_cast<V>(((((a[5] * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/polynomial_horner1_7.hpp b/Utilities/BGL/boost/math/tools/detail/polynomial_horner1_7.hpp new file mode 100644 index 0000000000000000000000000000000000000000..3091f1fcbf9ce40fc9f4b680aa8fc08cb1029233 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/polynomial_horner1_7.hpp @@ -0,0 +1,66 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_EVAL_7_HPP +#define BOOST_MATH_TOOLS_POLY_EVAL_7_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>(a[1] * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>((a[2] * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>(((a[3] * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<5>*) +{ + return static_cast<V>((((a[4] * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<6>*) +{ + return static_cast<V>(((((a[5] * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<7>*) +{ + return static_cast<V>((((((a[6] * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/polynomial_horner1_8.hpp b/Utilities/BGL/boost/math/tools/detail/polynomial_horner1_8.hpp new file mode 100644 index 0000000000000000000000000000000000000000..f3ffd22f844929248f2862a26d38a9957b140852 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/polynomial_horner1_8.hpp @@ -0,0 +1,72 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_EVAL_8_HPP +#define BOOST_MATH_TOOLS_POLY_EVAL_8_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>(a[1] * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>((a[2] * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>(((a[3] * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<5>*) +{ + return static_cast<V>((((a[4] * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<6>*) +{ + return static_cast<V>(((((a[5] * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<7>*) +{ + return static_cast<V>((((((a[6] * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<8>*) +{ + return static_cast<V>(((((((a[7] * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/polynomial_horner1_9.hpp b/Utilities/BGL/boost/math/tools/detail/polynomial_horner1_9.hpp new file mode 100644 index 0000000000000000000000000000000000000000..87e3869cecd069999ccfa6cba1dd6f5f59fdaf9b --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/polynomial_horner1_9.hpp @@ -0,0 +1,78 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_EVAL_9_HPP +#define BOOST_MATH_TOOLS_POLY_EVAL_9_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>(a[1] * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>((a[2] * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>(((a[3] * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<5>*) +{ + return static_cast<V>((((a[4] * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<6>*) +{ + return static_cast<V>(((((a[5] * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<7>*) +{ + return static_cast<V>((((((a[6] * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<8>*) +{ + return static_cast<V>(((((((a[7] * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<9>*) +{ + return static_cast<V>((((((((a[8] * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]); +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/polynomial_horner2_10.hpp b/Utilities/BGL/boost/math/tools/detail/polynomial_horner2_10.hpp new file mode 100644 index 0000000000000000000000000000000000000000..512e27d83cbb6025fa9ac784318e79456c2b0252 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/polynomial_horner2_10.hpp @@ -0,0 +1,90 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_EVAL_10_HPP +#define BOOST_MATH_TOOLS_POLY_EVAL_10_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>(a[1] * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>((a[2] * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>(((a[3] * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<5>*) +{ + V x2 = x * x; + return static_cast<V>((a[4] * x2 + a[2]) * x2 + a[0] + (a[3] * x2 + a[1]) * x); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<6>*) +{ + V x2 = x * x; + return static_cast<V>(((a[5] * x2 + a[3]) * x2 + a[1]) * x + (a[4] * x2 + a[2]) * x2 + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<7>*) +{ + V x2 = x * x; + return static_cast<V>(((a[6] * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + ((a[5] * x2 + a[3]) * x2 + a[1]) * x); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<8>*) +{ + V x2 = x * x; + return static_cast<V>((((a[7] * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + ((a[6] * x2 + a[4]) * x2 + a[2]) * x2 + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<9>*) +{ + V x2 = x * x; + return static_cast<V>((((a[8] * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + (((a[7] * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<10>*) +{ + V x2 = x * x; + return static_cast<V>(((((a[9] * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + (((a[8] * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]); +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/polynomial_horner2_11.hpp b/Utilities/BGL/boost/math/tools/detail/polynomial_horner2_11.hpp new file mode 100644 index 0000000000000000000000000000000000000000..6349c894fd52cd79a969b1c9138867e0f285b254 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/polynomial_horner2_11.hpp @@ -0,0 +1,97 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_EVAL_11_HPP +#define BOOST_MATH_TOOLS_POLY_EVAL_11_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>(a[1] * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>((a[2] * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>(((a[3] * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<5>*) +{ + V x2 = x * x; + return static_cast<V>((a[4] * x2 + a[2]) * x2 + a[0] + (a[3] * x2 + a[1]) * x); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<6>*) +{ + V x2 = x * x; + return static_cast<V>(((a[5] * x2 + a[3]) * x2 + a[1]) * x + (a[4] * x2 + a[2]) * x2 + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<7>*) +{ + V x2 = x * x; + return static_cast<V>(((a[6] * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + ((a[5] * x2 + a[3]) * x2 + a[1]) * x); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<8>*) +{ + V x2 = x * x; + return static_cast<V>((((a[7] * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + ((a[6] * x2 + a[4]) * x2 + a[2]) * x2 + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<9>*) +{ + V x2 = x * x; + return static_cast<V>((((a[8] * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + (((a[7] * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<10>*) +{ + V x2 = x * x; + return static_cast<V>(((((a[9] * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + (((a[8] * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<11>*) +{ + V x2 = x * x; + return static_cast<V>(((((a[10] * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + ((((a[9] * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x); +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/polynomial_horner2_12.hpp b/Utilities/BGL/boost/math/tools/detail/polynomial_horner2_12.hpp new file mode 100644 index 0000000000000000000000000000000000000000..02fabebbdb36d75e7746354cb1392a29cfe84bc0 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/polynomial_horner2_12.hpp @@ -0,0 +1,104 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_EVAL_12_HPP +#define BOOST_MATH_TOOLS_POLY_EVAL_12_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>(a[1] * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>((a[2] * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>(((a[3] * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<5>*) +{ + V x2 = x * x; + return static_cast<V>((a[4] * x2 + a[2]) * x2 + a[0] + (a[3] * x2 + a[1]) * x); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<6>*) +{ + V x2 = x * x; + return static_cast<V>(((a[5] * x2 + a[3]) * x2 + a[1]) * x + (a[4] * x2 + a[2]) * x2 + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<7>*) +{ + V x2 = x * x; + return static_cast<V>(((a[6] * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + ((a[5] * x2 + a[3]) * x2 + a[1]) * x); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<8>*) +{ + V x2 = x * x; + return static_cast<V>((((a[7] * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + ((a[6] * x2 + a[4]) * x2 + a[2]) * x2 + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<9>*) +{ + V x2 = x * x; + return static_cast<V>((((a[8] * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + (((a[7] * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<10>*) +{ + V x2 = x * x; + return static_cast<V>(((((a[9] * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + (((a[8] * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<11>*) +{ + V x2 = x * x; + return static_cast<V>(((((a[10] * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + ((((a[9] * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<12>*) +{ + V x2 = x * x; + return static_cast<V>((((((a[11] * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + ((((a[10] * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]); +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/polynomial_horner2_13.hpp b/Utilities/BGL/boost/math/tools/detail/polynomial_horner2_13.hpp new file mode 100644 index 0000000000000000000000000000000000000000..66c421a5f5738136a4d08764279abfc2eb438706 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/polynomial_horner2_13.hpp @@ -0,0 +1,111 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_EVAL_13_HPP +#define BOOST_MATH_TOOLS_POLY_EVAL_13_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>(a[1] * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>((a[2] * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>(((a[3] * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<5>*) +{ + V x2 = x * x; + return static_cast<V>((a[4] * x2 + a[2]) * x2 + a[0] + (a[3] * x2 + a[1]) * x); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<6>*) +{ + V x2 = x * x; + return static_cast<V>(((a[5] * x2 + a[3]) * x2 + a[1]) * x + (a[4] * x2 + a[2]) * x2 + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<7>*) +{ + V x2 = x * x; + return static_cast<V>(((a[6] * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + ((a[5] * x2 + a[3]) * x2 + a[1]) * x); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<8>*) +{ + V x2 = x * x; + return static_cast<V>((((a[7] * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + ((a[6] * x2 + a[4]) * x2 + a[2]) * x2 + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<9>*) +{ + V x2 = x * x; + return static_cast<V>((((a[8] * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + (((a[7] * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<10>*) +{ + V x2 = x * x; + return static_cast<V>(((((a[9] * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + (((a[8] * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<11>*) +{ + V x2 = x * x; + return static_cast<V>(((((a[10] * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + ((((a[9] * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<12>*) +{ + V x2 = x * x; + return static_cast<V>((((((a[11] * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + ((((a[10] * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<13>*) +{ + V x2 = x * x; + return static_cast<V>((((((a[12] * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + (((((a[11] * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x); +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/polynomial_horner2_14.hpp b/Utilities/BGL/boost/math/tools/detail/polynomial_horner2_14.hpp new file mode 100644 index 0000000000000000000000000000000000000000..dab8375fd6ed55dc88f836752f7a1eed60000cc8 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/polynomial_horner2_14.hpp @@ -0,0 +1,118 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_EVAL_14_HPP +#define BOOST_MATH_TOOLS_POLY_EVAL_14_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>(a[1] * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>((a[2] * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>(((a[3] * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<5>*) +{ + V x2 = x * x; + return static_cast<V>((a[4] * x2 + a[2]) * x2 + a[0] + (a[3] * x2 + a[1]) * x); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<6>*) +{ + V x2 = x * x; + return static_cast<V>(((a[5] * x2 + a[3]) * x2 + a[1]) * x + (a[4] * x2 + a[2]) * x2 + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<7>*) +{ + V x2 = x * x; + return static_cast<V>(((a[6] * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + ((a[5] * x2 + a[3]) * x2 + a[1]) * x); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<8>*) +{ + V x2 = x * x; + return static_cast<V>((((a[7] * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + ((a[6] * x2 + a[4]) * x2 + a[2]) * x2 + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<9>*) +{ + V x2 = x * x; + return static_cast<V>((((a[8] * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + (((a[7] * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<10>*) +{ + V x2 = x * x; + return static_cast<V>(((((a[9] * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + (((a[8] * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<11>*) +{ + V x2 = x * x; + return static_cast<V>(((((a[10] * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + ((((a[9] * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<12>*) +{ + V x2 = x * x; + return static_cast<V>((((((a[11] * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + ((((a[10] * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<13>*) +{ + V x2 = x * x; + return static_cast<V>((((((a[12] * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + (((((a[11] * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<14>*) +{ + V x2 = x * x; + return static_cast<V>(((((((a[13] * x2 + a[11]) * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + (((((a[12] * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]); +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/polynomial_horner2_15.hpp b/Utilities/BGL/boost/math/tools/detail/polynomial_horner2_15.hpp new file mode 100644 index 0000000000000000000000000000000000000000..a4ce91b8a61fd5634159ac26cf692b8429703b6f --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/polynomial_horner2_15.hpp @@ -0,0 +1,125 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_EVAL_15_HPP +#define BOOST_MATH_TOOLS_POLY_EVAL_15_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>(a[1] * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>((a[2] * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>(((a[3] * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<5>*) +{ + V x2 = x * x; + return static_cast<V>((a[4] * x2 + a[2]) * x2 + a[0] + (a[3] * x2 + a[1]) * x); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<6>*) +{ + V x2 = x * x; + return static_cast<V>(((a[5] * x2 + a[3]) * x2 + a[1]) * x + (a[4] * x2 + a[2]) * x2 + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<7>*) +{ + V x2 = x * x; + return static_cast<V>(((a[6] * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + ((a[5] * x2 + a[3]) * x2 + a[1]) * x); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<8>*) +{ + V x2 = x * x; + return static_cast<V>((((a[7] * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + ((a[6] * x2 + a[4]) * x2 + a[2]) * x2 + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<9>*) +{ + V x2 = x * x; + return static_cast<V>((((a[8] * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + (((a[7] * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<10>*) +{ + V x2 = x * x; + return static_cast<V>(((((a[9] * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + (((a[8] * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<11>*) +{ + V x2 = x * x; + return static_cast<V>(((((a[10] * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + ((((a[9] * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<12>*) +{ + V x2 = x * x; + return static_cast<V>((((((a[11] * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + ((((a[10] * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<13>*) +{ + V x2 = x * x; + return static_cast<V>((((((a[12] * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + (((((a[11] * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<14>*) +{ + V x2 = x * x; + return static_cast<V>(((((((a[13] * x2 + a[11]) * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + (((((a[12] * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<15>*) +{ + V x2 = x * x; + return static_cast<V>(((((((a[14] * x2 + a[12]) * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + ((((((a[13] * x2 + a[11]) * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x); +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/polynomial_horner2_16.hpp b/Utilities/BGL/boost/math/tools/detail/polynomial_horner2_16.hpp new file mode 100644 index 0000000000000000000000000000000000000000..e0a34352e143511a1bc03732e2c7be84eaba013a --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/polynomial_horner2_16.hpp @@ -0,0 +1,132 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_EVAL_16_HPP +#define BOOST_MATH_TOOLS_POLY_EVAL_16_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>(a[1] * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>((a[2] * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>(((a[3] * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<5>*) +{ + V x2 = x * x; + return static_cast<V>((a[4] * x2 + a[2]) * x2 + a[0] + (a[3] * x2 + a[1]) * x); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<6>*) +{ + V x2 = x * x; + return static_cast<V>(((a[5] * x2 + a[3]) * x2 + a[1]) * x + (a[4] * x2 + a[2]) * x2 + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<7>*) +{ + V x2 = x * x; + return static_cast<V>(((a[6] * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + ((a[5] * x2 + a[3]) * x2 + a[1]) * x); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<8>*) +{ + V x2 = x * x; + return static_cast<V>((((a[7] * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + ((a[6] * x2 + a[4]) * x2 + a[2]) * x2 + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<9>*) +{ + V x2 = x * x; + return static_cast<V>((((a[8] * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + (((a[7] * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<10>*) +{ + V x2 = x * x; + return static_cast<V>(((((a[9] * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + (((a[8] * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<11>*) +{ + V x2 = x * x; + return static_cast<V>(((((a[10] * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + ((((a[9] * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<12>*) +{ + V x2 = x * x; + return static_cast<V>((((((a[11] * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + ((((a[10] * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<13>*) +{ + V x2 = x * x; + return static_cast<V>((((((a[12] * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + (((((a[11] * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<14>*) +{ + V x2 = x * x; + return static_cast<V>(((((((a[13] * x2 + a[11]) * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + (((((a[12] * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<15>*) +{ + V x2 = x * x; + return static_cast<V>(((((((a[14] * x2 + a[12]) * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + ((((((a[13] * x2 + a[11]) * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<16>*) +{ + V x2 = x * x; + return static_cast<V>((((((((a[15] * x2 + a[13]) * x2 + a[11]) * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + ((((((a[14] * x2 + a[12]) * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]); +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/polynomial_horner2_17.hpp b/Utilities/BGL/boost/math/tools/detail/polynomial_horner2_17.hpp new file mode 100644 index 0000000000000000000000000000000000000000..d355011c122b48c6e9162c198de49625d2aecf20 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/polynomial_horner2_17.hpp @@ -0,0 +1,139 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_EVAL_17_HPP +#define BOOST_MATH_TOOLS_POLY_EVAL_17_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>(a[1] * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>((a[2] * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>(((a[3] * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<5>*) +{ + V x2 = x * x; + return static_cast<V>((a[4] * x2 + a[2]) * x2 + a[0] + (a[3] * x2 + a[1]) * x); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<6>*) +{ + V x2 = x * x; + return static_cast<V>(((a[5] * x2 + a[3]) * x2 + a[1]) * x + (a[4] * x2 + a[2]) * x2 + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<7>*) +{ + V x2 = x * x; + return static_cast<V>(((a[6] * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + ((a[5] * x2 + a[3]) * x2 + a[1]) * x); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<8>*) +{ + V x2 = x * x; + return static_cast<V>((((a[7] * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + ((a[6] * x2 + a[4]) * x2 + a[2]) * x2 + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<9>*) +{ + V x2 = x * x; + return static_cast<V>((((a[8] * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + (((a[7] * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<10>*) +{ + V x2 = x * x; + return static_cast<V>(((((a[9] * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + (((a[8] * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<11>*) +{ + V x2 = x * x; + return static_cast<V>(((((a[10] * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + ((((a[9] * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<12>*) +{ + V x2 = x * x; + return static_cast<V>((((((a[11] * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + ((((a[10] * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<13>*) +{ + V x2 = x * x; + return static_cast<V>((((((a[12] * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + (((((a[11] * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<14>*) +{ + V x2 = x * x; + return static_cast<V>(((((((a[13] * x2 + a[11]) * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + (((((a[12] * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<15>*) +{ + V x2 = x * x; + return static_cast<V>(((((((a[14] * x2 + a[12]) * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + ((((((a[13] * x2 + a[11]) * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<16>*) +{ + V x2 = x * x; + return static_cast<V>((((((((a[15] * x2 + a[13]) * x2 + a[11]) * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + ((((((a[14] * x2 + a[12]) * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<17>*) +{ + V x2 = x * x; + return static_cast<V>((((((((a[16] * x2 + a[14]) * x2 + a[12]) * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + (((((((a[15] * x2 + a[13]) * x2 + a[11]) * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x); +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/polynomial_horner2_18.hpp b/Utilities/BGL/boost/math/tools/detail/polynomial_horner2_18.hpp new file mode 100644 index 0000000000000000000000000000000000000000..e3eaae740dd1b93e65e80911caa1606123de34c3 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/polynomial_horner2_18.hpp @@ -0,0 +1,146 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_EVAL_18_HPP +#define BOOST_MATH_TOOLS_POLY_EVAL_18_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>(a[1] * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>((a[2] * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>(((a[3] * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<5>*) +{ + V x2 = x * x; + return static_cast<V>((a[4] * x2 + a[2]) * x2 + a[0] + (a[3] * x2 + a[1]) * x); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<6>*) +{ + V x2 = x * x; + return static_cast<V>(((a[5] * x2 + a[3]) * x2 + a[1]) * x + (a[4] * x2 + a[2]) * x2 + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<7>*) +{ + V x2 = x * x; + return static_cast<V>(((a[6] * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + ((a[5] * x2 + a[3]) * x2 + a[1]) * x); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<8>*) +{ + V x2 = x * x; + return static_cast<V>((((a[7] * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + ((a[6] * x2 + a[4]) * x2 + a[2]) * x2 + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<9>*) +{ + V x2 = x * x; + return static_cast<V>((((a[8] * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + (((a[7] * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<10>*) +{ + V x2 = x * x; + return static_cast<V>(((((a[9] * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + (((a[8] * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<11>*) +{ + V x2 = x * x; + return static_cast<V>(((((a[10] * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + ((((a[9] * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<12>*) +{ + V x2 = x * x; + return static_cast<V>((((((a[11] * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + ((((a[10] * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<13>*) +{ + V x2 = x * x; + return static_cast<V>((((((a[12] * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + (((((a[11] * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<14>*) +{ + V x2 = x * x; + return static_cast<V>(((((((a[13] * x2 + a[11]) * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + (((((a[12] * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<15>*) +{ + V x2 = x * x; + return static_cast<V>(((((((a[14] * x2 + a[12]) * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + ((((((a[13] * x2 + a[11]) * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<16>*) +{ + V x2 = x * x; + return static_cast<V>((((((((a[15] * x2 + a[13]) * x2 + a[11]) * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + ((((((a[14] * x2 + a[12]) * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<17>*) +{ + V x2 = x * x; + return static_cast<V>((((((((a[16] * x2 + a[14]) * x2 + a[12]) * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + (((((((a[15] * x2 + a[13]) * x2 + a[11]) * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<18>*) +{ + V x2 = x * x; + return static_cast<V>(((((((((a[17] * x2 + a[15]) * x2 + a[13]) * x2 + a[11]) * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + (((((((a[16] * x2 + a[14]) * x2 + a[12]) * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]); +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/polynomial_horner2_19.hpp b/Utilities/BGL/boost/math/tools/detail/polynomial_horner2_19.hpp new file mode 100644 index 0000000000000000000000000000000000000000..d37aba8612d993970ab586126df744988b3ef65a --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/polynomial_horner2_19.hpp @@ -0,0 +1,153 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_EVAL_19_HPP +#define BOOST_MATH_TOOLS_POLY_EVAL_19_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>(a[1] * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>((a[2] * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>(((a[3] * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<5>*) +{ + V x2 = x * x; + return static_cast<V>((a[4] * x2 + a[2]) * x2 + a[0] + (a[3] * x2 + a[1]) * x); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<6>*) +{ + V x2 = x * x; + return static_cast<V>(((a[5] * x2 + a[3]) * x2 + a[1]) * x + (a[4] * x2 + a[2]) * x2 + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<7>*) +{ + V x2 = x * x; + return static_cast<V>(((a[6] * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + ((a[5] * x2 + a[3]) * x2 + a[1]) * x); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<8>*) +{ + V x2 = x * x; + return static_cast<V>((((a[7] * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + ((a[6] * x2 + a[4]) * x2 + a[2]) * x2 + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<9>*) +{ + V x2 = x * x; + return static_cast<V>((((a[8] * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + (((a[7] * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<10>*) +{ + V x2 = x * x; + return static_cast<V>(((((a[9] * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + (((a[8] * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<11>*) +{ + V x2 = x * x; + return static_cast<V>(((((a[10] * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + ((((a[9] * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<12>*) +{ + V x2 = x * x; + return static_cast<V>((((((a[11] * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + ((((a[10] * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<13>*) +{ + V x2 = x * x; + return static_cast<V>((((((a[12] * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + (((((a[11] * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<14>*) +{ + V x2 = x * x; + return static_cast<V>(((((((a[13] * x2 + a[11]) * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + (((((a[12] * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<15>*) +{ + V x2 = x * x; + return static_cast<V>(((((((a[14] * x2 + a[12]) * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + ((((((a[13] * x2 + a[11]) * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<16>*) +{ + V x2 = x * x; + return static_cast<V>((((((((a[15] * x2 + a[13]) * x2 + a[11]) * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + ((((((a[14] * x2 + a[12]) * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<17>*) +{ + V x2 = x * x; + return static_cast<V>((((((((a[16] * x2 + a[14]) * x2 + a[12]) * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + (((((((a[15] * x2 + a[13]) * x2 + a[11]) * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<18>*) +{ + V x2 = x * x; + return static_cast<V>(((((((((a[17] * x2 + a[15]) * x2 + a[13]) * x2 + a[11]) * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + (((((((a[16] * x2 + a[14]) * x2 + a[12]) * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<19>*) +{ + V x2 = x * x; + return static_cast<V>(((((((((a[18] * x2 + a[16]) * x2 + a[14]) * x2 + a[12]) * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + ((((((((a[17] * x2 + a[15]) * x2 + a[13]) * x2 + a[11]) * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x); +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/polynomial_horner2_2.hpp b/Utilities/BGL/boost/math/tools/detail/polynomial_horner2_2.hpp new file mode 100644 index 0000000000000000000000000000000000000000..606bb980925e411318e22b11d3bf2f222ec863ad --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/polynomial_horner2_2.hpp @@ -0,0 +1,48 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_EVAL_2_HPP +#define BOOST_MATH_TOOLS_POLY_EVAL_2_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>(a[1] * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>((a[2] * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>(((a[3] * x + a[2]) * x + a[1]) * x + a[0]); +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/polynomial_horner2_20.hpp b/Utilities/BGL/boost/math/tools/detail/polynomial_horner2_20.hpp new file mode 100644 index 0000000000000000000000000000000000000000..052f8ae648cf88c0da0028c5885da4a882ddde0a --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/polynomial_horner2_20.hpp @@ -0,0 +1,160 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_EVAL_20_HPP +#define BOOST_MATH_TOOLS_POLY_EVAL_20_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>(a[1] * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>((a[2] * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>(((a[3] * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<5>*) +{ + V x2 = x * x; + return static_cast<V>((a[4] * x2 + a[2]) * x2 + a[0] + (a[3] * x2 + a[1]) * x); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<6>*) +{ + V x2 = x * x; + return static_cast<V>(((a[5] * x2 + a[3]) * x2 + a[1]) * x + (a[4] * x2 + a[2]) * x2 + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<7>*) +{ + V x2 = x * x; + return static_cast<V>(((a[6] * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + ((a[5] * x2 + a[3]) * x2 + a[1]) * x); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<8>*) +{ + V x2 = x * x; + return static_cast<V>((((a[7] * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + ((a[6] * x2 + a[4]) * x2 + a[2]) * x2 + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<9>*) +{ + V x2 = x * x; + return static_cast<V>((((a[8] * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + (((a[7] * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<10>*) +{ + V x2 = x * x; + return static_cast<V>(((((a[9] * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + (((a[8] * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<11>*) +{ + V x2 = x * x; + return static_cast<V>(((((a[10] * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + ((((a[9] * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<12>*) +{ + V x2 = x * x; + return static_cast<V>((((((a[11] * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + ((((a[10] * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<13>*) +{ + V x2 = x * x; + return static_cast<V>((((((a[12] * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + (((((a[11] * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<14>*) +{ + V x2 = x * x; + return static_cast<V>(((((((a[13] * x2 + a[11]) * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + (((((a[12] * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<15>*) +{ + V x2 = x * x; + return static_cast<V>(((((((a[14] * x2 + a[12]) * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + ((((((a[13] * x2 + a[11]) * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<16>*) +{ + V x2 = x * x; + return static_cast<V>((((((((a[15] * x2 + a[13]) * x2 + a[11]) * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + ((((((a[14] * x2 + a[12]) * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<17>*) +{ + V x2 = x * x; + return static_cast<V>((((((((a[16] * x2 + a[14]) * x2 + a[12]) * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + (((((((a[15] * x2 + a[13]) * x2 + a[11]) * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<18>*) +{ + V x2 = x * x; + return static_cast<V>(((((((((a[17] * x2 + a[15]) * x2 + a[13]) * x2 + a[11]) * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + (((((((a[16] * x2 + a[14]) * x2 + a[12]) * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<19>*) +{ + V x2 = x * x; + return static_cast<V>(((((((((a[18] * x2 + a[16]) * x2 + a[14]) * x2 + a[12]) * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + ((((((((a[17] * x2 + a[15]) * x2 + a[13]) * x2 + a[11]) * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<20>*) +{ + V x2 = x * x; + return static_cast<V>((((((((((a[19] * x2 + a[17]) * x2 + a[15]) * x2 + a[13]) * x2 + a[11]) * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + ((((((((a[18] * x2 + a[16]) * x2 + a[14]) * x2 + a[12]) * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]); +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/polynomial_horner2_3.hpp b/Utilities/BGL/boost/math/tools/detail/polynomial_horner2_3.hpp new file mode 100644 index 0000000000000000000000000000000000000000..6beb7928758c153f885e45e9f78b7eb39c2983e7 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/polynomial_horner2_3.hpp @@ -0,0 +1,48 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_EVAL_3_HPP +#define BOOST_MATH_TOOLS_POLY_EVAL_3_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>(a[1] * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>((a[2] * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>(((a[3] * x + a[2]) * x + a[1]) * x + a[0]); +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/polynomial_horner2_4.hpp b/Utilities/BGL/boost/math/tools/detail/polynomial_horner2_4.hpp new file mode 100644 index 0000000000000000000000000000000000000000..7e226d84b4c996f79e7891a8694e96640a63cb82 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/polynomial_horner2_4.hpp @@ -0,0 +1,48 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_EVAL_4_HPP +#define BOOST_MATH_TOOLS_POLY_EVAL_4_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>(a[1] * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>((a[2] * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>(((a[3] * x + a[2]) * x + a[1]) * x + a[0]); +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/polynomial_horner2_5.hpp b/Utilities/BGL/boost/math/tools/detail/polynomial_horner2_5.hpp new file mode 100644 index 0000000000000000000000000000000000000000..9cd89f00869ec7c6268e90f6eb0445b8f875d758 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/polynomial_horner2_5.hpp @@ -0,0 +1,55 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_EVAL_5_HPP +#define BOOST_MATH_TOOLS_POLY_EVAL_5_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>(a[1] * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>((a[2] * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>(((a[3] * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<5>*) +{ + V x2 = x * x; + return static_cast<V>((a[4] * x2 + a[2]) * x2 + a[0] + (a[3] * x2 + a[1]) * x); +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/polynomial_horner2_6.hpp b/Utilities/BGL/boost/math/tools/detail/polynomial_horner2_6.hpp new file mode 100644 index 0000000000000000000000000000000000000000..aff9c58e2ab8fbf7b781d8f0a67f8825c9753095 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/polynomial_horner2_6.hpp @@ -0,0 +1,62 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_EVAL_6_HPP +#define BOOST_MATH_TOOLS_POLY_EVAL_6_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>(a[1] * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>((a[2] * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>(((a[3] * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<5>*) +{ + V x2 = x * x; + return static_cast<V>((a[4] * x2 + a[2]) * x2 + a[0] + (a[3] * x2 + a[1]) * x); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<6>*) +{ + V x2 = x * x; + return static_cast<V>(((a[5] * x2 + a[3]) * x2 + a[1]) * x + (a[4] * x2 + a[2]) * x2 + a[0]); +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/polynomial_horner2_7.hpp b/Utilities/BGL/boost/math/tools/detail/polynomial_horner2_7.hpp new file mode 100644 index 0000000000000000000000000000000000000000..886ae623e885442e758d1df1899d46f9e94e5474 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/polynomial_horner2_7.hpp @@ -0,0 +1,69 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_EVAL_7_HPP +#define BOOST_MATH_TOOLS_POLY_EVAL_7_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>(a[1] * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>((a[2] * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>(((a[3] * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<5>*) +{ + V x2 = x * x; + return static_cast<V>((a[4] * x2 + a[2]) * x2 + a[0] + (a[3] * x2 + a[1]) * x); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<6>*) +{ + V x2 = x * x; + return static_cast<V>(((a[5] * x2 + a[3]) * x2 + a[1]) * x + (a[4] * x2 + a[2]) * x2 + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<7>*) +{ + V x2 = x * x; + return static_cast<V>(((a[6] * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + ((a[5] * x2 + a[3]) * x2 + a[1]) * x); +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/polynomial_horner2_8.hpp b/Utilities/BGL/boost/math/tools/detail/polynomial_horner2_8.hpp new file mode 100644 index 0000000000000000000000000000000000000000..1e57e9b62f2878c195f209bab5b79d245eff4911 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/polynomial_horner2_8.hpp @@ -0,0 +1,76 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_EVAL_8_HPP +#define BOOST_MATH_TOOLS_POLY_EVAL_8_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>(a[1] * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>((a[2] * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>(((a[3] * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<5>*) +{ + V x2 = x * x; + return static_cast<V>((a[4] * x2 + a[2]) * x2 + a[0] + (a[3] * x2 + a[1]) * x); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<6>*) +{ + V x2 = x * x; + return static_cast<V>(((a[5] * x2 + a[3]) * x2 + a[1]) * x + (a[4] * x2 + a[2]) * x2 + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<7>*) +{ + V x2 = x * x; + return static_cast<V>(((a[6] * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + ((a[5] * x2 + a[3]) * x2 + a[1]) * x); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<8>*) +{ + V x2 = x * x; + return static_cast<V>((((a[7] * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + ((a[6] * x2 + a[4]) * x2 + a[2]) * x2 + a[0]); +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/polynomial_horner2_9.hpp b/Utilities/BGL/boost/math/tools/detail/polynomial_horner2_9.hpp new file mode 100644 index 0000000000000000000000000000000000000000..0f41fd2a49a348e1003a560fb0b3c5a952c3661e --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/polynomial_horner2_9.hpp @@ -0,0 +1,83 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_EVAL_9_HPP +#define BOOST_MATH_TOOLS_POLY_EVAL_9_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>(a[1] * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>((a[2] * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>(((a[3] * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<5>*) +{ + V x2 = x * x; + return static_cast<V>((a[4] * x2 + a[2]) * x2 + a[0] + (a[3] * x2 + a[1]) * x); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<6>*) +{ + V x2 = x * x; + return static_cast<V>(((a[5] * x2 + a[3]) * x2 + a[1]) * x + (a[4] * x2 + a[2]) * x2 + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<7>*) +{ + V x2 = x * x; + return static_cast<V>(((a[6] * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + ((a[5] * x2 + a[3]) * x2 + a[1]) * x); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<8>*) +{ + V x2 = x * x; + return static_cast<V>((((a[7] * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + ((a[6] * x2 + a[4]) * x2 + a[2]) * x2 + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<9>*) +{ + V x2 = x * x; + return static_cast<V>((((a[8] * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + (((a[7] * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x); +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/polynomial_horner3_10.hpp b/Utilities/BGL/boost/math/tools/detail/polynomial_horner3_10.hpp new file mode 100644 index 0000000000000000000000000000000000000000..cbf1664897bc5ef0d6f35df84caebec23105fa99 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/polynomial_horner3_10.hpp @@ -0,0 +1,156 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Unrolled polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_EVAL_10_HPP +#define BOOST_MATH_TOOLS_POLY_EVAL_10_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>(a[1] * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>((a[2] * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>(((a[3] * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<5>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[4] * x2 + a[2]); + t[1] = static_cast<V>(a[3] * x2 + a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<6>*) +{ + V x2 = x * x; + V t[2]; + t[0] = a[5] * x2 + a[3]; + t[1] = a[4] * x2 + a[2]; + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[0] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<7>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[6] * x2 + a[4]); + t[1] = static_cast<V>(a[5] * x2 + a[3]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<8>*) +{ + V x2 = x * x; + V t[2]; + t[0] = a[7] * x2 + a[5]; + t[1] = a[6] * x2 + a[4]; + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[0] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<9>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[8] * x2 + a[6]); + t[1] = static_cast<V>(a[7] * x2 + a[5]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<10>*) +{ + V x2 = x * x; + V t[2]; + t[0] = a[9] * x2 + a[7]; + t[1] = a[8] * x2 + a[6]; + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[0] *= x; + return t[0] + t[1]; +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/polynomial_horner3_11.hpp b/Utilities/BGL/boost/math/tools/detail/polynomial_horner3_11.hpp new file mode 100644 index 0000000000000000000000000000000000000000..3adbfb389e1aa0ce9fbef4fa783a842ac00bb9e8 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/polynomial_horner3_11.hpp @@ -0,0 +1,181 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Unrolled polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_EVAL_11_HPP +#define BOOST_MATH_TOOLS_POLY_EVAL_11_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>(a[1] * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>((a[2] * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>(((a[3] * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<5>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[4] * x2 + a[2]); + t[1] = static_cast<V>(a[3] * x2 + a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<6>*) +{ + V x2 = x * x; + V t[2]; + t[0] = a[5] * x2 + a[3]; + t[1] = a[4] * x2 + a[2]; + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[0] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<7>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[6] * x2 + a[4]); + t[1] = static_cast<V>(a[5] * x2 + a[3]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<8>*) +{ + V x2 = x * x; + V t[2]; + t[0] = a[7] * x2 + a[5]; + t[1] = a[6] * x2 + a[4]; + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[0] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<9>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[8] * x2 + a[6]); + t[1] = static_cast<V>(a[7] * x2 + a[5]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<10>*) +{ + V x2 = x * x; + V t[2]; + t[0] = a[9] * x2 + a[7]; + t[1] = a[8] * x2 + a[6]; + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[0] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<11>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[10] * x2 + a[8]); + t[1] = static_cast<V>(a[9] * x2 + a[7]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[5]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/polynomial_horner3_12.hpp b/Utilities/BGL/boost/math/tools/detail/polynomial_horner3_12.hpp new file mode 100644 index 0000000000000000000000000000000000000000..6894a9d1a0dcc5d4e6d5ce30cf39a74d183f7606 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/polynomial_horner3_12.hpp @@ -0,0 +1,208 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Unrolled polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_EVAL_12_HPP +#define BOOST_MATH_TOOLS_POLY_EVAL_12_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>(a[1] * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>((a[2] * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>(((a[3] * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<5>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[4] * x2 + a[2]); + t[1] = static_cast<V>(a[3] * x2 + a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<6>*) +{ + V x2 = x * x; + V t[2]; + t[0] = a[5] * x2 + a[3]; + t[1] = a[4] * x2 + a[2]; + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[0] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<7>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[6] * x2 + a[4]); + t[1] = static_cast<V>(a[5] * x2 + a[3]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<8>*) +{ + V x2 = x * x; + V t[2]; + t[0] = a[7] * x2 + a[5]; + t[1] = a[6] * x2 + a[4]; + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[0] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<9>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[8] * x2 + a[6]); + t[1] = static_cast<V>(a[7] * x2 + a[5]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<10>*) +{ + V x2 = x * x; + V t[2]; + t[0] = a[9] * x2 + a[7]; + t[1] = a[8] * x2 + a[6]; + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[0] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<11>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[10] * x2 + a[8]); + t[1] = static_cast<V>(a[9] * x2 + a[7]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[5]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<12>*) +{ + V x2 = x * x; + V t[2]; + t[0] = a[11] * x2 + a[9]; + t[1] = a[10] * x2 + a[8]; + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[7]); + t[1] += static_cast<V>(a[6]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[0] *= x; + return t[0] + t[1]; +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/polynomial_horner3_13.hpp b/Utilities/BGL/boost/math/tools/detail/polynomial_horner3_13.hpp new file mode 100644 index 0000000000000000000000000000000000000000..3472e62822c56cd8807490e72b06d6a73f2fde5f --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/polynomial_horner3_13.hpp @@ -0,0 +1,237 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Unrolled polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_EVAL_13_HPP +#define BOOST_MATH_TOOLS_POLY_EVAL_13_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>(a[1] * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>((a[2] * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>(((a[3] * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<5>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[4] * x2 + a[2]); + t[1] = static_cast<V>(a[3] * x2 + a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<6>*) +{ + V x2 = x * x; + V t[2]; + t[0] = a[5] * x2 + a[3]; + t[1] = a[4] * x2 + a[2]; + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[0] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<7>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[6] * x2 + a[4]); + t[1] = static_cast<V>(a[5] * x2 + a[3]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<8>*) +{ + V x2 = x * x; + V t[2]; + t[0] = a[7] * x2 + a[5]; + t[1] = a[6] * x2 + a[4]; + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[0] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<9>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[8] * x2 + a[6]); + t[1] = static_cast<V>(a[7] * x2 + a[5]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<10>*) +{ + V x2 = x * x; + V t[2]; + t[0] = a[9] * x2 + a[7]; + t[1] = a[8] * x2 + a[6]; + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[0] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<11>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[10] * x2 + a[8]); + t[1] = static_cast<V>(a[9] * x2 + a[7]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[5]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<12>*) +{ + V x2 = x * x; + V t[2]; + t[0] = a[11] * x2 + a[9]; + t[1] = a[10] * x2 + a[8]; + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[7]); + t[1] += static_cast<V>(a[6]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[0] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<13>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[12] * x2 + a[10]); + t[1] = static_cast<V>(a[11] * x2 + a[9]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[7]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[5]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/polynomial_horner3_14.hpp b/Utilities/BGL/boost/math/tools/detail/polynomial_horner3_14.hpp new file mode 100644 index 0000000000000000000000000000000000000000..cbacac7e0c22efa5fe763047c283a854215a8749 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/polynomial_horner3_14.hpp @@ -0,0 +1,268 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Unrolled polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_EVAL_14_HPP +#define BOOST_MATH_TOOLS_POLY_EVAL_14_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>(a[1] * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>((a[2] * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>(((a[3] * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<5>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[4] * x2 + a[2]); + t[1] = static_cast<V>(a[3] * x2 + a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<6>*) +{ + V x2 = x * x; + V t[2]; + t[0] = a[5] * x2 + a[3]; + t[1] = a[4] * x2 + a[2]; + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[0] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<7>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[6] * x2 + a[4]); + t[1] = static_cast<V>(a[5] * x2 + a[3]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<8>*) +{ + V x2 = x * x; + V t[2]; + t[0] = a[7] * x2 + a[5]; + t[1] = a[6] * x2 + a[4]; + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[0] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<9>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[8] * x2 + a[6]); + t[1] = static_cast<V>(a[7] * x2 + a[5]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<10>*) +{ + V x2 = x * x; + V t[2]; + t[0] = a[9] * x2 + a[7]; + t[1] = a[8] * x2 + a[6]; + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[0] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<11>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[10] * x2 + a[8]); + t[1] = static_cast<V>(a[9] * x2 + a[7]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[5]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<12>*) +{ + V x2 = x * x; + V t[2]; + t[0] = a[11] * x2 + a[9]; + t[1] = a[10] * x2 + a[8]; + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[7]); + t[1] += static_cast<V>(a[6]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[0] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<13>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[12] * x2 + a[10]); + t[1] = static_cast<V>(a[11] * x2 + a[9]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[7]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[5]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<14>*) +{ + V x2 = x * x; + V t[2]; + t[0] = a[13] * x2 + a[11]; + t[1] = a[12] * x2 + a[10]; + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[9]); + t[1] += static_cast<V>(a[8]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[7]); + t[1] += static_cast<V>(a[6]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[0] *= x; + return t[0] + t[1]; +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/polynomial_horner3_15.hpp b/Utilities/BGL/boost/math/tools/detail/polynomial_horner3_15.hpp new file mode 100644 index 0000000000000000000000000000000000000000..abafcbc346736b18d3683e2f26c65b0731dae9b4 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/polynomial_horner3_15.hpp @@ -0,0 +1,301 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Unrolled polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_EVAL_15_HPP +#define BOOST_MATH_TOOLS_POLY_EVAL_15_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>(a[1] * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>((a[2] * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>(((a[3] * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<5>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[4] * x2 + a[2]); + t[1] = static_cast<V>(a[3] * x2 + a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<6>*) +{ + V x2 = x * x; + V t[2]; + t[0] = a[5] * x2 + a[3]; + t[1] = a[4] * x2 + a[2]; + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[0] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<7>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[6] * x2 + a[4]); + t[1] = static_cast<V>(a[5] * x2 + a[3]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<8>*) +{ + V x2 = x * x; + V t[2]; + t[0] = a[7] * x2 + a[5]; + t[1] = a[6] * x2 + a[4]; + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[0] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<9>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[8] * x2 + a[6]); + t[1] = static_cast<V>(a[7] * x2 + a[5]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<10>*) +{ + V x2 = x * x; + V t[2]; + t[0] = a[9] * x2 + a[7]; + t[1] = a[8] * x2 + a[6]; + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[0] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<11>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[10] * x2 + a[8]); + t[1] = static_cast<V>(a[9] * x2 + a[7]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[5]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<12>*) +{ + V x2 = x * x; + V t[2]; + t[0] = a[11] * x2 + a[9]; + t[1] = a[10] * x2 + a[8]; + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[7]); + t[1] += static_cast<V>(a[6]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[0] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<13>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[12] * x2 + a[10]); + t[1] = static_cast<V>(a[11] * x2 + a[9]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[7]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[5]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<14>*) +{ + V x2 = x * x; + V t[2]; + t[0] = a[13] * x2 + a[11]; + t[1] = a[12] * x2 + a[10]; + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[9]); + t[1] += static_cast<V>(a[8]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[7]); + t[1] += static_cast<V>(a[6]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[0] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<15>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[14] * x2 + a[12]); + t[1] = static_cast<V>(a[13] * x2 + a[11]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[9]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[7]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[5]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/polynomial_horner3_16.hpp b/Utilities/BGL/boost/math/tools/detail/polynomial_horner3_16.hpp new file mode 100644 index 0000000000000000000000000000000000000000..98a95c03ec3155b3e59d1c47c782e1136d7f7e55 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/polynomial_horner3_16.hpp @@ -0,0 +1,336 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Unrolled polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_EVAL_16_HPP +#define BOOST_MATH_TOOLS_POLY_EVAL_16_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>(a[1] * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>((a[2] * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>(((a[3] * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<5>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[4] * x2 + a[2]); + t[1] = static_cast<V>(a[3] * x2 + a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<6>*) +{ + V x2 = x * x; + V t[2]; + t[0] = a[5] * x2 + a[3]; + t[1] = a[4] * x2 + a[2]; + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[0] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<7>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[6] * x2 + a[4]); + t[1] = static_cast<V>(a[5] * x2 + a[3]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<8>*) +{ + V x2 = x * x; + V t[2]; + t[0] = a[7] * x2 + a[5]; + t[1] = a[6] * x2 + a[4]; + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[0] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<9>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[8] * x2 + a[6]); + t[1] = static_cast<V>(a[7] * x2 + a[5]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<10>*) +{ + V x2 = x * x; + V t[2]; + t[0] = a[9] * x2 + a[7]; + t[1] = a[8] * x2 + a[6]; + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[0] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<11>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[10] * x2 + a[8]); + t[1] = static_cast<V>(a[9] * x2 + a[7]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[5]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<12>*) +{ + V x2 = x * x; + V t[2]; + t[0] = a[11] * x2 + a[9]; + t[1] = a[10] * x2 + a[8]; + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[7]); + t[1] += static_cast<V>(a[6]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[0] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<13>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[12] * x2 + a[10]); + t[1] = static_cast<V>(a[11] * x2 + a[9]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[7]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[5]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<14>*) +{ + V x2 = x * x; + V t[2]; + t[0] = a[13] * x2 + a[11]; + t[1] = a[12] * x2 + a[10]; + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[9]); + t[1] += static_cast<V>(a[8]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[7]); + t[1] += static_cast<V>(a[6]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[0] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<15>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[14] * x2 + a[12]); + t[1] = static_cast<V>(a[13] * x2 + a[11]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[9]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[7]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[5]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<16>*) +{ + V x2 = x * x; + V t[2]; + t[0] = a[15] * x2 + a[13]; + t[1] = a[14] * x2 + a[12]; + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[11]); + t[1] += static_cast<V>(a[10]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[9]); + t[1] += static_cast<V>(a[8]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[7]); + t[1] += static_cast<V>(a[6]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[0] *= x; + return t[0] + t[1]; +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/polynomial_horner3_17.hpp b/Utilities/BGL/boost/math/tools/detail/polynomial_horner3_17.hpp new file mode 100644 index 0000000000000000000000000000000000000000..c61b83c031811ad6757ef25ae7a1c1baa5be7f4f --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/polynomial_horner3_17.hpp @@ -0,0 +1,373 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Unrolled polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_EVAL_17_HPP +#define BOOST_MATH_TOOLS_POLY_EVAL_17_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>(a[1] * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>((a[2] * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>(((a[3] * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<5>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[4] * x2 + a[2]); + t[1] = static_cast<V>(a[3] * x2 + a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<6>*) +{ + V x2 = x * x; + V t[2]; + t[0] = a[5] * x2 + a[3]; + t[1] = a[4] * x2 + a[2]; + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[0] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<7>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[6] * x2 + a[4]); + t[1] = static_cast<V>(a[5] * x2 + a[3]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<8>*) +{ + V x2 = x * x; + V t[2]; + t[0] = a[7] * x2 + a[5]; + t[1] = a[6] * x2 + a[4]; + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[0] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<9>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[8] * x2 + a[6]); + t[1] = static_cast<V>(a[7] * x2 + a[5]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<10>*) +{ + V x2 = x * x; + V t[2]; + t[0] = a[9] * x2 + a[7]; + t[1] = a[8] * x2 + a[6]; + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[0] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<11>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[10] * x2 + a[8]); + t[1] = static_cast<V>(a[9] * x2 + a[7]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[5]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<12>*) +{ + V x2 = x * x; + V t[2]; + t[0] = a[11] * x2 + a[9]; + t[1] = a[10] * x2 + a[8]; + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[7]); + t[1] += static_cast<V>(a[6]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[0] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<13>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[12] * x2 + a[10]); + t[1] = static_cast<V>(a[11] * x2 + a[9]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[7]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[5]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<14>*) +{ + V x2 = x * x; + V t[2]; + t[0] = a[13] * x2 + a[11]; + t[1] = a[12] * x2 + a[10]; + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[9]); + t[1] += static_cast<V>(a[8]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[7]); + t[1] += static_cast<V>(a[6]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[0] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<15>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[14] * x2 + a[12]); + t[1] = static_cast<V>(a[13] * x2 + a[11]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[9]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[7]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[5]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<16>*) +{ + V x2 = x * x; + V t[2]; + t[0] = a[15] * x2 + a[13]; + t[1] = a[14] * x2 + a[12]; + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[11]); + t[1] += static_cast<V>(a[10]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[9]); + t[1] += static_cast<V>(a[8]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[7]); + t[1] += static_cast<V>(a[6]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[0] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<17>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[16] * x2 + a[14]); + t[1] = static_cast<V>(a[15] * x2 + a[13]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[12]); + t[1] += static_cast<V>(a[11]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[9]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[7]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[5]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/polynomial_horner3_18.hpp b/Utilities/BGL/boost/math/tools/detail/polynomial_horner3_18.hpp new file mode 100644 index 0000000000000000000000000000000000000000..317155719e2cbfade9eba2403b885478ef9e23db --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/polynomial_horner3_18.hpp @@ -0,0 +1,412 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Unrolled polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_EVAL_18_HPP +#define BOOST_MATH_TOOLS_POLY_EVAL_18_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>(a[1] * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>((a[2] * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>(((a[3] * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<5>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[4] * x2 + a[2]); + t[1] = static_cast<V>(a[3] * x2 + a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<6>*) +{ + V x2 = x * x; + V t[2]; + t[0] = a[5] * x2 + a[3]; + t[1] = a[4] * x2 + a[2]; + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[0] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<7>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[6] * x2 + a[4]); + t[1] = static_cast<V>(a[5] * x2 + a[3]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<8>*) +{ + V x2 = x * x; + V t[2]; + t[0] = a[7] * x2 + a[5]; + t[1] = a[6] * x2 + a[4]; + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[0] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<9>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[8] * x2 + a[6]); + t[1] = static_cast<V>(a[7] * x2 + a[5]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<10>*) +{ + V x2 = x * x; + V t[2]; + t[0] = a[9] * x2 + a[7]; + t[1] = a[8] * x2 + a[6]; + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[0] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<11>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[10] * x2 + a[8]); + t[1] = static_cast<V>(a[9] * x2 + a[7]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[5]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<12>*) +{ + V x2 = x * x; + V t[2]; + t[0] = a[11] * x2 + a[9]; + t[1] = a[10] * x2 + a[8]; + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[7]); + t[1] += static_cast<V>(a[6]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[0] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<13>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[12] * x2 + a[10]); + t[1] = static_cast<V>(a[11] * x2 + a[9]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[7]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[5]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<14>*) +{ + V x2 = x * x; + V t[2]; + t[0] = a[13] * x2 + a[11]; + t[1] = a[12] * x2 + a[10]; + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[9]); + t[1] += static_cast<V>(a[8]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[7]); + t[1] += static_cast<V>(a[6]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[0] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<15>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[14] * x2 + a[12]); + t[1] = static_cast<V>(a[13] * x2 + a[11]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[9]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[7]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[5]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<16>*) +{ + V x2 = x * x; + V t[2]; + t[0] = a[15] * x2 + a[13]; + t[1] = a[14] * x2 + a[12]; + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[11]); + t[1] += static_cast<V>(a[10]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[9]); + t[1] += static_cast<V>(a[8]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[7]); + t[1] += static_cast<V>(a[6]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[0] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<17>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[16] * x2 + a[14]); + t[1] = static_cast<V>(a[15] * x2 + a[13]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[12]); + t[1] += static_cast<V>(a[11]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[9]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[7]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[5]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<18>*) +{ + V x2 = x * x; + V t[2]; + t[0] = a[17] * x2 + a[15]; + t[1] = a[16] * x2 + a[14]; + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[13]); + t[1] += static_cast<V>(a[12]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[11]); + t[1] += static_cast<V>(a[10]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[9]); + t[1] += static_cast<V>(a[8]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[7]); + t[1] += static_cast<V>(a[6]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[0] *= x; + return t[0] + t[1]; +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/polynomial_horner3_19.hpp b/Utilities/BGL/boost/math/tools/detail/polynomial_horner3_19.hpp new file mode 100644 index 0000000000000000000000000000000000000000..d1aed09036826868111b2823e86b2ceb1bb601d0 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/polynomial_horner3_19.hpp @@ -0,0 +1,453 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Unrolled polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_EVAL_19_HPP +#define BOOST_MATH_TOOLS_POLY_EVAL_19_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>(a[1] * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>((a[2] * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>(((a[3] * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<5>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[4] * x2 + a[2]); + t[1] = static_cast<V>(a[3] * x2 + a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<6>*) +{ + V x2 = x * x; + V t[2]; + t[0] = a[5] * x2 + a[3]; + t[1] = a[4] * x2 + a[2]; + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[0] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<7>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[6] * x2 + a[4]); + t[1] = static_cast<V>(a[5] * x2 + a[3]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<8>*) +{ + V x2 = x * x; + V t[2]; + t[0] = a[7] * x2 + a[5]; + t[1] = a[6] * x2 + a[4]; + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[0] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<9>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[8] * x2 + a[6]); + t[1] = static_cast<V>(a[7] * x2 + a[5]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<10>*) +{ + V x2 = x * x; + V t[2]; + t[0] = a[9] * x2 + a[7]; + t[1] = a[8] * x2 + a[6]; + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[0] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<11>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[10] * x2 + a[8]); + t[1] = static_cast<V>(a[9] * x2 + a[7]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[5]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<12>*) +{ + V x2 = x * x; + V t[2]; + t[0] = a[11] * x2 + a[9]; + t[1] = a[10] * x2 + a[8]; + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[7]); + t[1] += static_cast<V>(a[6]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[0] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<13>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[12] * x2 + a[10]); + t[1] = static_cast<V>(a[11] * x2 + a[9]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[7]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[5]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<14>*) +{ + V x2 = x * x; + V t[2]; + t[0] = a[13] * x2 + a[11]; + t[1] = a[12] * x2 + a[10]; + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[9]); + t[1] += static_cast<V>(a[8]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[7]); + t[1] += static_cast<V>(a[6]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[0] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<15>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[14] * x2 + a[12]); + t[1] = static_cast<V>(a[13] * x2 + a[11]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[9]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[7]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[5]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<16>*) +{ + V x2 = x * x; + V t[2]; + t[0] = a[15] * x2 + a[13]; + t[1] = a[14] * x2 + a[12]; + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[11]); + t[1] += static_cast<V>(a[10]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[9]); + t[1] += static_cast<V>(a[8]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[7]); + t[1] += static_cast<V>(a[6]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[0] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<17>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[16] * x2 + a[14]); + t[1] = static_cast<V>(a[15] * x2 + a[13]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[12]); + t[1] += static_cast<V>(a[11]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[9]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[7]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[5]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<18>*) +{ + V x2 = x * x; + V t[2]; + t[0] = a[17] * x2 + a[15]; + t[1] = a[16] * x2 + a[14]; + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[13]); + t[1] += static_cast<V>(a[12]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[11]); + t[1] += static_cast<V>(a[10]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[9]); + t[1] += static_cast<V>(a[8]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[7]); + t[1] += static_cast<V>(a[6]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[0] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<19>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[18] * x2 + a[16]); + t[1] = static_cast<V>(a[17] * x2 + a[15]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[14]); + t[1] += static_cast<V>(a[13]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[12]); + t[1] += static_cast<V>(a[11]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[9]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[7]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[5]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/polynomial_horner3_2.hpp b/Utilities/BGL/boost/math/tools/detail/polynomial_horner3_2.hpp new file mode 100644 index 0000000000000000000000000000000000000000..f8c0d1bd47f4489f643f95c5914a8233403e15a1 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/polynomial_horner3_2.hpp @@ -0,0 +1,48 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Unrolled polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_EVAL_2_HPP +#define BOOST_MATH_TOOLS_POLY_EVAL_2_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>(a[1] * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>((a[2] * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>(((a[3] * x + a[2]) * x + a[1]) * x + a[0]); +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/polynomial_horner3_20.hpp b/Utilities/BGL/boost/math/tools/detail/polynomial_horner3_20.hpp new file mode 100644 index 0000000000000000000000000000000000000000..499352d1e50283ebe288b52700d38d85906dbb25 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/polynomial_horner3_20.hpp @@ -0,0 +1,496 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Unrolled polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_EVAL_20_HPP +#define BOOST_MATH_TOOLS_POLY_EVAL_20_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>(a[1] * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>((a[2] * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>(((a[3] * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<5>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[4] * x2 + a[2]); + t[1] = static_cast<V>(a[3] * x2 + a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<6>*) +{ + V x2 = x * x; + V t[2]; + t[0] = a[5] * x2 + a[3]; + t[1] = a[4] * x2 + a[2]; + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[0] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<7>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[6] * x2 + a[4]); + t[1] = static_cast<V>(a[5] * x2 + a[3]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<8>*) +{ + V x2 = x * x; + V t[2]; + t[0] = a[7] * x2 + a[5]; + t[1] = a[6] * x2 + a[4]; + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[0] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<9>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[8] * x2 + a[6]); + t[1] = static_cast<V>(a[7] * x2 + a[5]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<10>*) +{ + V x2 = x * x; + V t[2]; + t[0] = a[9] * x2 + a[7]; + t[1] = a[8] * x2 + a[6]; + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[0] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<11>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[10] * x2 + a[8]); + t[1] = static_cast<V>(a[9] * x2 + a[7]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[5]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<12>*) +{ + V x2 = x * x; + V t[2]; + t[0] = a[11] * x2 + a[9]; + t[1] = a[10] * x2 + a[8]; + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[7]); + t[1] += static_cast<V>(a[6]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[0] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<13>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[12] * x2 + a[10]); + t[1] = static_cast<V>(a[11] * x2 + a[9]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[7]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[5]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<14>*) +{ + V x2 = x * x; + V t[2]; + t[0] = a[13] * x2 + a[11]; + t[1] = a[12] * x2 + a[10]; + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[9]); + t[1] += static_cast<V>(a[8]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[7]); + t[1] += static_cast<V>(a[6]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[0] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<15>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[14] * x2 + a[12]); + t[1] = static_cast<V>(a[13] * x2 + a[11]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[9]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[7]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[5]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<16>*) +{ + V x2 = x * x; + V t[2]; + t[0] = a[15] * x2 + a[13]; + t[1] = a[14] * x2 + a[12]; + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[11]); + t[1] += static_cast<V>(a[10]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[9]); + t[1] += static_cast<V>(a[8]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[7]); + t[1] += static_cast<V>(a[6]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[0] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<17>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[16] * x2 + a[14]); + t[1] = static_cast<V>(a[15] * x2 + a[13]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[12]); + t[1] += static_cast<V>(a[11]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[9]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[7]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[5]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<18>*) +{ + V x2 = x * x; + V t[2]; + t[0] = a[17] * x2 + a[15]; + t[1] = a[16] * x2 + a[14]; + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[13]); + t[1] += static_cast<V>(a[12]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[11]); + t[1] += static_cast<V>(a[10]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[9]); + t[1] += static_cast<V>(a[8]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[7]); + t[1] += static_cast<V>(a[6]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[0] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<19>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[18] * x2 + a[16]); + t[1] = static_cast<V>(a[17] * x2 + a[15]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[14]); + t[1] += static_cast<V>(a[13]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[12]); + t[1] += static_cast<V>(a[11]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[9]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[7]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[5]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<20>*) +{ + V x2 = x * x; + V t[2]; + t[0] = a[19] * x2 + a[17]; + t[1] = a[18] * x2 + a[16]; + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[15]); + t[1] += static_cast<V>(a[14]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[13]); + t[1] += static_cast<V>(a[12]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[11]); + t[1] += static_cast<V>(a[10]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[9]); + t[1] += static_cast<V>(a[8]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[7]); + t[1] += static_cast<V>(a[6]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[0] *= x; + return t[0] + t[1]; +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/polynomial_horner3_3.hpp b/Utilities/BGL/boost/math/tools/detail/polynomial_horner3_3.hpp new file mode 100644 index 0000000000000000000000000000000000000000..66b8d3c3bda56bfaf6f9348ec7fe7461e7b5a7b6 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/polynomial_horner3_3.hpp @@ -0,0 +1,48 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Unrolled polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_EVAL_3_HPP +#define BOOST_MATH_TOOLS_POLY_EVAL_3_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>(a[1] * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>((a[2] * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>(((a[3] * x + a[2]) * x + a[1]) * x + a[0]); +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/polynomial_horner3_4.hpp b/Utilities/BGL/boost/math/tools/detail/polynomial_horner3_4.hpp new file mode 100644 index 0000000000000000000000000000000000000000..49917d76aad7fa7d45925e7c288eb014ed258ec0 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/polynomial_horner3_4.hpp @@ -0,0 +1,48 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Unrolled polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_EVAL_4_HPP +#define BOOST_MATH_TOOLS_POLY_EVAL_4_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>(a[1] * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>((a[2] * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>(((a[3] * x + a[2]) * x + a[1]) * x + a[0]); +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/polynomial_horner3_5.hpp b/Utilities/BGL/boost/math/tools/detail/polynomial_horner3_5.hpp new file mode 100644 index 0000000000000000000000000000000000000000..96d54f6c18bc1cd2feab8e5e2a20cd061acd9bca --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/polynomial_horner3_5.hpp @@ -0,0 +1,61 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Unrolled polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_EVAL_5_HPP +#define BOOST_MATH_TOOLS_POLY_EVAL_5_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>(a[1] * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>((a[2] * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>(((a[3] * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<5>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[4] * x2 + a[2]); + t[1] = static_cast<V>(a[3] * x2 + a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/polynomial_horner3_6.hpp b/Utilities/BGL/boost/math/tools/detail/polynomial_horner3_6.hpp new file mode 100644 index 0000000000000000000000000000000000000000..41f6c1f9504b41927182a23c3aefcd9be594bde0 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/polynomial_horner3_6.hpp @@ -0,0 +1,76 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Unrolled polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_EVAL_6_HPP +#define BOOST_MATH_TOOLS_POLY_EVAL_6_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>(a[1] * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>((a[2] * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>(((a[3] * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<5>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[4] * x2 + a[2]); + t[1] = static_cast<V>(a[3] * x2 + a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<6>*) +{ + V x2 = x * x; + V t[2]; + t[0] = a[5] * x2 + a[3]; + t[1] = a[4] * x2 + a[2]; + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[0] *= x; + return t[0] + t[1]; +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/polynomial_horner3_7.hpp b/Utilities/BGL/boost/math/tools/detail/polynomial_horner3_7.hpp new file mode 100644 index 0000000000000000000000000000000000000000..695645b71687ef8ec0cf342c8b365f8287e71c9c --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/polynomial_horner3_7.hpp @@ -0,0 +1,93 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Unrolled polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_EVAL_7_HPP +#define BOOST_MATH_TOOLS_POLY_EVAL_7_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>(a[1] * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>((a[2] * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>(((a[3] * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<5>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[4] * x2 + a[2]); + t[1] = static_cast<V>(a[3] * x2 + a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<6>*) +{ + V x2 = x * x; + V t[2]; + t[0] = a[5] * x2 + a[3]; + t[1] = a[4] * x2 + a[2]; + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[0] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<7>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[6] * x2 + a[4]); + t[1] = static_cast<V>(a[5] * x2 + a[3]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/polynomial_horner3_8.hpp b/Utilities/BGL/boost/math/tools/detail/polynomial_horner3_8.hpp new file mode 100644 index 0000000000000000000000000000000000000000..180d27d38d099ccf43d3f25aa54ac8f1636ef33f --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/polynomial_horner3_8.hpp @@ -0,0 +1,112 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Unrolled polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_EVAL_8_HPP +#define BOOST_MATH_TOOLS_POLY_EVAL_8_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>(a[1] * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>((a[2] * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>(((a[3] * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<5>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[4] * x2 + a[2]); + t[1] = static_cast<V>(a[3] * x2 + a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<6>*) +{ + V x2 = x * x; + V t[2]; + t[0] = a[5] * x2 + a[3]; + t[1] = a[4] * x2 + a[2]; + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[0] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<7>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[6] * x2 + a[4]); + t[1] = static_cast<V>(a[5] * x2 + a[3]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<8>*) +{ + V x2 = x * x; + V t[2]; + t[0] = a[7] * x2 + a[5]; + t[1] = a[6] * x2 + a[4]; + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[0] *= x; + return t[0] + t[1]; +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/polynomial_horner3_9.hpp b/Utilities/BGL/boost/math/tools/detail/polynomial_horner3_9.hpp new file mode 100644 index 0000000000000000000000000000000000000000..e47d610b9090be88d6eef3115243dea7097e2d9f --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/polynomial_horner3_9.hpp @@ -0,0 +1,133 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Unrolled polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_EVAL_9_HPP +#define BOOST_MATH_TOOLS_POLY_EVAL_9_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>(a[1] * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>((a[2] * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>(((a[3] * x + a[2]) * x + a[1]) * x + a[0]); +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<5>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[4] * x2 + a[2]); + t[1] = static_cast<V>(a[3] * x2 + a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<6>*) +{ + V x2 = x * x; + V t[2]; + t[0] = a[5] * x2 + a[3]; + t[1] = a[4] * x2 + a[2]; + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[0] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<7>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[6] * x2 + a[4]); + t[1] = static_cast<V>(a[5] * x2 + a[3]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<8>*) +{ + V x2 = x * x; + V t[2]; + t[0] = a[7] * x2 + a[5]; + t[1] = a[6] * x2 + a[4]; + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[0] *= x; + return t[0] + t[1]; +} + +template <class T, class V> +inline V evaluate_polynomial_c_imp(const T* a, const V& x, const mpl::int_<9>*) +{ + V x2 = x * x; + V t[2]; + t[0] = static_cast<V>(a[8] * x2 + a[6]); + t[1] = static_cast<V>(a[7] * x2 + a[5]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[0] *= x2; + t[1] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[0] *= x2; + t[0] += static_cast<V>(a[0]); + t[1] *= x; + return t[0] + t[1]; +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/rational_horner1_10.hpp b/Utilities/BGL/boost/math/tools/detail/rational_horner1_10.hpp new file mode 100644 index 0000000000000000000000000000000000000000..10ae0f81b693a02e51a7e0587cdab47cd257a803 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/rational_horner1_10.hpp @@ -0,0 +1,138 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_RAT_10_HPP +#define BOOST_MATH_TOOLS_POLY_RAT_10_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T*, const U*, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]) / static_cast<V>(b[0]); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<2>*) +{ + if(x <= 1) + return static_cast<V>((a[1] * x + a[0]) / (b[1] * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((a[0] * z + a[1]) / (b[0] * z + b[1])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<3>*) +{ + if(x <= 1) + return static_cast<V>(((a[2] * x + a[1]) * x + a[0]) / ((b[2] * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((a[0] * z + a[1]) * z + a[2]) / ((b[0] * z + b[1]) * z + b[2])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<4>*) +{ + if(x <= 1) + return static_cast<V>((((a[3] * x + a[2]) * x + a[1]) * x + a[0]) / (((b[3] * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) / (((b[0] * z + b[1]) * z + b[2]) * z + b[3])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<5>*) +{ + if(x <= 1) + return static_cast<V>(((((a[4] * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((b[4] * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) / ((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<6>*) +{ + if(x <= 1) + return static_cast<V>((((((a[5] * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / (((((b[5] * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) / (((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<7>*) +{ + if(x <= 1) + return static_cast<V>(((((((a[6] * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((((b[6] * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) / ((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<8>*) +{ + if(x <= 1) + return static_cast<V>((((((((a[7] * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / (((((((b[7] * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) / (((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<9>*) +{ + if(x <= 1) + return static_cast<V>(((((((((a[8] * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((((((b[8] * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) / ((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<10>*) +{ + if(x <= 1) + return static_cast<V>((((((((((a[9] * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / (((((((((b[9] * x + b[8]) * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) * z + a[9]) / (((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8]) * z + b[9])); + } +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/rational_horner1_11.hpp b/Utilities/BGL/boost/math/tools/detail/rational_horner1_11.hpp new file mode 100644 index 0000000000000000000000000000000000000000..d8ca2acc44a22baba08450ddd03a7c95508b36cf --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/rational_horner1_11.hpp @@ -0,0 +1,150 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_RAT_11_HPP +#define BOOST_MATH_TOOLS_POLY_RAT_11_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T*, const U*, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]) / static_cast<V>(b[0]); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<2>*) +{ + if(x <= 1) + return static_cast<V>((a[1] * x + a[0]) / (b[1] * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((a[0] * z + a[1]) / (b[0] * z + b[1])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<3>*) +{ + if(x <= 1) + return static_cast<V>(((a[2] * x + a[1]) * x + a[0]) / ((b[2] * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((a[0] * z + a[1]) * z + a[2]) / ((b[0] * z + b[1]) * z + b[2])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<4>*) +{ + if(x <= 1) + return static_cast<V>((((a[3] * x + a[2]) * x + a[1]) * x + a[0]) / (((b[3] * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) / (((b[0] * z + b[1]) * z + b[2]) * z + b[3])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<5>*) +{ + if(x <= 1) + return static_cast<V>(((((a[4] * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((b[4] * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) / ((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<6>*) +{ + if(x <= 1) + return static_cast<V>((((((a[5] * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / (((((b[5] * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) / (((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<7>*) +{ + if(x <= 1) + return static_cast<V>(((((((a[6] * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((((b[6] * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) / ((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<8>*) +{ + if(x <= 1) + return static_cast<V>((((((((a[7] * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / (((((((b[7] * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) / (((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<9>*) +{ + if(x <= 1) + return static_cast<V>(((((((((a[8] * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((((((b[8] * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) / ((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<10>*) +{ + if(x <= 1) + return static_cast<V>((((((((((a[9] * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / (((((((((b[9] * x + b[8]) * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) * z + a[9]) / (((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8]) * z + b[9])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<11>*) +{ + if(x <= 1) + return static_cast<V>(((((((((((a[10] * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((((((((b[10] * x + b[9]) * x + b[8]) * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) * z + a[9]) * z + a[10]) / ((((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8]) * z + b[9]) * z + b[10])); + } +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/rational_horner1_12.hpp b/Utilities/BGL/boost/math/tools/detail/rational_horner1_12.hpp new file mode 100644 index 0000000000000000000000000000000000000000..5530d14fb003948ef90bb9809428a3e07ed7cf6f --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/rational_horner1_12.hpp @@ -0,0 +1,162 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_RAT_12_HPP +#define BOOST_MATH_TOOLS_POLY_RAT_12_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T*, const U*, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]) / static_cast<V>(b[0]); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<2>*) +{ + if(x <= 1) + return static_cast<V>((a[1] * x + a[0]) / (b[1] * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((a[0] * z + a[1]) / (b[0] * z + b[1])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<3>*) +{ + if(x <= 1) + return static_cast<V>(((a[2] * x + a[1]) * x + a[0]) / ((b[2] * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((a[0] * z + a[1]) * z + a[2]) / ((b[0] * z + b[1]) * z + b[2])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<4>*) +{ + if(x <= 1) + return static_cast<V>((((a[3] * x + a[2]) * x + a[1]) * x + a[0]) / (((b[3] * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) / (((b[0] * z + b[1]) * z + b[2]) * z + b[3])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<5>*) +{ + if(x <= 1) + return static_cast<V>(((((a[4] * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((b[4] * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) / ((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<6>*) +{ + if(x <= 1) + return static_cast<V>((((((a[5] * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / (((((b[5] * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) / (((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<7>*) +{ + if(x <= 1) + return static_cast<V>(((((((a[6] * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((((b[6] * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) / ((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<8>*) +{ + if(x <= 1) + return static_cast<V>((((((((a[7] * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / (((((((b[7] * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) / (((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<9>*) +{ + if(x <= 1) + return static_cast<V>(((((((((a[8] * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((((((b[8] * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) / ((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<10>*) +{ + if(x <= 1) + return static_cast<V>((((((((((a[9] * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / (((((((((b[9] * x + b[8]) * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) * z + a[9]) / (((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8]) * z + b[9])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<11>*) +{ + if(x <= 1) + return static_cast<V>(((((((((((a[10] * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((((((((b[10] * x + b[9]) * x + b[8]) * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) * z + a[9]) * z + a[10]) / ((((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8]) * z + b[9]) * z + b[10])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<12>*) +{ + if(x <= 1) + return static_cast<V>((((((((((((a[11] * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / (((((((((((b[11] * x + b[10]) * x + b[9]) * x + b[8]) * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) * z + a[9]) * z + a[10]) * z + a[11]) / (((((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8]) * z + b[9]) * z + b[10]) * z + b[11])); + } +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/rational_horner1_13.hpp b/Utilities/BGL/boost/math/tools/detail/rational_horner1_13.hpp new file mode 100644 index 0000000000000000000000000000000000000000..bb0c263fec4375ea5f0b8be352e69113569aa13c --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/rational_horner1_13.hpp @@ -0,0 +1,174 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_RAT_13_HPP +#define BOOST_MATH_TOOLS_POLY_RAT_13_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T*, const U*, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]) / static_cast<V>(b[0]); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<2>*) +{ + if(x <= 1) + return static_cast<V>((a[1] * x + a[0]) / (b[1] * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((a[0] * z + a[1]) / (b[0] * z + b[1])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<3>*) +{ + if(x <= 1) + return static_cast<V>(((a[2] * x + a[1]) * x + a[0]) / ((b[2] * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((a[0] * z + a[1]) * z + a[2]) / ((b[0] * z + b[1]) * z + b[2])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<4>*) +{ + if(x <= 1) + return static_cast<V>((((a[3] * x + a[2]) * x + a[1]) * x + a[0]) / (((b[3] * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) / (((b[0] * z + b[1]) * z + b[2]) * z + b[3])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<5>*) +{ + if(x <= 1) + return static_cast<V>(((((a[4] * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((b[4] * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) / ((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<6>*) +{ + if(x <= 1) + return static_cast<V>((((((a[5] * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / (((((b[5] * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) / (((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<7>*) +{ + if(x <= 1) + return static_cast<V>(((((((a[6] * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((((b[6] * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) / ((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<8>*) +{ + if(x <= 1) + return static_cast<V>((((((((a[7] * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / (((((((b[7] * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) / (((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<9>*) +{ + if(x <= 1) + return static_cast<V>(((((((((a[8] * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((((((b[8] * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) / ((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<10>*) +{ + if(x <= 1) + return static_cast<V>((((((((((a[9] * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / (((((((((b[9] * x + b[8]) * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) * z + a[9]) / (((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8]) * z + b[9])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<11>*) +{ + if(x <= 1) + return static_cast<V>(((((((((((a[10] * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((((((((b[10] * x + b[9]) * x + b[8]) * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) * z + a[9]) * z + a[10]) / ((((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8]) * z + b[9]) * z + b[10])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<12>*) +{ + if(x <= 1) + return static_cast<V>((((((((((((a[11] * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / (((((((((((b[11] * x + b[10]) * x + b[9]) * x + b[8]) * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) * z + a[9]) * z + a[10]) * z + a[11]) / (((((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8]) * z + b[9]) * z + b[10]) * z + b[11])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<13>*) +{ + if(x <= 1) + return static_cast<V>(((((((((((((a[12] * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((((((((((b[12] * x + b[11]) * x + b[10]) * x + b[9]) * x + b[8]) * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) * z + a[9]) * z + a[10]) * z + a[11]) * z + a[12]) / ((((((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8]) * z + b[9]) * z + b[10]) * z + b[11]) * z + b[12])); + } +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/rational_horner1_14.hpp b/Utilities/BGL/boost/math/tools/detail/rational_horner1_14.hpp new file mode 100644 index 0000000000000000000000000000000000000000..59d443832d7c883a08a60e5f28228036b741d66e --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/rational_horner1_14.hpp @@ -0,0 +1,186 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_RAT_14_HPP +#define BOOST_MATH_TOOLS_POLY_RAT_14_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T*, const U*, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]) / static_cast<V>(b[0]); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<2>*) +{ + if(x <= 1) + return static_cast<V>((a[1] * x + a[0]) / (b[1] * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((a[0] * z + a[1]) / (b[0] * z + b[1])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<3>*) +{ + if(x <= 1) + return static_cast<V>(((a[2] * x + a[1]) * x + a[0]) / ((b[2] * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((a[0] * z + a[1]) * z + a[2]) / ((b[0] * z + b[1]) * z + b[2])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<4>*) +{ + if(x <= 1) + return static_cast<V>((((a[3] * x + a[2]) * x + a[1]) * x + a[0]) / (((b[3] * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) / (((b[0] * z + b[1]) * z + b[2]) * z + b[3])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<5>*) +{ + if(x <= 1) + return static_cast<V>(((((a[4] * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((b[4] * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) / ((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<6>*) +{ + if(x <= 1) + return static_cast<V>((((((a[5] * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / (((((b[5] * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) / (((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<7>*) +{ + if(x <= 1) + return static_cast<V>(((((((a[6] * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((((b[6] * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) / ((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<8>*) +{ + if(x <= 1) + return static_cast<V>((((((((a[7] * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / (((((((b[7] * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) / (((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<9>*) +{ + if(x <= 1) + return static_cast<V>(((((((((a[8] * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((((((b[8] * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) / ((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<10>*) +{ + if(x <= 1) + return static_cast<V>((((((((((a[9] * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / (((((((((b[9] * x + b[8]) * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) * z + a[9]) / (((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8]) * z + b[9])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<11>*) +{ + if(x <= 1) + return static_cast<V>(((((((((((a[10] * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((((((((b[10] * x + b[9]) * x + b[8]) * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) * z + a[9]) * z + a[10]) / ((((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8]) * z + b[9]) * z + b[10])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<12>*) +{ + if(x <= 1) + return static_cast<V>((((((((((((a[11] * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / (((((((((((b[11] * x + b[10]) * x + b[9]) * x + b[8]) * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) * z + a[9]) * z + a[10]) * z + a[11]) / (((((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8]) * z + b[9]) * z + b[10]) * z + b[11])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<13>*) +{ + if(x <= 1) + return static_cast<V>(((((((((((((a[12] * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((((((((((b[12] * x + b[11]) * x + b[10]) * x + b[9]) * x + b[8]) * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) * z + a[9]) * z + a[10]) * z + a[11]) * z + a[12]) / ((((((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8]) * z + b[9]) * z + b[10]) * z + b[11]) * z + b[12])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<14>*) +{ + if(x <= 1) + return static_cast<V>((((((((((((((a[13] * x + a[12]) * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / (((((((((((((b[13] * x + b[12]) * x + b[11]) * x + b[10]) * x + b[9]) * x + b[8]) * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((((((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) * z + a[9]) * z + a[10]) * z + a[11]) * z + a[12]) * z + a[13]) / (((((((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8]) * z + b[9]) * z + b[10]) * z + b[11]) * z + b[12]) * z + b[13])); + } +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/rational_horner1_15.hpp b/Utilities/BGL/boost/math/tools/detail/rational_horner1_15.hpp new file mode 100644 index 0000000000000000000000000000000000000000..80e09660217c91beb3cea8e1b6a05cd47541e8ff --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/rational_horner1_15.hpp @@ -0,0 +1,198 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_RAT_15_HPP +#define BOOST_MATH_TOOLS_POLY_RAT_15_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T*, const U*, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]) / static_cast<V>(b[0]); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<2>*) +{ + if(x <= 1) + return static_cast<V>((a[1] * x + a[0]) / (b[1] * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((a[0] * z + a[1]) / (b[0] * z + b[1])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<3>*) +{ + if(x <= 1) + return static_cast<V>(((a[2] * x + a[1]) * x + a[0]) / ((b[2] * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((a[0] * z + a[1]) * z + a[2]) / ((b[0] * z + b[1]) * z + b[2])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<4>*) +{ + if(x <= 1) + return static_cast<V>((((a[3] * x + a[2]) * x + a[1]) * x + a[0]) / (((b[3] * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) / (((b[0] * z + b[1]) * z + b[2]) * z + b[3])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<5>*) +{ + if(x <= 1) + return static_cast<V>(((((a[4] * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((b[4] * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) / ((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<6>*) +{ + if(x <= 1) + return static_cast<V>((((((a[5] * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / (((((b[5] * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) / (((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<7>*) +{ + if(x <= 1) + return static_cast<V>(((((((a[6] * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((((b[6] * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) / ((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<8>*) +{ + if(x <= 1) + return static_cast<V>((((((((a[7] * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / (((((((b[7] * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) / (((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<9>*) +{ + if(x <= 1) + return static_cast<V>(((((((((a[8] * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((((((b[8] * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) / ((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<10>*) +{ + if(x <= 1) + return static_cast<V>((((((((((a[9] * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / (((((((((b[9] * x + b[8]) * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) * z + a[9]) / (((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8]) * z + b[9])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<11>*) +{ + if(x <= 1) + return static_cast<V>(((((((((((a[10] * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((((((((b[10] * x + b[9]) * x + b[8]) * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) * z + a[9]) * z + a[10]) / ((((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8]) * z + b[9]) * z + b[10])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<12>*) +{ + if(x <= 1) + return static_cast<V>((((((((((((a[11] * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / (((((((((((b[11] * x + b[10]) * x + b[9]) * x + b[8]) * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) * z + a[9]) * z + a[10]) * z + a[11]) / (((((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8]) * z + b[9]) * z + b[10]) * z + b[11])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<13>*) +{ + if(x <= 1) + return static_cast<V>(((((((((((((a[12] * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((((((((((b[12] * x + b[11]) * x + b[10]) * x + b[9]) * x + b[8]) * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) * z + a[9]) * z + a[10]) * z + a[11]) * z + a[12]) / ((((((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8]) * z + b[9]) * z + b[10]) * z + b[11]) * z + b[12])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<14>*) +{ + if(x <= 1) + return static_cast<V>((((((((((((((a[13] * x + a[12]) * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / (((((((((((((b[13] * x + b[12]) * x + b[11]) * x + b[10]) * x + b[9]) * x + b[8]) * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((((((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) * z + a[9]) * z + a[10]) * z + a[11]) * z + a[12]) * z + a[13]) / (((((((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8]) * z + b[9]) * z + b[10]) * z + b[11]) * z + b[12]) * z + b[13])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<15>*) +{ + if(x <= 1) + return static_cast<V>(((((((((((((((a[14] * x + a[13]) * x + a[12]) * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((((((((((((b[14] * x + b[13]) * x + b[12]) * x + b[11]) * x + b[10]) * x + b[9]) * x + b[8]) * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((((((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) * z + a[9]) * z + a[10]) * z + a[11]) * z + a[12]) * z + a[13]) * z + a[14]) / ((((((((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8]) * z + b[9]) * z + b[10]) * z + b[11]) * z + b[12]) * z + b[13]) * z + b[14])); + } +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/rational_horner1_16.hpp b/Utilities/BGL/boost/math/tools/detail/rational_horner1_16.hpp new file mode 100644 index 0000000000000000000000000000000000000000..def345fdf9878c69ff95f04c20b5e8c47f0f5fba --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/rational_horner1_16.hpp @@ -0,0 +1,210 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_RAT_16_HPP +#define BOOST_MATH_TOOLS_POLY_RAT_16_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T*, const U*, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]) / static_cast<V>(b[0]); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<2>*) +{ + if(x <= 1) + return static_cast<V>((a[1] * x + a[0]) / (b[1] * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((a[0] * z + a[1]) / (b[0] * z + b[1])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<3>*) +{ + if(x <= 1) + return static_cast<V>(((a[2] * x + a[1]) * x + a[0]) / ((b[2] * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((a[0] * z + a[1]) * z + a[2]) / ((b[0] * z + b[1]) * z + b[2])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<4>*) +{ + if(x <= 1) + return static_cast<V>((((a[3] * x + a[2]) * x + a[1]) * x + a[0]) / (((b[3] * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) / (((b[0] * z + b[1]) * z + b[2]) * z + b[3])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<5>*) +{ + if(x <= 1) + return static_cast<V>(((((a[4] * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((b[4] * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) / ((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<6>*) +{ + if(x <= 1) + return static_cast<V>((((((a[5] * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / (((((b[5] * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) / (((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<7>*) +{ + if(x <= 1) + return static_cast<V>(((((((a[6] * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((((b[6] * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) / ((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<8>*) +{ + if(x <= 1) + return static_cast<V>((((((((a[7] * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / (((((((b[7] * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) / (((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<9>*) +{ + if(x <= 1) + return static_cast<V>(((((((((a[8] * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((((((b[8] * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) / ((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<10>*) +{ + if(x <= 1) + return static_cast<V>((((((((((a[9] * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / (((((((((b[9] * x + b[8]) * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) * z + a[9]) / (((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8]) * z + b[9])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<11>*) +{ + if(x <= 1) + return static_cast<V>(((((((((((a[10] * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((((((((b[10] * x + b[9]) * x + b[8]) * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) * z + a[9]) * z + a[10]) / ((((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8]) * z + b[9]) * z + b[10])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<12>*) +{ + if(x <= 1) + return static_cast<V>((((((((((((a[11] * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / (((((((((((b[11] * x + b[10]) * x + b[9]) * x + b[8]) * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) * z + a[9]) * z + a[10]) * z + a[11]) / (((((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8]) * z + b[9]) * z + b[10]) * z + b[11])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<13>*) +{ + if(x <= 1) + return static_cast<V>(((((((((((((a[12] * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((((((((((b[12] * x + b[11]) * x + b[10]) * x + b[9]) * x + b[8]) * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) * z + a[9]) * z + a[10]) * z + a[11]) * z + a[12]) / ((((((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8]) * z + b[9]) * z + b[10]) * z + b[11]) * z + b[12])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<14>*) +{ + if(x <= 1) + return static_cast<V>((((((((((((((a[13] * x + a[12]) * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / (((((((((((((b[13] * x + b[12]) * x + b[11]) * x + b[10]) * x + b[9]) * x + b[8]) * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((((((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) * z + a[9]) * z + a[10]) * z + a[11]) * z + a[12]) * z + a[13]) / (((((((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8]) * z + b[9]) * z + b[10]) * z + b[11]) * z + b[12]) * z + b[13])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<15>*) +{ + if(x <= 1) + return static_cast<V>(((((((((((((((a[14] * x + a[13]) * x + a[12]) * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((((((((((((b[14] * x + b[13]) * x + b[12]) * x + b[11]) * x + b[10]) * x + b[9]) * x + b[8]) * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((((((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) * z + a[9]) * z + a[10]) * z + a[11]) * z + a[12]) * z + a[13]) * z + a[14]) / ((((((((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8]) * z + b[9]) * z + b[10]) * z + b[11]) * z + b[12]) * z + b[13]) * z + b[14])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<16>*) +{ + if(x <= 1) + return static_cast<V>((((((((((((((((a[15] * x + a[14]) * x + a[13]) * x + a[12]) * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / (((((((((((((((b[15] * x + b[14]) * x + b[13]) * x + b[12]) * x + b[11]) * x + b[10]) * x + b[9]) * x + b[8]) * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((((((((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) * z + a[9]) * z + a[10]) * z + a[11]) * z + a[12]) * z + a[13]) * z + a[14]) * z + a[15]) / (((((((((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8]) * z + b[9]) * z + b[10]) * z + b[11]) * z + b[12]) * z + b[13]) * z + b[14]) * z + b[15])); + } +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/rational_horner1_17.hpp b/Utilities/BGL/boost/math/tools/detail/rational_horner1_17.hpp new file mode 100644 index 0000000000000000000000000000000000000000..7e6c277652dd49d1eb057c7f68f605307711deae --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/rational_horner1_17.hpp @@ -0,0 +1,222 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_RAT_17_HPP +#define BOOST_MATH_TOOLS_POLY_RAT_17_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T*, const U*, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]) / static_cast<V>(b[0]); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<2>*) +{ + if(x <= 1) + return static_cast<V>((a[1] * x + a[0]) / (b[1] * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((a[0] * z + a[1]) / (b[0] * z + b[1])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<3>*) +{ + if(x <= 1) + return static_cast<V>(((a[2] * x + a[1]) * x + a[0]) / ((b[2] * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((a[0] * z + a[1]) * z + a[2]) / ((b[0] * z + b[1]) * z + b[2])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<4>*) +{ + if(x <= 1) + return static_cast<V>((((a[3] * x + a[2]) * x + a[1]) * x + a[0]) / (((b[3] * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) / (((b[0] * z + b[1]) * z + b[2]) * z + b[3])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<5>*) +{ + if(x <= 1) + return static_cast<V>(((((a[4] * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((b[4] * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) / ((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<6>*) +{ + if(x <= 1) + return static_cast<V>((((((a[5] * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / (((((b[5] * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) / (((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<7>*) +{ + if(x <= 1) + return static_cast<V>(((((((a[6] * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((((b[6] * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) / ((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<8>*) +{ + if(x <= 1) + return static_cast<V>((((((((a[7] * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / (((((((b[7] * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) / (((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<9>*) +{ + if(x <= 1) + return static_cast<V>(((((((((a[8] * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((((((b[8] * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) / ((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<10>*) +{ + if(x <= 1) + return static_cast<V>((((((((((a[9] * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / (((((((((b[9] * x + b[8]) * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) * z + a[9]) / (((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8]) * z + b[9])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<11>*) +{ + if(x <= 1) + return static_cast<V>(((((((((((a[10] * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((((((((b[10] * x + b[9]) * x + b[8]) * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) * z + a[9]) * z + a[10]) / ((((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8]) * z + b[9]) * z + b[10])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<12>*) +{ + if(x <= 1) + return static_cast<V>((((((((((((a[11] * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / (((((((((((b[11] * x + b[10]) * x + b[9]) * x + b[8]) * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) * z + a[9]) * z + a[10]) * z + a[11]) / (((((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8]) * z + b[9]) * z + b[10]) * z + b[11])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<13>*) +{ + if(x <= 1) + return static_cast<V>(((((((((((((a[12] * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((((((((((b[12] * x + b[11]) * x + b[10]) * x + b[9]) * x + b[8]) * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) * z + a[9]) * z + a[10]) * z + a[11]) * z + a[12]) / ((((((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8]) * z + b[9]) * z + b[10]) * z + b[11]) * z + b[12])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<14>*) +{ + if(x <= 1) + return static_cast<V>((((((((((((((a[13] * x + a[12]) * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / (((((((((((((b[13] * x + b[12]) * x + b[11]) * x + b[10]) * x + b[9]) * x + b[8]) * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((((((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) * z + a[9]) * z + a[10]) * z + a[11]) * z + a[12]) * z + a[13]) / (((((((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8]) * z + b[9]) * z + b[10]) * z + b[11]) * z + b[12]) * z + b[13])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<15>*) +{ + if(x <= 1) + return static_cast<V>(((((((((((((((a[14] * x + a[13]) * x + a[12]) * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((((((((((((b[14] * x + b[13]) * x + b[12]) * x + b[11]) * x + b[10]) * x + b[9]) * x + b[8]) * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((((((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) * z + a[9]) * z + a[10]) * z + a[11]) * z + a[12]) * z + a[13]) * z + a[14]) / ((((((((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8]) * z + b[9]) * z + b[10]) * z + b[11]) * z + b[12]) * z + b[13]) * z + b[14])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<16>*) +{ + if(x <= 1) + return static_cast<V>((((((((((((((((a[15] * x + a[14]) * x + a[13]) * x + a[12]) * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / (((((((((((((((b[15] * x + b[14]) * x + b[13]) * x + b[12]) * x + b[11]) * x + b[10]) * x + b[9]) * x + b[8]) * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((((((((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) * z + a[9]) * z + a[10]) * z + a[11]) * z + a[12]) * z + a[13]) * z + a[14]) * z + a[15]) / (((((((((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8]) * z + b[9]) * z + b[10]) * z + b[11]) * z + b[12]) * z + b[13]) * z + b[14]) * z + b[15])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<17>*) +{ + if(x <= 1) + return static_cast<V>(((((((((((((((((a[16] * x + a[15]) * x + a[14]) * x + a[13]) * x + a[12]) * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((((((((((((((b[16] * x + b[15]) * x + b[14]) * x + b[13]) * x + b[12]) * x + b[11]) * x + b[10]) * x + b[9]) * x + b[8]) * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((((((((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) * z + a[9]) * z + a[10]) * z + a[11]) * z + a[12]) * z + a[13]) * z + a[14]) * z + a[15]) * z + a[16]) / ((((((((((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8]) * z + b[9]) * z + b[10]) * z + b[11]) * z + b[12]) * z + b[13]) * z + b[14]) * z + b[15]) * z + b[16])); + } +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/rational_horner1_18.hpp b/Utilities/BGL/boost/math/tools/detail/rational_horner1_18.hpp new file mode 100644 index 0000000000000000000000000000000000000000..34cfaadbf02110ce72dfb4d83038348a47e7b326 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/rational_horner1_18.hpp @@ -0,0 +1,234 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_RAT_18_HPP +#define BOOST_MATH_TOOLS_POLY_RAT_18_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T*, const U*, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]) / static_cast<V>(b[0]); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<2>*) +{ + if(x <= 1) + return static_cast<V>((a[1] * x + a[0]) / (b[1] * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((a[0] * z + a[1]) / (b[0] * z + b[1])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<3>*) +{ + if(x <= 1) + return static_cast<V>(((a[2] * x + a[1]) * x + a[0]) / ((b[2] * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((a[0] * z + a[1]) * z + a[2]) / ((b[0] * z + b[1]) * z + b[2])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<4>*) +{ + if(x <= 1) + return static_cast<V>((((a[3] * x + a[2]) * x + a[1]) * x + a[0]) / (((b[3] * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) / (((b[0] * z + b[1]) * z + b[2]) * z + b[3])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<5>*) +{ + if(x <= 1) + return static_cast<V>(((((a[4] * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((b[4] * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) / ((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<6>*) +{ + if(x <= 1) + return static_cast<V>((((((a[5] * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / (((((b[5] * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) / (((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<7>*) +{ + if(x <= 1) + return static_cast<V>(((((((a[6] * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((((b[6] * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) / ((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<8>*) +{ + if(x <= 1) + return static_cast<V>((((((((a[7] * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / (((((((b[7] * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) / (((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<9>*) +{ + if(x <= 1) + return static_cast<V>(((((((((a[8] * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((((((b[8] * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) / ((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<10>*) +{ + if(x <= 1) + return static_cast<V>((((((((((a[9] * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / (((((((((b[9] * x + b[8]) * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) * z + a[9]) / (((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8]) * z + b[9])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<11>*) +{ + if(x <= 1) + return static_cast<V>(((((((((((a[10] * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((((((((b[10] * x + b[9]) * x + b[8]) * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) * z + a[9]) * z + a[10]) / ((((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8]) * z + b[9]) * z + b[10])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<12>*) +{ + if(x <= 1) + return static_cast<V>((((((((((((a[11] * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / (((((((((((b[11] * x + b[10]) * x + b[9]) * x + b[8]) * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) * z + a[9]) * z + a[10]) * z + a[11]) / (((((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8]) * z + b[9]) * z + b[10]) * z + b[11])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<13>*) +{ + if(x <= 1) + return static_cast<V>(((((((((((((a[12] * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((((((((((b[12] * x + b[11]) * x + b[10]) * x + b[9]) * x + b[8]) * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) * z + a[9]) * z + a[10]) * z + a[11]) * z + a[12]) / ((((((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8]) * z + b[9]) * z + b[10]) * z + b[11]) * z + b[12])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<14>*) +{ + if(x <= 1) + return static_cast<V>((((((((((((((a[13] * x + a[12]) * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / (((((((((((((b[13] * x + b[12]) * x + b[11]) * x + b[10]) * x + b[9]) * x + b[8]) * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((((((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) * z + a[9]) * z + a[10]) * z + a[11]) * z + a[12]) * z + a[13]) / (((((((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8]) * z + b[9]) * z + b[10]) * z + b[11]) * z + b[12]) * z + b[13])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<15>*) +{ + if(x <= 1) + return static_cast<V>(((((((((((((((a[14] * x + a[13]) * x + a[12]) * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((((((((((((b[14] * x + b[13]) * x + b[12]) * x + b[11]) * x + b[10]) * x + b[9]) * x + b[8]) * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((((((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) * z + a[9]) * z + a[10]) * z + a[11]) * z + a[12]) * z + a[13]) * z + a[14]) / ((((((((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8]) * z + b[9]) * z + b[10]) * z + b[11]) * z + b[12]) * z + b[13]) * z + b[14])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<16>*) +{ + if(x <= 1) + return static_cast<V>((((((((((((((((a[15] * x + a[14]) * x + a[13]) * x + a[12]) * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / (((((((((((((((b[15] * x + b[14]) * x + b[13]) * x + b[12]) * x + b[11]) * x + b[10]) * x + b[9]) * x + b[8]) * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((((((((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) * z + a[9]) * z + a[10]) * z + a[11]) * z + a[12]) * z + a[13]) * z + a[14]) * z + a[15]) / (((((((((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8]) * z + b[9]) * z + b[10]) * z + b[11]) * z + b[12]) * z + b[13]) * z + b[14]) * z + b[15])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<17>*) +{ + if(x <= 1) + return static_cast<V>(((((((((((((((((a[16] * x + a[15]) * x + a[14]) * x + a[13]) * x + a[12]) * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((((((((((((((b[16] * x + b[15]) * x + b[14]) * x + b[13]) * x + b[12]) * x + b[11]) * x + b[10]) * x + b[9]) * x + b[8]) * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((((((((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) * z + a[9]) * z + a[10]) * z + a[11]) * z + a[12]) * z + a[13]) * z + a[14]) * z + a[15]) * z + a[16]) / ((((((((((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8]) * z + b[9]) * z + b[10]) * z + b[11]) * z + b[12]) * z + b[13]) * z + b[14]) * z + b[15]) * z + b[16])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<18>*) +{ + if(x <= 1) + return static_cast<V>((((((((((((((((((a[17] * x + a[16]) * x + a[15]) * x + a[14]) * x + a[13]) * x + a[12]) * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / (((((((((((((((((b[17] * x + b[16]) * x + b[15]) * x + b[14]) * x + b[13]) * x + b[12]) * x + b[11]) * x + b[10]) * x + b[9]) * x + b[8]) * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((((((((((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) * z + a[9]) * z + a[10]) * z + a[11]) * z + a[12]) * z + a[13]) * z + a[14]) * z + a[15]) * z + a[16]) * z + a[17]) / (((((((((((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8]) * z + b[9]) * z + b[10]) * z + b[11]) * z + b[12]) * z + b[13]) * z + b[14]) * z + b[15]) * z + b[16]) * z + b[17])); + } +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/rational_horner1_19.hpp b/Utilities/BGL/boost/math/tools/detail/rational_horner1_19.hpp new file mode 100644 index 0000000000000000000000000000000000000000..bcbbd626d2c5a7939ea08d03176fa522aa546549 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/rational_horner1_19.hpp @@ -0,0 +1,246 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_RAT_19_HPP +#define BOOST_MATH_TOOLS_POLY_RAT_19_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T*, const U*, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]) / static_cast<V>(b[0]); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<2>*) +{ + if(x <= 1) + return static_cast<V>((a[1] * x + a[0]) / (b[1] * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((a[0] * z + a[1]) / (b[0] * z + b[1])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<3>*) +{ + if(x <= 1) + return static_cast<V>(((a[2] * x + a[1]) * x + a[0]) / ((b[2] * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((a[0] * z + a[1]) * z + a[2]) / ((b[0] * z + b[1]) * z + b[2])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<4>*) +{ + if(x <= 1) + return static_cast<V>((((a[3] * x + a[2]) * x + a[1]) * x + a[0]) / (((b[3] * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) / (((b[0] * z + b[1]) * z + b[2]) * z + b[3])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<5>*) +{ + if(x <= 1) + return static_cast<V>(((((a[4] * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((b[4] * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) / ((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<6>*) +{ + if(x <= 1) + return static_cast<V>((((((a[5] * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / (((((b[5] * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) / (((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<7>*) +{ + if(x <= 1) + return static_cast<V>(((((((a[6] * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((((b[6] * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) / ((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<8>*) +{ + if(x <= 1) + return static_cast<V>((((((((a[7] * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / (((((((b[7] * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) / (((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<9>*) +{ + if(x <= 1) + return static_cast<V>(((((((((a[8] * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((((((b[8] * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) / ((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<10>*) +{ + if(x <= 1) + return static_cast<V>((((((((((a[9] * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / (((((((((b[9] * x + b[8]) * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) * z + a[9]) / (((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8]) * z + b[9])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<11>*) +{ + if(x <= 1) + return static_cast<V>(((((((((((a[10] * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((((((((b[10] * x + b[9]) * x + b[8]) * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) * z + a[9]) * z + a[10]) / ((((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8]) * z + b[9]) * z + b[10])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<12>*) +{ + if(x <= 1) + return static_cast<V>((((((((((((a[11] * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / (((((((((((b[11] * x + b[10]) * x + b[9]) * x + b[8]) * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) * z + a[9]) * z + a[10]) * z + a[11]) / (((((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8]) * z + b[9]) * z + b[10]) * z + b[11])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<13>*) +{ + if(x <= 1) + return static_cast<V>(((((((((((((a[12] * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((((((((((b[12] * x + b[11]) * x + b[10]) * x + b[9]) * x + b[8]) * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) * z + a[9]) * z + a[10]) * z + a[11]) * z + a[12]) / ((((((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8]) * z + b[9]) * z + b[10]) * z + b[11]) * z + b[12])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<14>*) +{ + if(x <= 1) + return static_cast<V>((((((((((((((a[13] * x + a[12]) * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / (((((((((((((b[13] * x + b[12]) * x + b[11]) * x + b[10]) * x + b[9]) * x + b[8]) * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((((((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) * z + a[9]) * z + a[10]) * z + a[11]) * z + a[12]) * z + a[13]) / (((((((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8]) * z + b[9]) * z + b[10]) * z + b[11]) * z + b[12]) * z + b[13])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<15>*) +{ + if(x <= 1) + return static_cast<V>(((((((((((((((a[14] * x + a[13]) * x + a[12]) * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((((((((((((b[14] * x + b[13]) * x + b[12]) * x + b[11]) * x + b[10]) * x + b[9]) * x + b[8]) * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((((((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) * z + a[9]) * z + a[10]) * z + a[11]) * z + a[12]) * z + a[13]) * z + a[14]) / ((((((((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8]) * z + b[9]) * z + b[10]) * z + b[11]) * z + b[12]) * z + b[13]) * z + b[14])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<16>*) +{ + if(x <= 1) + return static_cast<V>((((((((((((((((a[15] * x + a[14]) * x + a[13]) * x + a[12]) * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / (((((((((((((((b[15] * x + b[14]) * x + b[13]) * x + b[12]) * x + b[11]) * x + b[10]) * x + b[9]) * x + b[8]) * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((((((((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) * z + a[9]) * z + a[10]) * z + a[11]) * z + a[12]) * z + a[13]) * z + a[14]) * z + a[15]) / (((((((((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8]) * z + b[9]) * z + b[10]) * z + b[11]) * z + b[12]) * z + b[13]) * z + b[14]) * z + b[15])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<17>*) +{ + if(x <= 1) + return static_cast<V>(((((((((((((((((a[16] * x + a[15]) * x + a[14]) * x + a[13]) * x + a[12]) * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((((((((((((((b[16] * x + b[15]) * x + b[14]) * x + b[13]) * x + b[12]) * x + b[11]) * x + b[10]) * x + b[9]) * x + b[8]) * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((((((((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) * z + a[9]) * z + a[10]) * z + a[11]) * z + a[12]) * z + a[13]) * z + a[14]) * z + a[15]) * z + a[16]) / ((((((((((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8]) * z + b[9]) * z + b[10]) * z + b[11]) * z + b[12]) * z + b[13]) * z + b[14]) * z + b[15]) * z + b[16])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<18>*) +{ + if(x <= 1) + return static_cast<V>((((((((((((((((((a[17] * x + a[16]) * x + a[15]) * x + a[14]) * x + a[13]) * x + a[12]) * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / (((((((((((((((((b[17] * x + b[16]) * x + b[15]) * x + b[14]) * x + b[13]) * x + b[12]) * x + b[11]) * x + b[10]) * x + b[9]) * x + b[8]) * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((((((((((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) * z + a[9]) * z + a[10]) * z + a[11]) * z + a[12]) * z + a[13]) * z + a[14]) * z + a[15]) * z + a[16]) * z + a[17]) / (((((((((((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8]) * z + b[9]) * z + b[10]) * z + b[11]) * z + b[12]) * z + b[13]) * z + b[14]) * z + b[15]) * z + b[16]) * z + b[17])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<19>*) +{ + if(x <= 1) + return static_cast<V>(((((((((((((((((((a[18] * x + a[17]) * x + a[16]) * x + a[15]) * x + a[14]) * x + a[13]) * x + a[12]) * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((((((((((((((((b[18] * x + b[17]) * x + b[16]) * x + b[15]) * x + b[14]) * x + b[13]) * x + b[12]) * x + b[11]) * x + b[10]) * x + b[9]) * x + b[8]) * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((((((((((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) * z + a[9]) * z + a[10]) * z + a[11]) * z + a[12]) * z + a[13]) * z + a[14]) * z + a[15]) * z + a[16]) * z + a[17]) * z + a[18]) / ((((((((((((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8]) * z + b[9]) * z + b[10]) * z + b[11]) * z + b[12]) * z + b[13]) * z + b[14]) * z + b[15]) * z + b[16]) * z + b[17]) * z + b[18])); + } +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/rational_horner1_2.hpp b/Utilities/BGL/boost/math/tools/detail/rational_horner1_2.hpp new file mode 100644 index 0000000000000000000000000000000000000000..580e3b1f9c881e0ab93a3a47ca264d203993c9ae --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/rational_horner1_2.hpp @@ -0,0 +1,42 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_RAT_2_HPP +#define BOOST_MATH_TOOLS_POLY_RAT_2_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T*, const U*, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]) / static_cast<V>(b[0]); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<2>*) +{ + if(x <= 1) + return static_cast<V>((a[1] * x + a[0]) / (b[1] * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((a[0] * z + a[1]) / (b[0] * z + b[1])); + } +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/rational_horner1_20.hpp b/Utilities/BGL/boost/math/tools/detail/rational_horner1_20.hpp new file mode 100644 index 0000000000000000000000000000000000000000..e3a43811d0a84ee3062f6ea9d803b07d1b6e1ed7 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/rational_horner1_20.hpp @@ -0,0 +1,258 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_RAT_20_HPP +#define BOOST_MATH_TOOLS_POLY_RAT_20_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T*, const U*, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]) / static_cast<V>(b[0]); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<2>*) +{ + if(x <= 1) + return static_cast<V>((a[1] * x + a[0]) / (b[1] * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((a[0] * z + a[1]) / (b[0] * z + b[1])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<3>*) +{ + if(x <= 1) + return static_cast<V>(((a[2] * x + a[1]) * x + a[0]) / ((b[2] * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((a[0] * z + a[1]) * z + a[2]) / ((b[0] * z + b[1]) * z + b[2])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<4>*) +{ + if(x <= 1) + return static_cast<V>((((a[3] * x + a[2]) * x + a[1]) * x + a[0]) / (((b[3] * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) / (((b[0] * z + b[1]) * z + b[2]) * z + b[3])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<5>*) +{ + if(x <= 1) + return static_cast<V>(((((a[4] * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((b[4] * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) / ((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<6>*) +{ + if(x <= 1) + return static_cast<V>((((((a[5] * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / (((((b[5] * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) / (((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<7>*) +{ + if(x <= 1) + return static_cast<V>(((((((a[6] * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((((b[6] * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) / ((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<8>*) +{ + if(x <= 1) + return static_cast<V>((((((((a[7] * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / (((((((b[7] * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) / (((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<9>*) +{ + if(x <= 1) + return static_cast<V>(((((((((a[8] * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((((((b[8] * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) / ((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<10>*) +{ + if(x <= 1) + return static_cast<V>((((((((((a[9] * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / (((((((((b[9] * x + b[8]) * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) * z + a[9]) / (((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8]) * z + b[9])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<11>*) +{ + if(x <= 1) + return static_cast<V>(((((((((((a[10] * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((((((((b[10] * x + b[9]) * x + b[8]) * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) * z + a[9]) * z + a[10]) / ((((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8]) * z + b[9]) * z + b[10])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<12>*) +{ + if(x <= 1) + return static_cast<V>((((((((((((a[11] * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / (((((((((((b[11] * x + b[10]) * x + b[9]) * x + b[8]) * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) * z + a[9]) * z + a[10]) * z + a[11]) / (((((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8]) * z + b[9]) * z + b[10]) * z + b[11])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<13>*) +{ + if(x <= 1) + return static_cast<V>(((((((((((((a[12] * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((((((((((b[12] * x + b[11]) * x + b[10]) * x + b[9]) * x + b[8]) * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) * z + a[9]) * z + a[10]) * z + a[11]) * z + a[12]) / ((((((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8]) * z + b[9]) * z + b[10]) * z + b[11]) * z + b[12])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<14>*) +{ + if(x <= 1) + return static_cast<V>((((((((((((((a[13] * x + a[12]) * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / (((((((((((((b[13] * x + b[12]) * x + b[11]) * x + b[10]) * x + b[9]) * x + b[8]) * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((((((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) * z + a[9]) * z + a[10]) * z + a[11]) * z + a[12]) * z + a[13]) / (((((((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8]) * z + b[9]) * z + b[10]) * z + b[11]) * z + b[12]) * z + b[13])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<15>*) +{ + if(x <= 1) + return static_cast<V>(((((((((((((((a[14] * x + a[13]) * x + a[12]) * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((((((((((((b[14] * x + b[13]) * x + b[12]) * x + b[11]) * x + b[10]) * x + b[9]) * x + b[8]) * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((((((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) * z + a[9]) * z + a[10]) * z + a[11]) * z + a[12]) * z + a[13]) * z + a[14]) / ((((((((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8]) * z + b[9]) * z + b[10]) * z + b[11]) * z + b[12]) * z + b[13]) * z + b[14])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<16>*) +{ + if(x <= 1) + return static_cast<V>((((((((((((((((a[15] * x + a[14]) * x + a[13]) * x + a[12]) * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / (((((((((((((((b[15] * x + b[14]) * x + b[13]) * x + b[12]) * x + b[11]) * x + b[10]) * x + b[9]) * x + b[8]) * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((((((((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) * z + a[9]) * z + a[10]) * z + a[11]) * z + a[12]) * z + a[13]) * z + a[14]) * z + a[15]) / (((((((((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8]) * z + b[9]) * z + b[10]) * z + b[11]) * z + b[12]) * z + b[13]) * z + b[14]) * z + b[15])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<17>*) +{ + if(x <= 1) + return static_cast<V>(((((((((((((((((a[16] * x + a[15]) * x + a[14]) * x + a[13]) * x + a[12]) * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((((((((((((((b[16] * x + b[15]) * x + b[14]) * x + b[13]) * x + b[12]) * x + b[11]) * x + b[10]) * x + b[9]) * x + b[8]) * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((((((((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) * z + a[9]) * z + a[10]) * z + a[11]) * z + a[12]) * z + a[13]) * z + a[14]) * z + a[15]) * z + a[16]) / ((((((((((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8]) * z + b[9]) * z + b[10]) * z + b[11]) * z + b[12]) * z + b[13]) * z + b[14]) * z + b[15]) * z + b[16])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<18>*) +{ + if(x <= 1) + return static_cast<V>((((((((((((((((((a[17] * x + a[16]) * x + a[15]) * x + a[14]) * x + a[13]) * x + a[12]) * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / (((((((((((((((((b[17] * x + b[16]) * x + b[15]) * x + b[14]) * x + b[13]) * x + b[12]) * x + b[11]) * x + b[10]) * x + b[9]) * x + b[8]) * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((((((((((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) * z + a[9]) * z + a[10]) * z + a[11]) * z + a[12]) * z + a[13]) * z + a[14]) * z + a[15]) * z + a[16]) * z + a[17]) / (((((((((((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8]) * z + b[9]) * z + b[10]) * z + b[11]) * z + b[12]) * z + b[13]) * z + b[14]) * z + b[15]) * z + b[16]) * z + b[17])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<19>*) +{ + if(x <= 1) + return static_cast<V>(((((((((((((((((((a[18] * x + a[17]) * x + a[16]) * x + a[15]) * x + a[14]) * x + a[13]) * x + a[12]) * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((((((((((((((((b[18] * x + b[17]) * x + b[16]) * x + b[15]) * x + b[14]) * x + b[13]) * x + b[12]) * x + b[11]) * x + b[10]) * x + b[9]) * x + b[8]) * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((((((((((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) * z + a[9]) * z + a[10]) * z + a[11]) * z + a[12]) * z + a[13]) * z + a[14]) * z + a[15]) * z + a[16]) * z + a[17]) * z + a[18]) / ((((((((((((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8]) * z + b[9]) * z + b[10]) * z + b[11]) * z + b[12]) * z + b[13]) * z + b[14]) * z + b[15]) * z + b[16]) * z + b[17]) * z + b[18])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<20>*) +{ + if(x <= 1) + return static_cast<V>((((((((((((((((((((a[19] * x + a[18]) * x + a[17]) * x + a[16]) * x + a[15]) * x + a[14]) * x + a[13]) * x + a[12]) * x + a[11]) * x + a[10]) * x + a[9]) * x + a[8]) * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / (((((((((((((((((((b[19] * x + b[18]) * x + b[17]) * x + b[16]) * x + b[15]) * x + b[14]) * x + b[13]) * x + b[12]) * x + b[11]) * x + b[10]) * x + b[9]) * x + b[8]) * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((((((((((((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) * z + a[9]) * z + a[10]) * z + a[11]) * z + a[12]) * z + a[13]) * z + a[14]) * z + a[15]) * z + a[16]) * z + a[17]) * z + a[18]) * z + a[19]) / (((((((((((((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8]) * z + b[9]) * z + b[10]) * z + b[11]) * z + b[12]) * z + b[13]) * z + b[14]) * z + b[15]) * z + b[16]) * z + b[17]) * z + b[18]) * z + b[19])); + } +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/rational_horner1_3.hpp b/Utilities/BGL/boost/math/tools/detail/rational_horner1_3.hpp new file mode 100644 index 0000000000000000000000000000000000000000..02e9d4de98f0c7ef8f1cc579c48b8388c638542d --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/rational_horner1_3.hpp @@ -0,0 +1,54 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_RAT_3_HPP +#define BOOST_MATH_TOOLS_POLY_RAT_3_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T*, const U*, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]) / static_cast<V>(b[0]); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<2>*) +{ + if(x <= 1) + return static_cast<V>((a[1] * x + a[0]) / (b[1] * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((a[0] * z + a[1]) / (b[0] * z + b[1])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<3>*) +{ + if(x <= 1) + return static_cast<V>(((a[2] * x + a[1]) * x + a[0]) / ((b[2] * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((a[0] * z + a[1]) * z + a[2]) / ((b[0] * z + b[1]) * z + b[2])); + } +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/rational_horner1_4.hpp b/Utilities/BGL/boost/math/tools/detail/rational_horner1_4.hpp new file mode 100644 index 0000000000000000000000000000000000000000..398b0ceeaf904ee97cff246e2114593b96ba4a3c --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/rational_horner1_4.hpp @@ -0,0 +1,66 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_RAT_4_HPP +#define BOOST_MATH_TOOLS_POLY_RAT_4_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T*, const U*, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]) / static_cast<V>(b[0]); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<2>*) +{ + if(x <= 1) + return static_cast<V>((a[1] * x + a[0]) / (b[1] * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((a[0] * z + a[1]) / (b[0] * z + b[1])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<3>*) +{ + if(x <= 1) + return static_cast<V>(((a[2] * x + a[1]) * x + a[0]) / ((b[2] * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((a[0] * z + a[1]) * z + a[2]) / ((b[0] * z + b[1]) * z + b[2])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<4>*) +{ + if(x <= 1) + return static_cast<V>((((a[3] * x + a[2]) * x + a[1]) * x + a[0]) / (((b[3] * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) / (((b[0] * z + b[1]) * z + b[2]) * z + b[3])); + } +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/rational_horner1_5.hpp b/Utilities/BGL/boost/math/tools/detail/rational_horner1_5.hpp new file mode 100644 index 0000000000000000000000000000000000000000..5b52df6040980678080953bbdd4f93a5c089506e --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/rational_horner1_5.hpp @@ -0,0 +1,78 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_RAT_5_HPP +#define BOOST_MATH_TOOLS_POLY_RAT_5_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T*, const U*, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]) / static_cast<V>(b[0]); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<2>*) +{ + if(x <= 1) + return static_cast<V>((a[1] * x + a[0]) / (b[1] * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((a[0] * z + a[1]) / (b[0] * z + b[1])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<3>*) +{ + if(x <= 1) + return static_cast<V>(((a[2] * x + a[1]) * x + a[0]) / ((b[2] * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((a[0] * z + a[1]) * z + a[2]) / ((b[0] * z + b[1]) * z + b[2])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<4>*) +{ + if(x <= 1) + return static_cast<V>((((a[3] * x + a[2]) * x + a[1]) * x + a[0]) / (((b[3] * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) / (((b[0] * z + b[1]) * z + b[2]) * z + b[3])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<5>*) +{ + if(x <= 1) + return static_cast<V>(((((a[4] * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((b[4] * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) / ((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4])); + } +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/rational_horner1_6.hpp b/Utilities/BGL/boost/math/tools/detail/rational_horner1_6.hpp new file mode 100644 index 0000000000000000000000000000000000000000..4cb56ca7d899b1d298be6dd66d06611ec594dc57 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/rational_horner1_6.hpp @@ -0,0 +1,90 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_RAT_6_HPP +#define BOOST_MATH_TOOLS_POLY_RAT_6_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T*, const U*, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]) / static_cast<V>(b[0]); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<2>*) +{ + if(x <= 1) + return static_cast<V>((a[1] * x + a[0]) / (b[1] * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((a[0] * z + a[1]) / (b[0] * z + b[1])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<3>*) +{ + if(x <= 1) + return static_cast<V>(((a[2] * x + a[1]) * x + a[0]) / ((b[2] * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((a[0] * z + a[1]) * z + a[2]) / ((b[0] * z + b[1]) * z + b[2])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<4>*) +{ + if(x <= 1) + return static_cast<V>((((a[3] * x + a[2]) * x + a[1]) * x + a[0]) / (((b[3] * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) / (((b[0] * z + b[1]) * z + b[2]) * z + b[3])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<5>*) +{ + if(x <= 1) + return static_cast<V>(((((a[4] * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((b[4] * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) / ((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<6>*) +{ + if(x <= 1) + return static_cast<V>((((((a[5] * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / (((((b[5] * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) / (((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5])); + } +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/rational_horner1_7.hpp b/Utilities/BGL/boost/math/tools/detail/rational_horner1_7.hpp new file mode 100644 index 0000000000000000000000000000000000000000..0eb1c0a31b7642e2183180f49a30e1b774ca99d9 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/rational_horner1_7.hpp @@ -0,0 +1,102 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_RAT_7_HPP +#define BOOST_MATH_TOOLS_POLY_RAT_7_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T*, const U*, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]) / static_cast<V>(b[0]); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<2>*) +{ + if(x <= 1) + return static_cast<V>((a[1] * x + a[0]) / (b[1] * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((a[0] * z + a[1]) / (b[0] * z + b[1])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<3>*) +{ + if(x <= 1) + return static_cast<V>(((a[2] * x + a[1]) * x + a[0]) / ((b[2] * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((a[0] * z + a[1]) * z + a[2]) / ((b[0] * z + b[1]) * z + b[2])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<4>*) +{ + if(x <= 1) + return static_cast<V>((((a[3] * x + a[2]) * x + a[1]) * x + a[0]) / (((b[3] * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) / (((b[0] * z + b[1]) * z + b[2]) * z + b[3])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<5>*) +{ + if(x <= 1) + return static_cast<V>(((((a[4] * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((b[4] * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) / ((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<6>*) +{ + if(x <= 1) + return static_cast<V>((((((a[5] * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / (((((b[5] * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) / (((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<7>*) +{ + if(x <= 1) + return static_cast<V>(((((((a[6] * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((((b[6] * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) / ((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6])); + } +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/rational_horner1_8.hpp b/Utilities/BGL/boost/math/tools/detail/rational_horner1_8.hpp new file mode 100644 index 0000000000000000000000000000000000000000..b01f03101d2564778deacf04d992060d74b2fd58 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/rational_horner1_8.hpp @@ -0,0 +1,114 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_RAT_8_HPP +#define BOOST_MATH_TOOLS_POLY_RAT_8_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T*, const U*, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]) / static_cast<V>(b[0]); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<2>*) +{ + if(x <= 1) + return static_cast<V>((a[1] * x + a[0]) / (b[1] * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((a[0] * z + a[1]) / (b[0] * z + b[1])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<3>*) +{ + if(x <= 1) + return static_cast<V>(((a[2] * x + a[1]) * x + a[0]) / ((b[2] * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((a[0] * z + a[1]) * z + a[2]) / ((b[0] * z + b[1]) * z + b[2])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<4>*) +{ + if(x <= 1) + return static_cast<V>((((a[3] * x + a[2]) * x + a[1]) * x + a[0]) / (((b[3] * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) / (((b[0] * z + b[1]) * z + b[2]) * z + b[3])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<5>*) +{ + if(x <= 1) + return static_cast<V>(((((a[4] * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((b[4] * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) / ((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<6>*) +{ + if(x <= 1) + return static_cast<V>((((((a[5] * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / (((((b[5] * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) / (((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<7>*) +{ + if(x <= 1) + return static_cast<V>(((((((a[6] * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((((b[6] * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) / ((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<8>*) +{ + if(x <= 1) + return static_cast<V>((((((((a[7] * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / (((((((b[7] * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) / (((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7])); + } +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/rational_horner1_9.hpp b/Utilities/BGL/boost/math/tools/detail/rational_horner1_9.hpp new file mode 100644 index 0000000000000000000000000000000000000000..764a8a7337c761a2040094e4aad429532087f7ac --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/rational_horner1_9.hpp @@ -0,0 +1,126 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using Horners rule +#ifndef BOOST_MATH_TOOLS_POLY_RAT_9_HPP +#define BOOST_MATH_TOOLS_POLY_RAT_9_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T*, const U*, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]) / static_cast<V>(b[0]); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<2>*) +{ + if(x <= 1) + return static_cast<V>((a[1] * x + a[0]) / (b[1] * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((a[0] * z + a[1]) / (b[0] * z + b[1])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<3>*) +{ + if(x <= 1) + return static_cast<V>(((a[2] * x + a[1]) * x + a[0]) / ((b[2] * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((a[0] * z + a[1]) * z + a[2]) / ((b[0] * z + b[1]) * z + b[2])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<4>*) +{ + if(x <= 1) + return static_cast<V>((((a[3] * x + a[2]) * x + a[1]) * x + a[0]) / (((b[3] * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) / (((b[0] * z + b[1]) * z + b[2]) * z + b[3])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<5>*) +{ + if(x <= 1) + return static_cast<V>(((((a[4] * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((b[4] * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) / ((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<6>*) +{ + if(x <= 1) + return static_cast<V>((((((a[5] * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / (((((b[5] * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) / (((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<7>*) +{ + if(x <= 1) + return static_cast<V>(((((((a[6] * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((((b[6] * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) / ((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<8>*) +{ + if(x <= 1) + return static_cast<V>((((((((a[7] * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / (((((((b[7] * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) / (((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<9>*) +{ + if(x <= 1) + return static_cast<V>(((((((((a[8] * x + a[7]) * x + a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0]) / ((((((((b[8] * x + b[7]) * x + b[6]) * x + b[5]) * x + b[4]) * x + b[3]) * x + b[2]) * x + b[1]) * x + b[0])); + else + { + V z = 1 / x; + return static_cast<V>(((((((((a[0] * z + a[1]) * z + a[2]) * z + a[3]) * z + a[4]) * z + a[5]) * z + a[6]) * z + a[7]) * z + a[8]) / ((((((((b[0] * z + b[1]) * z + b[2]) * z + b[3]) * z + b[4]) * z + b[5]) * z + b[6]) * z + b[7]) * z + b[8])); + } +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/rational_horner2_10.hpp b/Utilities/BGL/boost/math/tools/detail/rational_horner2_10.hpp new file mode 100644 index 0000000000000000000000000000000000000000..9f01b97ad60cd299cc85e128f6bcd5b4ba802944 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/rational_horner2_10.hpp @@ -0,0 +1,144 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_RAT_EVAL_10_HPP +#define BOOST_MATH_TOOLS_RAT_EVAL_10_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]) / static_cast<V>(b[0]); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>((a[1] * x + a[0]) / (b[1] * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>(((a[2] * x + a[1]) * x + a[0]) / ((b[2] * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>((((a[3] * x + a[2]) * x + a[1]) * x + a[0]) / (((b[3] * x + b[2]) * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<5>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((a[4] * x2 + a[2]) * x2 + a[0] + (a[3] * x2 + a[1]) * x) / ((b[4] * x2 + b[2]) * x2 + b[0] + (b[3] * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((a[0] * z2 + a[2]) * z2 + a[4] + (a[1] * z2 + a[3]) * z) / ((b[0] * z2 + b[2]) * z2 + b[4] + (b[1] * z2 + b[3]) * z)); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<6>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((a[5] * x2 + a[3]) * x2 + a[1]) * x + (a[4] * x2 + a[2]) * x2 + a[0]) / (((b[5] * x2 + b[3]) * x2 + b[1]) * x + (b[4] * x2 + b[2]) * x2 + b[0])); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((a[0] * z2 + a[2]) * z2 + a[4]) * z + (a[1] * z2 + a[3]) * z2 + a[5]) / (((b[0] * z2 + b[2]) * z2 + b[4]) * z + (b[1] * z2 + b[3]) * z2 + b[5])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<7>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((a[6] * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + ((a[5] * x2 + a[3]) * x2 + a[1]) * x) / (((b[6] * x2 + b[4]) * x2 + b[2]) * x2 + b[0] + ((b[5] * x2 + b[3]) * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6] + ((a[1] * z2 + a[3]) * z2 + a[5]) * z) / (((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6] + ((b[1] * z2 + b[3]) * z2 + b[5]) * z)); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<8>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((((a[7] * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + ((a[6] * x2 + a[4]) * x2 + a[2]) * x2 + a[0]) / ((((b[7] * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x + ((b[6] * x2 + b[4]) * x2 + b[2]) * x2 + b[0])); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z + ((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) / ((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z + ((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<9>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((((a[8] * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + (((a[7] * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x) / ((((b[8] * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0] + (((b[7] * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8] + (((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z) / ((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8] + (((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z)); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<10>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((((a[9] * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + (((a[8] * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]) / (((((b[9] * x2 + b[7]) * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x + (((b[8] * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0])); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8]) * z + (((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z2 + a[9]) / (((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8]) * z + (((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z2 + b[9])); + } +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/rational_horner2_11.hpp b/Utilities/BGL/boost/math/tools/detail/rational_horner2_11.hpp new file mode 100644 index 0000000000000000000000000000000000000000..7fb99fb9931c7ffb3afc36bdbbe20cfd8795ef73 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/rational_horner2_11.hpp @@ -0,0 +1,160 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_RAT_EVAL_11_HPP +#define BOOST_MATH_TOOLS_RAT_EVAL_11_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]) / static_cast<V>(b[0]); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>((a[1] * x + a[0]) / (b[1] * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>(((a[2] * x + a[1]) * x + a[0]) / ((b[2] * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>((((a[3] * x + a[2]) * x + a[1]) * x + a[0]) / (((b[3] * x + b[2]) * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<5>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((a[4] * x2 + a[2]) * x2 + a[0] + (a[3] * x2 + a[1]) * x) / ((b[4] * x2 + b[2]) * x2 + b[0] + (b[3] * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((a[0] * z2 + a[2]) * z2 + a[4] + (a[1] * z2 + a[3]) * z) / ((b[0] * z2 + b[2]) * z2 + b[4] + (b[1] * z2 + b[3]) * z)); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<6>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((a[5] * x2 + a[3]) * x2 + a[1]) * x + (a[4] * x2 + a[2]) * x2 + a[0]) / (((b[5] * x2 + b[3]) * x2 + b[1]) * x + (b[4] * x2 + b[2]) * x2 + b[0])); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((a[0] * z2 + a[2]) * z2 + a[4]) * z + (a[1] * z2 + a[3]) * z2 + a[5]) / (((b[0] * z2 + b[2]) * z2 + b[4]) * z + (b[1] * z2 + b[3]) * z2 + b[5])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<7>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((a[6] * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + ((a[5] * x2 + a[3]) * x2 + a[1]) * x) / (((b[6] * x2 + b[4]) * x2 + b[2]) * x2 + b[0] + ((b[5] * x2 + b[3]) * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6] + ((a[1] * z2 + a[3]) * z2 + a[5]) * z) / (((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6] + ((b[1] * z2 + b[3]) * z2 + b[5]) * z)); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<8>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((((a[7] * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + ((a[6] * x2 + a[4]) * x2 + a[2]) * x2 + a[0]) / ((((b[7] * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x + ((b[6] * x2 + b[4]) * x2 + b[2]) * x2 + b[0])); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z + ((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) / ((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z + ((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<9>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((((a[8] * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + (((a[7] * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x) / ((((b[8] * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0] + (((b[7] * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8] + (((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z) / ((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8] + (((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z)); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<10>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((((a[9] * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + (((a[8] * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]) / (((((b[9] * x2 + b[7]) * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x + (((b[8] * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0])); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8]) * z + (((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z2 + a[9]) / (((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8]) * z + (((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z2 + b[9])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<11>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((((a[10] * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + ((((a[9] * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x) / (((((b[10] * x2 + b[8]) * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0] + ((((b[9] * x2 + b[7]) * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8]) * z2 + a[10] + ((((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z2 + a[9]) * z) / (((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8]) * z2 + b[10] + ((((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z2 + b[9]) * z)); + } +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/rational_horner2_12.hpp b/Utilities/BGL/boost/math/tools/detail/rational_horner2_12.hpp new file mode 100644 index 0000000000000000000000000000000000000000..dc272ae77274623415b16cf628499e29cc393707 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/rational_horner2_12.hpp @@ -0,0 +1,176 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_RAT_EVAL_12_HPP +#define BOOST_MATH_TOOLS_RAT_EVAL_12_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]) / static_cast<V>(b[0]); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>((a[1] * x + a[0]) / (b[1] * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>(((a[2] * x + a[1]) * x + a[0]) / ((b[2] * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>((((a[3] * x + a[2]) * x + a[1]) * x + a[0]) / (((b[3] * x + b[2]) * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<5>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((a[4] * x2 + a[2]) * x2 + a[0] + (a[3] * x2 + a[1]) * x) / ((b[4] * x2 + b[2]) * x2 + b[0] + (b[3] * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((a[0] * z2 + a[2]) * z2 + a[4] + (a[1] * z2 + a[3]) * z) / ((b[0] * z2 + b[2]) * z2 + b[4] + (b[1] * z2 + b[3]) * z)); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<6>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((a[5] * x2 + a[3]) * x2 + a[1]) * x + (a[4] * x2 + a[2]) * x2 + a[0]) / (((b[5] * x2 + b[3]) * x2 + b[1]) * x + (b[4] * x2 + b[2]) * x2 + b[0])); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((a[0] * z2 + a[2]) * z2 + a[4]) * z + (a[1] * z2 + a[3]) * z2 + a[5]) / (((b[0] * z2 + b[2]) * z2 + b[4]) * z + (b[1] * z2 + b[3]) * z2 + b[5])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<7>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((a[6] * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + ((a[5] * x2 + a[3]) * x2 + a[1]) * x) / (((b[6] * x2 + b[4]) * x2 + b[2]) * x2 + b[0] + ((b[5] * x2 + b[3]) * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6] + ((a[1] * z2 + a[3]) * z2 + a[5]) * z) / (((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6] + ((b[1] * z2 + b[3]) * z2 + b[5]) * z)); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<8>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((((a[7] * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + ((a[6] * x2 + a[4]) * x2 + a[2]) * x2 + a[0]) / ((((b[7] * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x + ((b[6] * x2 + b[4]) * x2 + b[2]) * x2 + b[0])); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z + ((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) / ((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z + ((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<9>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((((a[8] * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + (((a[7] * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x) / ((((b[8] * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0] + (((b[7] * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8] + (((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z) / ((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8] + (((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z)); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<10>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((((a[9] * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + (((a[8] * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]) / (((((b[9] * x2 + b[7]) * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x + (((b[8] * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0])); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8]) * z + (((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z2 + a[9]) / (((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8]) * z + (((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z2 + b[9])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<11>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((((a[10] * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + ((((a[9] * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x) / (((((b[10] * x2 + b[8]) * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0] + ((((b[9] * x2 + b[7]) * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8]) * z2 + a[10] + ((((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z2 + a[9]) * z) / (((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8]) * z2 + b[10] + ((((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z2 + b[9]) * z)); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<12>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((((((a[11] * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + ((((a[10] * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]) / ((((((b[11] * x2 + b[9]) * x2 + b[7]) * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x + ((((b[10] * x2 + b[8]) * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0])); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8]) * z2 + a[10]) * z + ((((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z2 + a[9]) * z2 + a[11]) / ((((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8]) * z2 + b[10]) * z + ((((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z2 + b[9]) * z2 + b[11])); + } +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/rational_horner2_13.hpp b/Utilities/BGL/boost/math/tools/detail/rational_horner2_13.hpp new file mode 100644 index 0000000000000000000000000000000000000000..6e51de66b57efe880b2e7c542923c7c4bb872ef7 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/rational_horner2_13.hpp @@ -0,0 +1,192 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_RAT_EVAL_13_HPP +#define BOOST_MATH_TOOLS_RAT_EVAL_13_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]) / static_cast<V>(b[0]); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>((a[1] * x + a[0]) / (b[1] * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>(((a[2] * x + a[1]) * x + a[0]) / ((b[2] * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>((((a[3] * x + a[2]) * x + a[1]) * x + a[0]) / (((b[3] * x + b[2]) * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<5>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((a[4] * x2 + a[2]) * x2 + a[0] + (a[3] * x2 + a[1]) * x) / ((b[4] * x2 + b[2]) * x2 + b[0] + (b[3] * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((a[0] * z2 + a[2]) * z2 + a[4] + (a[1] * z2 + a[3]) * z) / ((b[0] * z2 + b[2]) * z2 + b[4] + (b[1] * z2 + b[3]) * z)); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<6>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((a[5] * x2 + a[3]) * x2 + a[1]) * x + (a[4] * x2 + a[2]) * x2 + a[0]) / (((b[5] * x2 + b[3]) * x2 + b[1]) * x + (b[4] * x2 + b[2]) * x2 + b[0])); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((a[0] * z2 + a[2]) * z2 + a[4]) * z + (a[1] * z2 + a[3]) * z2 + a[5]) / (((b[0] * z2 + b[2]) * z2 + b[4]) * z + (b[1] * z2 + b[3]) * z2 + b[5])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<7>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((a[6] * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + ((a[5] * x2 + a[3]) * x2 + a[1]) * x) / (((b[6] * x2 + b[4]) * x2 + b[2]) * x2 + b[0] + ((b[5] * x2 + b[3]) * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6] + ((a[1] * z2 + a[3]) * z2 + a[5]) * z) / (((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6] + ((b[1] * z2 + b[3]) * z2 + b[5]) * z)); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<8>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((((a[7] * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + ((a[6] * x2 + a[4]) * x2 + a[2]) * x2 + a[0]) / ((((b[7] * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x + ((b[6] * x2 + b[4]) * x2 + b[2]) * x2 + b[0])); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z + ((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) / ((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z + ((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<9>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((((a[8] * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + (((a[7] * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x) / ((((b[8] * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0] + (((b[7] * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8] + (((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z) / ((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8] + (((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z)); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<10>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((((a[9] * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + (((a[8] * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]) / (((((b[9] * x2 + b[7]) * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x + (((b[8] * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0])); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8]) * z + (((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z2 + a[9]) / (((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8]) * z + (((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z2 + b[9])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<11>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((((a[10] * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + ((((a[9] * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x) / (((((b[10] * x2 + b[8]) * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0] + ((((b[9] * x2 + b[7]) * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8]) * z2 + a[10] + ((((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z2 + a[9]) * z) / (((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8]) * z2 + b[10] + ((((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z2 + b[9]) * z)); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<12>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((((((a[11] * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + ((((a[10] * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]) / ((((((b[11] * x2 + b[9]) * x2 + b[7]) * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x + ((((b[10] * x2 + b[8]) * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0])); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8]) * z2 + a[10]) * z + ((((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z2 + a[9]) * z2 + a[11]) / ((((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8]) * z2 + b[10]) * z + ((((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z2 + b[9]) * z2 + b[11])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<13>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((((((a[12] * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + (((((a[11] * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x) / ((((((b[12] * x2 + b[10]) * x2 + b[8]) * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0] + (((((b[11] * x2 + b[9]) * x2 + b[7]) * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8]) * z2 + a[10]) * z2 + a[12] + (((((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z2 + a[9]) * z2 + a[11]) * z) / ((((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8]) * z2 + b[10]) * z2 + b[12] + (((((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z2 + b[9]) * z2 + b[11]) * z)); + } +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/rational_horner2_14.hpp b/Utilities/BGL/boost/math/tools/detail/rational_horner2_14.hpp new file mode 100644 index 0000000000000000000000000000000000000000..68e82675b1c34be3934eeafb636e73be265b4dab --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/rational_horner2_14.hpp @@ -0,0 +1,208 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_RAT_EVAL_14_HPP +#define BOOST_MATH_TOOLS_RAT_EVAL_14_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]) / static_cast<V>(b[0]); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>((a[1] * x + a[0]) / (b[1] * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>(((a[2] * x + a[1]) * x + a[0]) / ((b[2] * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>((((a[3] * x + a[2]) * x + a[1]) * x + a[0]) / (((b[3] * x + b[2]) * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<5>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((a[4] * x2 + a[2]) * x2 + a[0] + (a[3] * x2 + a[1]) * x) / ((b[4] * x2 + b[2]) * x2 + b[0] + (b[3] * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((a[0] * z2 + a[2]) * z2 + a[4] + (a[1] * z2 + a[3]) * z) / ((b[0] * z2 + b[2]) * z2 + b[4] + (b[1] * z2 + b[3]) * z)); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<6>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((a[5] * x2 + a[3]) * x2 + a[1]) * x + (a[4] * x2 + a[2]) * x2 + a[0]) / (((b[5] * x2 + b[3]) * x2 + b[1]) * x + (b[4] * x2 + b[2]) * x2 + b[0])); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((a[0] * z2 + a[2]) * z2 + a[4]) * z + (a[1] * z2 + a[3]) * z2 + a[5]) / (((b[0] * z2 + b[2]) * z2 + b[4]) * z + (b[1] * z2 + b[3]) * z2 + b[5])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<7>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((a[6] * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + ((a[5] * x2 + a[3]) * x2 + a[1]) * x) / (((b[6] * x2 + b[4]) * x2 + b[2]) * x2 + b[0] + ((b[5] * x2 + b[3]) * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6] + ((a[1] * z2 + a[3]) * z2 + a[5]) * z) / (((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6] + ((b[1] * z2 + b[3]) * z2 + b[5]) * z)); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<8>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((((a[7] * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + ((a[6] * x2 + a[4]) * x2 + a[2]) * x2 + a[0]) / ((((b[7] * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x + ((b[6] * x2 + b[4]) * x2 + b[2]) * x2 + b[0])); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z + ((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) / ((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z + ((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<9>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((((a[8] * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + (((a[7] * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x) / ((((b[8] * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0] + (((b[7] * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8] + (((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z) / ((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8] + (((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z)); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<10>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((((a[9] * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + (((a[8] * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]) / (((((b[9] * x2 + b[7]) * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x + (((b[8] * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0])); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8]) * z + (((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z2 + a[9]) / (((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8]) * z + (((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z2 + b[9])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<11>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((((a[10] * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + ((((a[9] * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x) / (((((b[10] * x2 + b[8]) * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0] + ((((b[9] * x2 + b[7]) * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8]) * z2 + a[10] + ((((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z2 + a[9]) * z) / (((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8]) * z2 + b[10] + ((((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z2 + b[9]) * z)); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<12>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((((((a[11] * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + ((((a[10] * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]) / ((((((b[11] * x2 + b[9]) * x2 + b[7]) * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x + ((((b[10] * x2 + b[8]) * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0])); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8]) * z2 + a[10]) * z + ((((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z2 + a[9]) * z2 + a[11]) / ((((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8]) * z2 + b[10]) * z + ((((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z2 + b[9]) * z2 + b[11])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<13>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((((((a[12] * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + (((((a[11] * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x) / ((((((b[12] * x2 + b[10]) * x2 + b[8]) * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0] + (((((b[11] * x2 + b[9]) * x2 + b[7]) * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8]) * z2 + a[10]) * z2 + a[12] + (((((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z2 + a[9]) * z2 + a[11]) * z) / ((((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8]) * z2 + b[10]) * z2 + b[12] + (((((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z2 + b[9]) * z2 + b[11]) * z)); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<14>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((((((a[13] * x2 + a[11]) * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + (((((a[12] * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]) / (((((((b[13] * x2 + b[11]) * x2 + b[9]) * x2 + b[7]) * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x + (((((b[12] * x2 + b[10]) * x2 + b[8]) * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0])); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8]) * z2 + a[10]) * z2 + a[12]) * z + (((((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z2 + a[9]) * z2 + a[11]) * z2 + a[13]) / (((((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8]) * z2 + b[10]) * z2 + b[12]) * z + (((((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z2 + b[9]) * z2 + b[11]) * z2 + b[13])); + } +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/rational_horner2_15.hpp b/Utilities/BGL/boost/math/tools/detail/rational_horner2_15.hpp new file mode 100644 index 0000000000000000000000000000000000000000..5c48a4826df3a897e8e7ee932c90ea35caeb13e9 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/rational_horner2_15.hpp @@ -0,0 +1,224 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_RAT_EVAL_15_HPP +#define BOOST_MATH_TOOLS_RAT_EVAL_15_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]) / static_cast<V>(b[0]); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>((a[1] * x + a[0]) / (b[1] * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>(((a[2] * x + a[1]) * x + a[0]) / ((b[2] * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>((((a[3] * x + a[2]) * x + a[1]) * x + a[0]) / (((b[3] * x + b[2]) * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<5>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((a[4] * x2 + a[2]) * x2 + a[0] + (a[3] * x2 + a[1]) * x) / ((b[4] * x2 + b[2]) * x2 + b[0] + (b[3] * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((a[0] * z2 + a[2]) * z2 + a[4] + (a[1] * z2 + a[3]) * z) / ((b[0] * z2 + b[2]) * z2 + b[4] + (b[1] * z2 + b[3]) * z)); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<6>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((a[5] * x2 + a[3]) * x2 + a[1]) * x + (a[4] * x2 + a[2]) * x2 + a[0]) / (((b[5] * x2 + b[3]) * x2 + b[1]) * x + (b[4] * x2 + b[2]) * x2 + b[0])); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((a[0] * z2 + a[2]) * z2 + a[4]) * z + (a[1] * z2 + a[3]) * z2 + a[5]) / (((b[0] * z2 + b[2]) * z2 + b[4]) * z + (b[1] * z2 + b[3]) * z2 + b[5])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<7>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((a[6] * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + ((a[5] * x2 + a[3]) * x2 + a[1]) * x) / (((b[6] * x2 + b[4]) * x2 + b[2]) * x2 + b[0] + ((b[5] * x2 + b[3]) * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6] + ((a[1] * z2 + a[3]) * z2 + a[5]) * z) / (((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6] + ((b[1] * z2 + b[3]) * z2 + b[5]) * z)); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<8>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((((a[7] * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + ((a[6] * x2 + a[4]) * x2 + a[2]) * x2 + a[0]) / ((((b[7] * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x + ((b[6] * x2 + b[4]) * x2 + b[2]) * x2 + b[0])); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z + ((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) / ((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z + ((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<9>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((((a[8] * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + (((a[7] * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x) / ((((b[8] * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0] + (((b[7] * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8] + (((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z) / ((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8] + (((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z)); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<10>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((((a[9] * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + (((a[8] * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]) / (((((b[9] * x2 + b[7]) * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x + (((b[8] * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0])); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8]) * z + (((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z2 + a[9]) / (((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8]) * z + (((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z2 + b[9])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<11>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((((a[10] * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + ((((a[9] * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x) / (((((b[10] * x2 + b[8]) * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0] + ((((b[9] * x2 + b[7]) * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8]) * z2 + a[10] + ((((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z2 + a[9]) * z) / (((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8]) * z2 + b[10] + ((((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z2 + b[9]) * z)); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<12>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((((((a[11] * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + ((((a[10] * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]) / ((((((b[11] * x2 + b[9]) * x2 + b[7]) * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x + ((((b[10] * x2 + b[8]) * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0])); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8]) * z2 + a[10]) * z + ((((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z2 + a[9]) * z2 + a[11]) / ((((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8]) * z2 + b[10]) * z + ((((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z2 + b[9]) * z2 + b[11])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<13>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((((((a[12] * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + (((((a[11] * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x) / ((((((b[12] * x2 + b[10]) * x2 + b[8]) * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0] + (((((b[11] * x2 + b[9]) * x2 + b[7]) * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8]) * z2 + a[10]) * z2 + a[12] + (((((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z2 + a[9]) * z2 + a[11]) * z) / ((((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8]) * z2 + b[10]) * z2 + b[12] + (((((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z2 + b[9]) * z2 + b[11]) * z)); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<14>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((((((a[13] * x2 + a[11]) * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + (((((a[12] * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]) / (((((((b[13] * x2 + b[11]) * x2 + b[9]) * x2 + b[7]) * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x + (((((b[12] * x2 + b[10]) * x2 + b[8]) * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0])); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8]) * z2 + a[10]) * z2 + a[12]) * z + (((((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z2 + a[9]) * z2 + a[11]) * z2 + a[13]) / (((((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8]) * z2 + b[10]) * z2 + b[12]) * z + (((((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z2 + b[9]) * z2 + b[11]) * z2 + b[13])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<15>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((((((a[14] * x2 + a[12]) * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + ((((((a[13] * x2 + a[11]) * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x) / (((((((b[14] * x2 + b[12]) * x2 + b[10]) * x2 + b[8]) * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0] + ((((((b[13] * x2 + b[11]) * x2 + b[9]) * x2 + b[7]) * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8]) * z2 + a[10]) * z2 + a[12]) * z2 + a[14] + ((((((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z2 + a[9]) * z2 + a[11]) * z2 + a[13]) * z) / (((((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8]) * z2 + b[10]) * z2 + b[12]) * z2 + b[14] + ((((((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z2 + b[9]) * z2 + b[11]) * z2 + b[13]) * z)); + } +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/rational_horner2_16.hpp b/Utilities/BGL/boost/math/tools/detail/rational_horner2_16.hpp new file mode 100644 index 0000000000000000000000000000000000000000..f3ab6e79ceeffd3db380406f8b5ec6dc86e86557 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/rational_horner2_16.hpp @@ -0,0 +1,240 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_RAT_EVAL_16_HPP +#define BOOST_MATH_TOOLS_RAT_EVAL_16_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]) / static_cast<V>(b[0]); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>((a[1] * x + a[0]) / (b[1] * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>(((a[2] * x + a[1]) * x + a[0]) / ((b[2] * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>((((a[3] * x + a[2]) * x + a[1]) * x + a[0]) / (((b[3] * x + b[2]) * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<5>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((a[4] * x2 + a[2]) * x2 + a[0] + (a[3] * x2 + a[1]) * x) / ((b[4] * x2 + b[2]) * x2 + b[0] + (b[3] * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((a[0] * z2 + a[2]) * z2 + a[4] + (a[1] * z2 + a[3]) * z) / ((b[0] * z2 + b[2]) * z2 + b[4] + (b[1] * z2 + b[3]) * z)); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<6>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((a[5] * x2 + a[3]) * x2 + a[1]) * x + (a[4] * x2 + a[2]) * x2 + a[0]) / (((b[5] * x2 + b[3]) * x2 + b[1]) * x + (b[4] * x2 + b[2]) * x2 + b[0])); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((a[0] * z2 + a[2]) * z2 + a[4]) * z + (a[1] * z2 + a[3]) * z2 + a[5]) / (((b[0] * z2 + b[2]) * z2 + b[4]) * z + (b[1] * z2 + b[3]) * z2 + b[5])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<7>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((a[6] * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + ((a[5] * x2 + a[3]) * x2 + a[1]) * x) / (((b[6] * x2 + b[4]) * x2 + b[2]) * x2 + b[0] + ((b[5] * x2 + b[3]) * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6] + ((a[1] * z2 + a[3]) * z2 + a[5]) * z) / (((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6] + ((b[1] * z2 + b[3]) * z2 + b[5]) * z)); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<8>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((((a[7] * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + ((a[6] * x2 + a[4]) * x2 + a[2]) * x2 + a[0]) / ((((b[7] * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x + ((b[6] * x2 + b[4]) * x2 + b[2]) * x2 + b[0])); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z + ((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) / ((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z + ((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<9>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((((a[8] * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + (((a[7] * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x) / ((((b[8] * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0] + (((b[7] * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8] + (((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z) / ((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8] + (((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z)); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<10>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((((a[9] * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + (((a[8] * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]) / (((((b[9] * x2 + b[7]) * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x + (((b[8] * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0])); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8]) * z + (((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z2 + a[9]) / (((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8]) * z + (((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z2 + b[9])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<11>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((((a[10] * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + ((((a[9] * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x) / (((((b[10] * x2 + b[8]) * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0] + ((((b[9] * x2 + b[7]) * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8]) * z2 + a[10] + ((((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z2 + a[9]) * z) / (((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8]) * z2 + b[10] + ((((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z2 + b[9]) * z)); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<12>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((((((a[11] * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + ((((a[10] * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]) / ((((((b[11] * x2 + b[9]) * x2 + b[7]) * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x + ((((b[10] * x2 + b[8]) * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0])); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8]) * z2 + a[10]) * z + ((((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z2 + a[9]) * z2 + a[11]) / ((((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8]) * z2 + b[10]) * z + ((((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z2 + b[9]) * z2 + b[11])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<13>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((((((a[12] * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + (((((a[11] * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x) / ((((((b[12] * x2 + b[10]) * x2 + b[8]) * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0] + (((((b[11] * x2 + b[9]) * x2 + b[7]) * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8]) * z2 + a[10]) * z2 + a[12] + (((((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z2 + a[9]) * z2 + a[11]) * z) / ((((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8]) * z2 + b[10]) * z2 + b[12] + (((((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z2 + b[9]) * z2 + b[11]) * z)); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<14>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((((((a[13] * x2 + a[11]) * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + (((((a[12] * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]) / (((((((b[13] * x2 + b[11]) * x2 + b[9]) * x2 + b[7]) * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x + (((((b[12] * x2 + b[10]) * x2 + b[8]) * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0])); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8]) * z2 + a[10]) * z2 + a[12]) * z + (((((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z2 + a[9]) * z2 + a[11]) * z2 + a[13]) / (((((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8]) * z2 + b[10]) * z2 + b[12]) * z + (((((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z2 + b[9]) * z2 + b[11]) * z2 + b[13])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<15>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((((((a[14] * x2 + a[12]) * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + ((((((a[13] * x2 + a[11]) * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x) / (((((((b[14] * x2 + b[12]) * x2 + b[10]) * x2 + b[8]) * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0] + ((((((b[13] * x2 + b[11]) * x2 + b[9]) * x2 + b[7]) * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8]) * z2 + a[10]) * z2 + a[12]) * z2 + a[14] + ((((((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z2 + a[9]) * z2 + a[11]) * z2 + a[13]) * z) / (((((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8]) * z2 + b[10]) * z2 + b[12]) * z2 + b[14] + ((((((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z2 + b[9]) * z2 + b[11]) * z2 + b[13]) * z)); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<16>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((((((((a[15] * x2 + a[13]) * x2 + a[11]) * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + ((((((a[14] * x2 + a[12]) * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]) / ((((((((b[15] * x2 + b[13]) * x2 + b[11]) * x2 + b[9]) * x2 + b[7]) * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x + ((((((b[14] * x2 + b[12]) * x2 + b[10]) * x2 + b[8]) * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0])); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((((((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8]) * z2 + a[10]) * z2 + a[12]) * z2 + a[14]) * z + ((((((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z2 + a[9]) * z2 + a[11]) * z2 + a[13]) * z2 + a[15]) / ((((((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8]) * z2 + b[10]) * z2 + b[12]) * z2 + b[14]) * z + ((((((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z2 + b[9]) * z2 + b[11]) * z2 + b[13]) * z2 + b[15])); + } +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/rational_horner2_17.hpp b/Utilities/BGL/boost/math/tools/detail/rational_horner2_17.hpp new file mode 100644 index 0000000000000000000000000000000000000000..c975adde1b99c72e0ef772a3a67f311a18a69d3f --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/rational_horner2_17.hpp @@ -0,0 +1,256 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_RAT_EVAL_17_HPP +#define BOOST_MATH_TOOLS_RAT_EVAL_17_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]) / static_cast<V>(b[0]); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>((a[1] * x + a[0]) / (b[1] * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>(((a[2] * x + a[1]) * x + a[0]) / ((b[2] * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>((((a[3] * x + a[2]) * x + a[1]) * x + a[0]) / (((b[3] * x + b[2]) * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<5>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((a[4] * x2 + a[2]) * x2 + a[0] + (a[3] * x2 + a[1]) * x) / ((b[4] * x2 + b[2]) * x2 + b[0] + (b[3] * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((a[0] * z2 + a[2]) * z2 + a[4] + (a[1] * z2 + a[3]) * z) / ((b[0] * z2 + b[2]) * z2 + b[4] + (b[1] * z2 + b[3]) * z)); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<6>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((a[5] * x2 + a[3]) * x2 + a[1]) * x + (a[4] * x2 + a[2]) * x2 + a[0]) / (((b[5] * x2 + b[3]) * x2 + b[1]) * x + (b[4] * x2 + b[2]) * x2 + b[0])); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((a[0] * z2 + a[2]) * z2 + a[4]) * z + (a[1] * z2 + a[3]) * z2 + a[5]) / (((b[0] * z2 + b[2]) * z2 + b[4]) * z + (b[1] * z2 + b[3]) * z2 + b[5])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<7>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((a[6] * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + ((a[5] * x2 + a[3]) * x2 + a[1]) * x) / (((b[6] * x2 + b[4]) * x2 + b[2]) * x2 + b[0] + ((b[5] * x2 + b[3]) * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6] + ((a[1] * z2 + a[3]) * z2 + a[5]) * z) / (((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6] + ((b[1] * z2 + b[3]) * z2 + b[5]) * z)); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<8>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((((a[7] * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + ((a[6] * x2 + a[4]) * x2 + a[2]) * x2 + a[0]) / ((((b[7] * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x + ((b[6] * x2 + b[4]) * x2 + b[2]) * x2 + b[0])); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z + ((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) / ((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z + ((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<9>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((((a[8] * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + (((a[7] * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x) / ((((b[8] * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0] + (((b[7] * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8] + (((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z) / ((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8] + (((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z)); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<10>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((((a[9] * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + (((a[8] * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]) / (((((b[9] * x2 + b[7]) * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x + (((b[8] * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0])); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8]) * z + (((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z2 + a[9]) / (((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8]) * z + (((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z2 + b[9])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<11>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((((a[10] * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + ((((a[9] * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x) / (((((b[10] * x2 + b[8]) * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0] + ((((b[9] * x2 + b[7]) * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8]) * z2 + a[10] + ((((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z2 + a[9]) * z) / (((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8]) * z2 + b[10] + ((((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z2 + b[9]) * z)); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<12>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((((((a[11] * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + ((((a[10] * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]) / ((((((b[11] * x2 + b[9]) * x2 + b[7]) * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x + ((((b[10] * x2 + b[8]) * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0])); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8]) * z2 + a[10]) * z + ((((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z2 + a[9]) * z2 + a[11]) / ((((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8]) * z2 + b[10]) * z + ((((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z2 + b[9]) * z2 + b[11])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<13>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((((((a[12] * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + (((((a[11] * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x) / ((((((b[12] * x2 + b[10]) * x2 + b[8]) * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0] + (((((b[11] * x2 + b[9]) * x2 + b[7]) * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8]) * z2 + a[10]) * z2 + a[12] + (((((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z2 + a[9]) * z2 + a[11]) * z) / ((((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8]) * z2 + b[10]) * z2 + b[12] + (((((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z2 + b[9]) * z2 + b[11]) * z)); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<14>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((((((a[13] * x2 + a[11]) * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + (((((a[12] * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]) / (((((((b[13] * x2 + b[11]) * x2 + b[9]) * x2 + b[7]) * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x + (((((b[12] * x2 + b[10]) * x2 + b[8]) * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0])); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8]) * z2 + a[10]) * z2 + a[12]) * z + (((((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z2 + a[9]) * z2 + a[11]) * z2 + a[13]) / (((((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8]) * z2 + b[10]) * z2 + b[12]) * z + (((((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z2 + b[9]) * z2 + b[11]) * z2 + b[13])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<15>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((((((a[14] * x2 + a[12]) * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + ((((((a[13] * x2 + a[11]) * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x) / (((((((b[14] * x2 + b[12]) * x2 + b[10]) * x2 + b[8]) * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0] + ((((((b[13] * x2 + b[11]) * x2 + b[9]) * x2 + b[7]) * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8]) * z2 + a[10]) * z2 + a[12]) * z2 + a[14] + ((((((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z2 + a[9]) * z2 + a[11]) * z2 + a[13]) * z) / (((((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8]) * z2 + b[10]) * z2 + b[12]) * z2 + b[14] + ((((((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z2 + b[9]) * z2 + b[11]) * z2 + b[13]) * z)); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<16>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((((((((a[15] * x2 + a[13]) * x2 + a[11]) * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + ((((((a[14] * x2 + a[12]) * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]) / ((((((((b[15] * x2 + b[13]) * x2 + b[11]) * x2 + b[9]) * x2 + b[7]) * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x + ((((((b[14] * x2 + b[12]) * x2 + b[10]) * x2 + b[8]) * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0])); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((((((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8]) * z2 + a[10]) * z2 + a[12]) * z2 + a[14]) * z + ((((((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z2 + a[9]) * z2 + a[11]) * z2 + a[13]) * z2 + a[15]) / ((((((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8]) * z2 + b[10]) * z2 + b[12]) * z2 + b[14]) * z + ((((((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z2 + b[9]) * z2 + b[11]) * z2 + b[13]) * z2 + b[15])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<17>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((((((((a[16] * x2 + a[14]) * x2 + a[12]) * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + (((((((a[15] * x2 + a[13]) * x2 + a[11]) * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x) / ((((((((b[16] * x2 + b[14]) * x2 + b[12]) * x2 + b[10]) * x2 + b[8]) * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0] + (((((((b[15] * x2 + b[13]) * x2 + b[11]) * x2 + b[9]) * x2 + b[7]) * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((((((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8]) * z2 + a[10]) * z2 + a[12]) * z2 + a[14]) * z2 + a[16] + (((((((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z2 + a[9]) * z2 + a[11]) * z2 + a[13]) * z2 + a[15]) * z) / ((((((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8]) * z2 + b[10]) * z2 + b[12]) * z2 + b[14]) * z2 + b[16] + (((((((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z2 + b[9]) * z2 + b[11]) * z2 + b[13]) * z2 + b[15]) * z)); + } +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/rational_horner2_18.hpp b/Utilities/BGL/boost/math/tools/detail/rational_horner2_18.hpp new file mode 100644 index 0000000000000000000000000000000000000000..d8513c0d7475985ede8513c83833affe2c055d80 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/rational_horner2_18.hpp @@ -0,0 +1,272 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_RAT_EVAL_18_HPP +#define BOOST_MATH_TOOLS_RAT_EVAL_18_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]) / static_cast<V>(b[0]); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>((a[1] * x + a[0]) / (b[1] * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>(((a[2] * x + a[1]) * x + a[0]) / ((b[2] * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>((((a[3] * x + a[2]) * x + a[1]) * x + a[0]) / (((b[3] * x + b[2]) * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<5>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((a[4] * x2 + a[2]) * x2 + a[0] + (a[3] * x2 + a[1]) * x) / ((b[4] * x2 + b[2]) * x2 + b[0] + (b[3] * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((a[0] * z2 + a[2]) * z2 + a[4] + (a[1] * z2 + a[3]) * z) / ((b[0] * z2 + b[2]) * z2 + b[4] + (b[1] * z2 + b[3]) * z)); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<6>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((a[5] * x2 + a[3]) * x2 + a[1]) * x + (a[4] * x2 + a[2]) * x2 + a[0]) / (((b[5] * x2 + b[3]) * x2 + b[1]) * x + (b[4] * x2 + b[2]) * x2 + b[0])); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((a[0] * z2 + a[2]) * z2 + a[4]) * z + (a[1] * z2 + a[3]) * z2 + a[5]) / (((b[0] * z2 + b[2]) * z2 + b[4]) * z + (b[1] * z2 + b[3]) * z2 + b[5])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<7>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((a[6] * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + ((a[5] * x2 + a[3]) * x2 + a[1]) * x) / (((b[6] * x2 + b[4]) * x2 + b[2]) * x2 + b[0] + ((b[5] * x2 + b[3]) * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6] + ((a[1] * z2 + a[3]) * z2 + a[5]) * z) / (((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6] + ((b[1] * z2 + b[3]) * z2 + b[5]) * z)); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<8>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((((a[7] * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + ((a[6] * x2 + a[4]) * x2 + a[2]) * x2 + a[0]) / ((((b[7] * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x + ((b[6] * x2 + b[4]) * x2 + b[2]) * x2 + b[0])); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z + ((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) / ((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z + ((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<9>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((((a[8] * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + (((a[7] * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x) / ((((b[8] * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0] + (((b[7] * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8] + (((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z) / ((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8] + (((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z)); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<10>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((((a[9] * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + (((a[8] * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]) / (((((b[9] * x2 + b[7]) * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x + (((b[8] * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0])); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8]) * z + (((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z2 + a[9]) / (((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8]) * z + (((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z2 + b[9])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<11>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((((a[10] * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + ((((a[9] * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x) / (((((b[10] * x2 + b[8]) * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0] + ((((b[9] * x2 + b[7]) * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8]) * z2 + a[10] + ((((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z2 + a[9]) * z) / (((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8]) * z2 + b[10] + ((((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z2 + b[9]) * z)); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<12>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((((((a[11] * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + ((((a[10] * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]) / ((((((b[11] * x2 + b[9]) * x2 + b[7]) * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x + ((((b[10] * x2 + b[8]) * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0])); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8]) * z2 + a[10]) * z + ((((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z2 + a[9]) * z2 + a[11]) / ((((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8]) * z2 + b[10]) * z + ((((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z2 + b[9]) * z2 + b[11])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<13>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((((((a[12] * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + (((((a[11] * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x) / ((((((b[12] * x2 + b[10]) * x2 + b[8]) * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0] + (((((b[11] * x2 + b[9]) * x2 + b[7]) * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8]) * z2 + a[10]) * z2 + a[12] + (((((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z2 + a[9]) * z2 + a[11]) * z) / ((((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8]) * z2 + b[10]) * z2 + b[12] + (((((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z2 + b[9]) * z2 + b[11]) * z)); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<14>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((((((a[13] * x2 + a[11]) * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + (((((a[12] * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]) / (((((((b[13] * x2 + b[11]) * x2 + b[9]) * x2 + b[7]) * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x + (((((b[12] * x2 + b[10]) * x2 + b[8]) * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0])); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8]) * z2 + a[10]) * z2 + a[12]) * z + (((((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z2 + a[9]) * z2 + a[11]) * z2 + a[13]) / (((((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8]) * z2 + b[10]) * z2 + b[12]) * z + (((((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z2 + b[9]) * z2 + b[11]) * z2 + b[13])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<15>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((((((a[14] * x2 + a[12]) * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + ((((((a[13] * x2 + a[11]) * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x) / (((((((b[14] * x2 + b[12]) * x2 + b[10]) * x2 + b[8]) * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0] + ((((((b[13] * x2 + b[11]) * x2 + b[9]) * x2 + b[7]) * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8]) * z2 + a[10]) * z2 + a[12]) * z2 + a[14] + ((((((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z2 + a[9]) * z2 + a[11]) * z2 + a[13]) * z) / (((((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8]) * z2 + b[10]) * z2 + b[12]) * z2 + b[14] + ((((((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z2 + b[9]) * z2 + b[11]) * z2 + b[13]) * z)); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<16>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((((((((a[15] * x2 + a[13]) * x2 + a[11]) * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + ((((((a[14] * x2 + a[12]) * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]) / ((((((((b[15] * x2 + b[13]) * x2 + b[11]) * x2 + b[9]) * x2 + b[7]) * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x + ((((((b[14] * x2 + b[12]) * x2 + b[10]) * x2 + b[8]) * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0])); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((((((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8]) * z2 + a[10]) * z2 + a[12]) * z2 + a[14]) * z + ((((((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z2 + a[9]) * z2 + a[11]) * z2 + a[13]) * z2 + a[15]) / ((((((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8]) * z2 + b[10]) * z2 + b[12]) * z2 + b[14]) * z + ((((((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z2 + b[9]) * z2 + b[11]) * z2 + b[13]) * z2 + b[15])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<17>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((((((((a[16] * x2 + a[14]) * x2 + a[12]) * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + (((((((a[15] * x2 + a[13]) * x2 + a[11]) * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x) / ((((((((b[16] * x2 + b[14]) * x2 + b[12]) * x2 + b[10]) * x2 + b[8]) * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0] + (((((((b[15] * x2 + b[13]) * x2 + b[11]) * x2 + b[9]) * x2 + b[7]) * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((((((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8]) * z2 + a[10]) * z2 + a[12]) * z2 + a[14]) * z2 + a[16] + (((((((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z2 + a[9]) * z2 + a[11]) * z2 + a[13]) * z2 + a[15]) * z) / ((((((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8]) * z2 + b[10]) * z2 + b[12]) * z2 + b[14]) * z2 + b[16] + (((((((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z2 + b[9]) * z2 + b[11]) * z2 + b[13]) * z2 + b[15]) * z)); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<18>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((((((((a[17] * x2 + a[15]) * x2 + a[13]) * x2 + a[11]) * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + (((((((a[16] * x2 + a[14]) * x2 + a[12]) * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]) / (((((((((b[17] * x2 + b[15]) * x2 + b[13]) * x2 + b[11]) * x2 + b[9]) * x2 + b[7]) * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x + (((((((b[16] * x2 + b[14]) * x2 + b[12]) * x2 + b[10]) * x2 + b[8]) * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0])); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((((((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8]) * z2 + a[10]) * z2 + a[12]) * z2 + a[14]) * z2 + a[16]) * z + (((((((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z2 + a[9]) * z2 + a[11]) * z2 + a[13]) * z2 + a[15]) * z2 + a[17]) / (((((((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8]) * z2 + b[10]) * z2 + b[12]) * z2 + b[14]) * z2 + b[16]) * z + (((((((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z2 + b[9]) * z2 + b[11]) * z2 + b[13]) * z2 + b[15]) * z2 + b[17])); + } +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/rational_horner2_19.hpp b/Utilities/BGL/boost/math/tools/detail/rational_horner2_19.hpp new file mode 100644 index 0000000000000000000000000000000000000000..c8269f3013ad03873c66677e49f3a143e574324a --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/rational_horner2_19.hpp @@ -0,0 +1,288 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_RAT_EVAL_19_HPP +#define BOOST_MATH_TOOLS_RAT_EVAL_19_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]) / static_cast<V>(b[0]); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>((a[1] * x + a[0]) / (b[1] * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>(((a[2] * x + a[1]) * x + a[0]) / ((b[2] * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>((((a[3] * x + a[2]) * x + a[1]) * x + a[0]) / (((b[3] * x + b[2]) * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<5>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((a[4] * x2 + a[2]) * x2 + a[0] + (a[3] * x2 + a[1]) * x) / ((b[4] * x2 + b[2]) * x2 + b[0] + (b[3] * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((a[0] * z2 + a[2]) * z2 + a[4] + (a[1] * z2 + a[3]) * z) / ((b[0] * z2 + b[2]) * z2 + b[4] + (b[1] * z2 + b[3]) * z)); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<6>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((a[5] * x2 + a[3]) * x2 + a[1]) * x + (a[4] * x2 + a[2]) * x2 + a[0]) / (((b[5] * x2 + b[3]) * x2 + b[1]) * x + (b[4] * x2 + b[2]) * x2 + b[0])); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((a[0] * z2 + a[2]) * z2 + a[4]) * z + (a[1] * z2 + a[3]) * z2 + a[5]) / (((b[0] * z2 + b[2]) * z2 + b[4]) * z + (b[1] * z2 + b[3]) * z2 + b[5])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<7>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((a[6] * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + ((a[5] * x2 + a[3]) * x2 + a[1]) * x) / (((b[6] * x2 + b[4]) * x2 + b[2]) * x2 + b[0] + ((b[5] * x2 + b[3]) * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6] + ((a[1] * z2 + a[3]) * z2 + a[5]) * z) / (((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6] + ((b[1] * z2 + b[3]) * z2 + b[5]) * z)); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<8>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((((a[7] * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + ((a[6] * x2 + a[4]) * x2 + a[2]) * x2 + a[0]) / ((((b[7] * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x + ((b[6] * x2 + b[4]) * x2 + b[2]) * x2 + b[0])); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z + ((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) / ((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z + ((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<9>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((((a[8] * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + (((a[7] * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x) / ((((b[8] * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0] + (((b[7] * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8] + (((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z) / ((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8] + (((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z)); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<10>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((((a[9] * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + (((a[8] * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]) / (((((b[9] * x2 + b[7]) * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x + (((b[8] * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0])); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8]) * z + (((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z2 + a[9]) / (((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8]) * z + (((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z2 + b[9])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<11>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((((a[10] * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + ((((a[9] * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x) / (((((b[10] * x2 + b[8]) * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0] + ((((b[9] * x2 + b[7]) * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8]) * z2 + a[10] + ((((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z2 + a[9]) * z) / (((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8]) * z2 + b[10] + ((((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z2 + b[9]) * z)); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<12>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((((((a[11] * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + ((((a[10] * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]) / ((((((b[11] * x2 + b[9]) * x2 + b[7]) * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x + ((((b[10] * x2 + b[8]) * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0])); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8]) * z2 + a[10]) * z + ((((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z2 + a[9]) * z2 + a[11]) / ((((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8]) * z2 + b[10]) * z + ((((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z2 + b[9]) * z2 + b[11])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<13>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((((((a[12] * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + (((((a[11] * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x) / ((((((b[12] * x2 + b[10]) * x2 + b[8]) * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0] + (((((b[11] * x2 + b[9]) * x2 + b[7]) * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8]) * z2 + a[10]) * z2 + a[12] + (((((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z2 + a[9]) * z2 + a[11]) * z) / ((((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8]) * z2 + b[10]) * z2 + b[12] + (((((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z2 + b[9]) * z2 + b[11]) * z)); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<14>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((((((a[13] * x2 + a[11]) * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + (((((a[12] * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]) / (((((((b[13] * x2 + b[11]) * x2 + b[9]) * x2 + b[7]) * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x + (((((b[12] * x2 + b[10]) * x2 + b[8]) * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0])); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8]) * z2 + a[10]) * z2 + a[12]) * z + (((((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z2 + a[9]) * z2 + a[11]) * z2 + a[13]) / (((((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8]) * z2 + b[10]) * z2 + b[12]) * z + (((((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z2 + b[9]) * z2 + b[11]) * z2 + b[13])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<15>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((((((a[14] * x2 + a[12]) * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + ((((((a[13] * x2 + a[11]) * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x) / (((((((b[14] * x2 + b[12]) * x2 + b[10]) * x2 + b[8]) * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0] + ((((((b[13] * x2 + b[11]) * x2 + b[9]) * x2 + b[7]) * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8]) * z2 + a[10]) * z2 + a[12]) * z2 + a[14] + ((((((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z2 + a[9]) * z2 + a[11]) * z2 + a[13]) * z) / (((((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8]) * z2 + b[10]) * z2 + b[12]) * z2 + b[14] + ((((((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z2 + b[9]) * z2 + b[11]) * z2 + b[13]) * z)); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<16>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((((((((a[15] * x2 + a[13]) * x2 + a[11]) * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + ((((((a[14] * x2 + a[12]) * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]) / ((((((((b[15] * x2 + b[13]) * x2 + b[11]) * x2 + b[9]) * x2 + b[7]) * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x + ((((((b[14] * x2 + b[12]) * x2 + b[10]) * x2 + b[8]) * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0])); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((((((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8]) * z2 + a[10]) * z2 + a[12]) * z2 + a[14]) * z + ((((((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z2 + a[9]) * z2 + a[11]) * z2 + a[13]) * z2 + a[15]) / ((((((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8]) * z2 + b[10]) * z2 + b[12]) * z2 + b[14]) * z + ((((((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z2 + b[9]) * z2 + b[11]) * z2 + b[13]) * z2 + b[15])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<17>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((((((((a[16] * x2 + a[14]) * x2 + a[12]) * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + (((((((a[15] * x2 + a[13]) * x2 + a[11]) * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x) / ((((((((b[16] * x2 + b[14]) * x2 + b[12]) * x2 + b[10]) * x2 + b[8]) * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0] + (((((((b[15] * x2 + b[13]) * x2 + b[11]) * x2 + b[9]) * x2 + b[7]) * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((((((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8]) * z2 + a[10]) * z2 + a[12]) * z2 + a[14]) * z2 + a[16] + (((((((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z2 + a[9]) * z2 + a[11]) * z2 + a[13]) * z2 + a[15]) * z) / ((((((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8]) * z2 + b[10]) * z2 + b[12]) * z2 + b[14]) * z2 + b[16] + (((((((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z2 + b[9]) * z2 + b[11]) * z2 + b[13]) * z2 + b[15]) * z)); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<18>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((((((((a[17] * x2 + a[15]) * x2 + a[13]) * x2 + a[11]) * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + (((((((a[16] * x2 + a[14]) * x2 + a[12]) * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]) / (((((((((b[17] * x2 + b[15]) * x2 + b[13]) * x2 + b[11]) * x2 + b[9]) * x2 + b[7]) * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x + (((((((b[16] * x2 + b[14]) * x2 + b[12]) * x2 + b[10]) * x2 + b[8]) * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0])); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((((((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8]) * z2 + a[10]) * z2 + a[12]) * z2 + a[14]) * z2 + a[16]) * z + (((((((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z2 + a[9]) * z2 + a[11]) * z2 + a[13]) * z2 + a[15]) * z2 + a[17]) / (((((((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8]) * z2 + b[10]) * z2 + b[12]) * z2 + b[14]) * z2 + b[16]) * z + (((((((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z2 + b[9]) * z2 + b[11]) * z2 + b[13]) * z2 + b[15]) * z2 + b[17])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<19>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((((((((a[18] * x2 + a[16]) * x2 + a[14]) * x2 + a[12]) * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + ((((((((a[17] * x2 + a[15]) * x2 + a[13]) * x2 + a[11]) * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x) / (((((((((b[18] * x2 + b[16]) * x2 + b[14]) * x2 + b[12]) * x2 + b[10]) * x2 + b[8]) * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0] + ((((((((b[17] * x2 + b[15]) * x2 + b[13]) * x2 + b[11]) * x2 + b[9]) * x2 + b[7]) * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((((((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8]) * z2 + a[10]) * z2 + a[12]) * z2 + a[14]) * z2 + a[16]) * z2 + a[18] + ((((((((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z2 + a[9]) * z2 + a[11]) * z2 + a[13]) * z2 + a[15]) * z2 + a[17]) * z) / (((((((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8]) * z2 + b[10]) * z2 + b[12]) * z2 + b[14]) * z2 + b[16]) * z2 + b[18] + ((((((((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z2 + b[9]) * z2 + b[11]) * z2 + b[13]) * z2 + b[15]) * z2 + b[17]) * z)); + } +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/rational_horner2_2.hpp b/Utilities/BGL/boost/math/tools/detail/rational_horner2_2.hpp new file mode 100644 index 0000000000000000000000000000000000000000..5373d144f6c795e4aa14bb4c8fb6ee24707b03db --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/rational_horner2_2.hpp @@ -0,0 +1,48 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_RAT_EVAL_2_HPP +#define BOOST_MATH_TOOLS_RAT_EVAL_2_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]) / static_cast<V>(b[0]); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>((a[1] * x + a[0]) / (b[1] * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>(((a[2] * x + a[1]) * x + a[0]) / ((b[2] * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>((((a[3] * x + a[2]) * x + a[1]) * x + a[0]) / (((b[3] * x + b[2]) * x + b[1]) * x + b[0])); +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/rational_horner2_20.hpp b/Utilities/BGL/boost/math/tools/detail/rational_horner2_20.hpp new file mode 100644 index 0000000000000000000000000000000000000000..affba515872ec3c996e0dddf03b69aa0b34855a2 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/rational_horner2_20.hpp @@ -0,0 +1,304 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_RAT_EVAL_20_HPP +#define BOOST_MATH_TOOLS_RAT_EVAL_20_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]) / static_cast<V>(b[0]); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>((a[1] * x + a[0]) / (b[1] * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>(((a[2] * x + a[1]) * x + a[0]) / ((b[2] * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>((((a[3] * x + a[2]) * x + a[1]) * x + a[0]) / (((b[3] * x + b[2]) * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<5>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((a[4] * x2 + a[2]) * x2 + a[0] + (a[3] * x2 + a[1]) * x) / ((b[4] * x2 + b[2]) * x2 + b[0] + (b[3] * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((a[0] * z2 + a[2]) * z2 + a[4] + (a[1] * z2 + a[3]) * z) / ((b[0] * z2 + b[2]) * z2 + b[4] + (b[1] * z2 + b[3]) * z)); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<6>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((a[5] * x2 + a[3]) * x2 + a[1]) * x + (a[4] * x2 + a[2]) * x2 + a[0]) / (((b[5] * x2 + b[3]) * x2 + b[1]) * x + (b[4] * x2 + b[2]) * x2 + b[0])); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((a[0] * z2 + a[2]) * z2 + a[4]) * z + (a[1] * z2 + a[3]) * z2 + a[5]) / (((b[0] * z2 + b[2]) * z2 + b[4]) * z + (b[1] * z2 + b[3]) * z2 + b[5])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<7>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((a[6] * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + ((a[5] * x2 + a[3]) * x2 + a[1]) * x) / (((b[6] * x2 + b[4]) * x2 + b[2]) * x2 + b[0] + ((b[5] * x2 + b[3]) * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6] + ((a[1] * z2 + a[3]) * z2 + a[5]) * z) / (((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6] + ((b[1] * z2 + b[3]) * z2 + b[5]) * z)); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<8>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((((a[7] * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + ((a[6] * x2 + a[4]) * x2 + a[2]) * x2 + a[0]) / ((((b[7] * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x + ((b[6] * x2 + b[4]) * x2 + b[2]) * x2 + b[0])); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z + ((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) / ((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z + ((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<9>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((((a[8] * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + (((a[7] * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x) / ((((b[8] * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0] + (((b[7] * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8] + (((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z) / ((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8] + (((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z)); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<10>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((((a[9] * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + (((a[8] * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]) / (((((b[9] * x2 + b[7]) * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x + (((b[8] * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0])); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8]) * z + (((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z2 + a[9]) / (((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8]) * z + (((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z2 + b[9])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<11>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((((a[10] * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + ((((a[9] * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x) / (((((b[10] * x2 + b[8]) * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0] + ((((b[9] * x2 + b[7]) * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8]) * z2 + a[10] + ((((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z2 + a[9]) * z) / (((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8]) * z2 + b[10] + ((((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z2 + b[9]) * z)); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<12>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((((((a[11] * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + ((((a[10] * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]) / ((((((b[11] * x2 + b[9]) * x2 + b[7]) * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x + ((((b[10] * x2 + b[8]) * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0])); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8]) * z2 + a[10]) * z + ((((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z2 + a[9]) * z2 + a[11]) / ((((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8]) * z2 + b[10]) * z + ((((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z2 + b[9]) * z2 + b[11])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<13>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((((((a[12] * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + (((((a[11] * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x) / ((((((b[12] * x2 + b[10]) * x2 + b[8]) * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0] + (((((b[11] * x2 + b[9]) * x2 + b[7]) * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8]) * z2 + a[10]) * z2 + a[12] + (((((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z2 + a[9]) * z2 + a[11]) * z) / ((((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8]) * z2 + b[10]) * z2 + b[12] + (((((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z2 + b[9]) * z2 + b[11]) * z)); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<14>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((((((a[13] * x2 + a[11]) * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + (((((a[12] * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]) / (((((((b[13] * x2 + b[11]) * x2 + b[9]) * x2 + b[7]) * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x + (((((b[12] * x2 + b[10]) * x2 + b[8]) * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0])); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8]) * z2 + a[10]) * z2 + a[12]) * z + (((((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z2 + a[9]) * z2 + a[11]) * z2 + a[13]) / (((((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8]) * z2 + b[10]) * z2 + b[12]) * z + (((((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z2 + b[9]) * z2 + b[11]) * z2 + b[13])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<15>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((((((a[14] * x2 + a[12]) * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + ((((((a[13] * x2 + a[11]) * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x) / (((((((b[14] * x2 + b[12]) * x2 + b[10]) * x2 + b[8]) * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0] + ((((((b[13] * x2 + b[11]) * x2 + b[9]) * x2 + b[7]) * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8]) * z2 + a[10]) * z2 + a[12]) * z2 + a[14] + ((((((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z2 + a[9]) * z2 + a[11]) * z2 + a[13]) * z) / (((((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8]) * z2 + b[10]) * z2 + b[12]) * z2 + b[14] + ((((((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z2 + b[9]) * z2 + b[11]) * z2 + b[13]) * z)); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<16>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((((((((a[15] * x2 + a[13]) * x2 + a[11]) * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + ((((((a[14] * x2 + a[12]) * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]) / ((((((((b[15] * x2 + b[13]) * x2 + b[11]) * x2 + b[9]) * x2 + b[7]) * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x + ((((((b[14] * x2 + b[12]) * x2 + b[10]) * x2 + b[8]) * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0])); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((((((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8]) * z2 + a[10]) * z2 + a[12]) * z2 + a[14]) * z + ((((((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z2 + a[9]) * z2 + a[11]) * z2 + a[13]) * z2 + a[15]) / ((((((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8]) * z2 + b[10]) * z2 + b[12]) * z2 + b[14]) * z + ((((((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z2 + b[9]) * z2 + b[11]) * z2 + b[13]) * z2 + b[15])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<17>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((((((((a[16] * x2 + a[14]) * x2 + a[12]) * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + (((((((a[15] * x2 + a[13]) * x2 + a[11]) * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x) / ((((((((b[16] * x2 + b[14]) * x2 + b[12]) * x2 + b[10]) * x2 + b[8]) * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0] + (((((((b[15] * x2 + b[13]) * x2 + b[11]) * x2 + b[9]) * x2 + b[7]) * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((((((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8]) * z2 + a[10]) * z2 + a[12]) * z2 + a[14]) * z2 + a[16] + (((((((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z2 + a[9]) * z2 + a[11]) * z2 + a[13]) * z2 + a[15]) * z) / ((((((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8]) * z2 + b[10]) * z2 + b[12]) * z2 + b[14]) * z2 + b[16] + (((((((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z2 + b[9]) * z2 + b[11]) * z2 + b[13]) * z2 + b[15]) * z)); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<18>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((((((((a[17] * x2 + a[15]) * x2 + a[13]) * x2 + a[11]) * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + (((((((a[16] * x2 + a[14]) * x2 + a[12]) * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]) / (((((((((b[17] * x2 + b[15]) * x2 + b[13]) * x2 + b[11]) * x2 + b[9]) * x2 + b[7]) * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x + (((((((b[16] * x2 + b[14]) * x2 + b[12]) * x2 + b[10]) * x2 + b[8]) * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0])); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((((((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8]) * z2 + a[10]) * z2 + a[12]) * z2 + a[14]) * z2 + a[16]) * z + (((((((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z2 + a[9]) * z2 + a[11]) * z2 + a[13]) * z2 + a[15]) * z2 + a[17]) / (((((((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8]) * z2 + b[10]) * z2 + b[12]) * z2 + b[14]) * z2 + b[16]) * z + (((((((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z2 + b[9]) * z2 + b[11]) * z2 + b[13]) * z2 + b[15]) * z2 + b[17])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<19>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((((((((a[18] * x2 + a[16]) * x2 + a[14]) * x2 + a[12]) * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + ((((((((a[17] * x2 + a[15]) * x2 + a[13]) * x2 + a[11]) * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x) / (((((((((b[18] * x2 + b[16]) * x2 + b[14]) * x2 + b[12]) * x2 + b[10]) * x2 + b[8]) * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0] + ((((((((b[17] * x2 + b[15]) * x2 + b[13]) * x2 + b[11]) * x2 + b[9]) * x2 + b[7]) * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((((((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8]) * z2 + a[10]) * z2 + a[12]) * z2 + a[14]) * z2 + a[16]) * z2 + a[18] + ((((((((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z2 + a[9]) * z2 + a[11]) * z2 + a[13]) * z2 + a[15]) * z2 + a[17]) * z) / (((((((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8]) * z2 + b[10]) * z2 + b[12]) * z2 + b[14]) * z2 + b[16]) * z2 + b[18] + ((((((((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z2 + b[9]) * z2 + b[11]) * z2 + b[13]) * z2 + b[15]) * z2 + b[17]) * z)); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<20>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((((((((((a[19] * x2 + a[17]) * x2 + a[15]) * x2 + a[13]) * x2 + a[11]) * x2 + a[9]) * x2 + a[7]) * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + ((((((((a[18] * x2 + a[16]) * x2 + a[14]) * x2 + a[12]) * x2 + a[10]) * x2 + a[8]) * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0]) / ((((((((((b[19] * x2 + b[17]) * x2 + b[15]) * x2 + b[13]) * x2 + b[11]) * x2 + b[9]) * x2 + b[7]) * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x + ((((((((b[18] * x2 + b[16]) * x2 + b[14]) * x2 + b[12]) * x2 + b[10]) * x2 + b[8]) * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0])); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((((((((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8]) * z2 + a[10]) * z2 + a[12]) * z2 + a[14]) * z2 + a[16]) * z2 + a[18]) * z + ((((((((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z2 + a[9]) * z2 + a[11]) * z2 + a[13]) * z2 + a[15]) * z2 + a[17]) * z2 + a[19]) / ((((((((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8]) * z2 + b[10]) * z2 + b[12]) * z2 + b[14]) * z2 + b[16]) * z2 + b[18]) * z + ((((((((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z2 + b[9]) * z2 + b[11]) * z2 + b[13]) * z2 + b[15]) * z2 + b[17]) * z2 + b[19])); + } +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/rational_horner2_3.hpp b/Utilities/BGL/boost/math/tools/detail/rational_horner2_3.hpp new file mode 100644 index 0000000000000000000000000000000000000000..f1897e145f3035d587678533f40a09fee3cda2d0 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/rational_horner2_3.hpp @@ -0,0 +1,48 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_RAT_EVAL_3_HPP +#define BOOST_MATH_TOOLS_RAT_EVAL_3_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]) / static_cast<V>(b[0]); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>((a[1] * x + a[0]) / (b[1] * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>(((a[2] * x + a[1]) * x + a[0]) / ((b[2] * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>((((a[3] * x + a[2]) * x + a[1]) * x + a[0]) / (((b[3] * x + b[2]) * x + b[1]) * x + b[0])); +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/rational_horner2_4.hpp b/Utilities/BGL/boost/math/tools/detail/rational_horner2_4.hpp new file mode 100644 index 0000000000000000000000000000000000000000..e7d6ccd13068e74326be5d48ce46f289900dd1d8 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/rational_horner2_4.hpp @@ -0,0 +1,48 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_RAT_EVAL_4_HPP +#define BOOST_MATH_TOOLS_RAT_EVAL_4_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]) / static_cast<V>(b[0]); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>((a[1] * x + a[0]) / (b[1] * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>(((a[2] * x + a[1]) * x + a[0]) / ((b[2] * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>((((a[3] * x + a[2]) * x + a[1]) * x + a[0]) / (((b[3] * x + b[2]) * x + b[1]) * x + b[0])); +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/rational_horner2_5.hpp b/Utilities/BGL/boost/math/tools/detail/rational_horner2_5.hpp new file mode 100644 index 0000000000000000000000000000000000000000..76e614918513d369f0e517c2ad258e354cb9a5cc --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/rational_horner2_5.hpp @@ -0,0 +1,64 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_RAT_EVAL_5_HPP +#define BOOST_MATH_TOOLS_RAT_EVAL_5_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]) / static_cast<V>(b[0]); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>((a[1] * x + a[0]) / (b[1] * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>(((a[2] * x + a[1]) * x + a[0]) / ((b[2] * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>((((a[3] * x + a[2]) * x + a[1]) * x + a[0]) / (((b[3] * x + b[2]) * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<5>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((a[4] * x2 + a[2]) * x2 + a[0] + (a[3] * x2 + a[1]) * x) / ((b[4] * x2 + b[2]) * x2 + b[0] + (b[3] * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((a[0] * z2 + a[2]) * z2 + a[4] + (a[1] * z2 + a[3]) * z) / ((b[0] * z2 + b[2]) * z2 + b[4] + (b[1] * z2 + b[3]) * z)); + } +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/rational_horner2_6.hpp b/Utilities/BGL/boost/math/tools/detail/rational_horner2_6.hpp new file mode 100644 index 0000000000000000000000000000000000000000..fb525fe3ad5d924c1f41a1c9b5fea6ec37790864 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/rational_horner2_6.hpp @@ -0,0 +1,80 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_RAT_EVAL_6_HPP +#define BOOST_MATH_TOOLS_RAT_EVAL_6_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]) / static_cast<V>(b[0]); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>((a[1] * x + a[0]) / (b[1] * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>(((a[2] * x + a[1]) * x + a[0]) / ((b[2] * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>((((a[3] * x + a[2]) * x + a[1]) * x + a[0]) / (((b[3] * x + b[2]) * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<5>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((a[4] * x2 + a[2]) * x2 + a[0] + (a[3] * x2 + a[1]) * x) / ((b[4] * x2 + b[2]) * x2 + b[0] + (b[3] * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((a[0] * z2 + a[2]) * z2 + a[4] + (a[1] * z2 + a[3]) * z) / ((b[0] * z2 + b[2]) * z2 + b[4] + (b[1] * z2 + b[3]) * z)); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<6>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((a[5] * x2 + a[3]) * x2 + a[1]) * x + (a[4] * x2 + a[2]) * x2 + a[0]) / (((b[5] * x2 + b[3]) * x2 + b[1]) * x + (b[4] * x2 + b[2]) * x2 + b[0])); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((a[0] * z2 + a[2]) * z2 + a[4]) * z + (a[1] * z2 + a[3]) * z2 + a[5]) / (((b[0] * z2 + b[2]) * z2 + b[4]) * z + (b[1] * z2 + b[3]) * z2 + b[5])); + } +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/rational_horner2_7.hpp b/Utilities/BGL/boost/math/tools/detail/rational_horner2_7.hpp new file mode 100644 index 0000000000000000000000000000000000000000..2bb083afee384e7eea61e58137ece07d372ca55b --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/rational_horner2_7.hpp @@ -0,0 +1,96 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_RAT_EVAL_7_HPP +#define BOOST_MATH_TOOLS_RAT_EVAL_7_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]) / static_cast<V>(b[0]); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>((a[1] * x + a[0]) / (b[1] * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>(((a[2] * x + a[1]) * x + a[0]) / ((b[2] * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>((((a[3] * x + a[2]) * x + a[1]) * x + a[0]) / (((b[3] * x + b[2]) * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<5>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((a[4] * x2 + a[2]) * x2 + a[0] + (a[3] * x2 + a[1]) * x) / ((b[4] * x2 + b[2]) * x2 + b[0] + (b[3] * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((a[0] * z2 + a[2]) * z2 + a[4] + (a[1] * z2 + a[3]) * z) / ((b[0] * z2 + b[2]) * z2 + b[4] + (b[1] * z2 + b[3]) * z)); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<6>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((a[5] * x2 + a[3]) * x2 + a[1]) * x + (a[4] * x2 + a[2]) * x2 + a[0]) / (((b[5] * x2 + b[3]) * x2 + b[1]) * x + (b[4] * x2 + b[2]) * x2 + b[0])); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((a[0] * z2 + a[2]) * z2 + a[4]) * z + (a[1] * z2 + a[3]) * z2 + a[5]) / (((b[0] * z2 + b[2]) * z2 + b[4]) * z + (b[1] * z2 + b[3]) * z2 + b[5])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<7>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((a[6] * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + ((a[5] * x2 + a[3]) * x2 + a[1]) * x) / (((b[6] * x2 + b[4]) * x2 + b[2]) * x2 + b[0] + ((b[5] * x2 + b[3]) * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6] + ((a[1] * z2 + a[3]) * z2 + a[5]) * z) / (((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6] + ((b[1] * z2 + b[3]) * z2 + b[5]) * z)); + } +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/rational_horner2_8.hpp b/Utilities/BGL/boost/math/tools/detail/rational_horner2_8.hpp new file mode 100644 index 0000000000000000000000000000000000000000..3ef0a3ad3e0694d46a72eae0b9d8ba1a90db4d94 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/rational_horner2_8.hpp @@ -0,0 +1,112 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_RAT_EVAL_8_HPP +#define BOOST_MATH_TOOLS_RAT_EVAL_8_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]) / static_cast<V>(b[0]); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>((a[1] * x + a[0]) / (b[1] * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>(((a[2] * x + a[1]) * x + a[0]) / ((b[2] * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>((((a[3] * x + a[2]) * x + a[1]) * x + a[0]) / (((b[3] * x + b[2]) * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<5>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((a[4] * x2 + a[2]) * x2 + a[0] + (a[3] * x2 + a[1]) * x) / ((b[4] * x2 + b[2]) * x2 + b[0] + (b[3] * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((a[0] * z2 + a[2]) * z2 + a[4] + (a[1] * z2 + a[3]) * z) / ((b[0] * z2 + b[2]) * z2 + b[4] + (b[1] * z2 + b[3]) * z)); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<6>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((a[5] * x2 + a[3]) * x2 + a[1]) * x + (a[4] * x2 + a[2]) * x2 + a[0]) / (((b[5] * x2 + b[3]) * x2 + b[1]) * x + (b[4] * x2 + b[2]) * x2 + b[0])); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((a[0] * z2 + a[2]) * z2 + a[4]) * z + (a[1] * z2 + a[3]) * z2 + a[5]) / (((b[0] * z2 + b[2]) * z2 + b[4]) * z + (b[1] * z2 + b[3]) * z2 + b[5])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<7>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((a[6] * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + ((a[5] * x2 + a[3]) * x2 + a[1]) * x) / (((b[6] * x2 + b[4]) * x2 + b[2]) * x2 + b[0] + ((b[5] * x2 + b[3]) * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6] + ((a[1] * z2 + a[3]) * z2 + a[5]) * z) / (((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6] + ((b[1] * z2 + b[3]) * z2 + b[5]) * z)); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<8>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((((a[7] * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + ((a[6] * x2 + a[4]) * x2 + a[2]) * x2 + a[0]) / ((((b[7] * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x + ((b[6] * x2 + b[4]) * x2 + b[2]) * x2 + b[0])); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z + ((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) / ((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z + ((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7])); + } +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/rational_horner2_9.hpp b/Utilities/BGL/boost/math/tools/detail/rational_horner2_9.hpp new file mode 100644 index 0000000000000000000000000000000000000000..424909efea9b97ba05a8f19e69a1bb909e8481f9 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/rational_horner2_9.hpp @@ -0,0 +1,128 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_RAT_EVAL_9_HPP +#define BOOST_MATH_TOOLS_RAT_EVAL_9_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]) / static_cast<V>(b[0]); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>((a[1] * x + a[0]) / (b[1] * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>(((a[2] * x + a[1]) * x + a[0]) / ((b[2] * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>((((a[3] * x + a[2]) * x + a[1]) * x + a[0]) / (((b[3] * x + b[2]) * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<5>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((a[4] * x2 + a[2]) * x2 + a[0] + (a[3] * x2 + a[1]) * x) / ((b[4] * x2 + b[2]) * x2 + b[0] + (b[3] * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((a[0] * z2 + a[2]) * z2 + a[4] + (a[1] * z2 + a[3]) * z) / ((b[0] * z2 + b[2]) * z2 + b[4] + (b[1] * z2 + b[3]) * z)); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<6>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((a[5] * x2 + a[3]) * x2 + a[1]) * x + (a[4] * x2 + a[2]) * x2 + a[0]) / (((b[5] * x2 + b[3]) * x2 + b[1]) * x + (b[4] * x2 + b[2]) * x2 + b[0])); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((a[0] * z2 + a[2]) * z2 + a[4]) * z + (a[1] * z2 + a[3]) * z2 + a[5]) / (((b[0] * z2 + b[2]) * z2 + b[4]) * z + (b[1] * z2 + b[3]) * z2 + b[5])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<7>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>((((a[6] * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + ((a[5] * x2 + a[3]) * x2 + a[1]) * x) / (((b[6] * x2 + b[4]) * x2 + b[2]) * x2 + b[0] + ((b[5] * x2 + b[3]) * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6] + ((a[1] * z2 + a[3]) * z2 + a[5]) * z) / (((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6] + ((b[1] * z2 + b[3]) * z2 + b[5]) * z)); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<8>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((((a[7] * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x + ((a[6] * x2 + a[4]) * x2 + a[2]) * x2 + a[0]) / ((((b[7] * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x + ((b[6] * x2 + b[4]) * x2 + b[2]) * x2 + b[0])); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z + ((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) / ((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z + ((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7])); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<9>*) +{ + if(x <= 1) + { + V x2 = x * x; + return static_cast<V>(((((a[8] * x2 + a[6]) * x2 + a[4]) * x2 + a[2]) * x2 + a[0] + (((a[7] * x2 + a[5]) * x2 + a[3]) * x2 + a[1]) * x) / ((((b[8] * x2 + b[6]) * x2 + b[4]) * x2 + b[2]) * x2 + b[0] + (((b[7] * x2 + b[5]) * x2 + b[3]) * x2 + b[1]) * x)); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + return static_cast<V>(((((a[0] * z2 + a[2]) * z2 + a[4]) * z2 + a[6]) * z2 + a[8] + (((a[1] * z2 + a[3]) * z2 + a[5]) * z2 + a[7]) * z) / ((((b[0] * z2 + b[2]) * z2 + b[4]) * z2 + b[6]) * z2 + b[8] + (((b[1] * z2 + b[3]) * z2 + b[5]) * z2 + b[7]) * z)); + } +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/rational_horner3_10.hpp b/Utilities/BGL/boost/math/tools/detail/rational_horner3_10.hpp new file mode 100644 index 0000000000000000000000000000000000000000..757fb091a660aaed201546b66a7cb44b5af1ee6b --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/rational_horner3_10.hpp @@ -0,0 +1,396 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_RAT_EVAL_10_HPP +#define BOOST_MATH_TOOLS_RAT_EVAL_10_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]) / static_cast<V>(b[0]); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>((a[1] * x + a[0]) / (b[1] * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>(((a[2] * x + a[1]) * x + a[0]) / ((b[2] * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>((((a[3] * x + a[2]) * x + a[1]) * x + a[0]) / (((b[3] * x + b[2]) * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<5>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[4] * x2 + a[2]; + t[1] = a[3] * x2 + a[1]; + t[2] = b[4] * x2 + b[2]; + t[3] = b[3] * x2 + b[1]; + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[4]); + t[2] += static_cast<V>(b[4]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<6>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[5] * x2 + a[3]; + t[1] = a[4] * x2 + a[2]; + t[2] = b[5] * x2 + b[3]; + t[3] = b[4] * x2 + b[2]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[1]); + t[3] += static_cast<V>(b[0]); + t[0] *= x; + t[2] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z; + t[2] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<7>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[6] * x2 + a[4]; + t[1] = a[5] * x2 + a[3]; + t[2] = b[6] * x2 + b[4]; + t[3] = b[5] * x2 + b[3]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[2] += static_cast<V>(b[2]); + t[3] += static_cast<V>(b[1]); + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[6]); + t[2] += static_cast<V>(b[6]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<8>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[7] * x2 + a[5]; + t[1] = a[6] * x2 + a[4]; + t[2] = b[7] * x2 + b[5]; + t[3] = b[6] * x2 + b[4]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[2] += static_cast<V>(b[3]); + t[3] += static_cast<V>(b[2]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[1]); + t[3] += static_cast<V>(b[0]); + t[0] *= x; + t[2] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z; + t[2] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<9>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[8] * x2 + a[6]; + t[1] = a[7] * x2 + a[5]; + t[2] = b[8] * x2 + b[6]; + t[3] = b[7] * x2 + b[5]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[3]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[2] += static_cast<V>(b[2]); + t[3] += static_cast<V>(b[1]); + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[8]); + t[2] += static_cast<V>(b[8]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<10>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[9] * x2 + a[7]; + t[1] = a[8] * x2 + a[6]; + t[2] = b[9] * x2 + b[7]; + t[3] = b[8] * x2 + b[6]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[2] += static_cast<V>(b[5]); + t[3] += static_cast<V>(b[4]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[2] += static_cast<V>(b[3]); + t[3] += static_cast<V>(b[2]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[1]); + t[3] += static_cast<V>(b[0]); + t[0] *= x; + t[2] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[9]); + t[0] *= z; + t[2] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/rational_horner3_11.hpp b/Utilities/BGL/boost/math/tools/detail/rational_horner3_11.hpp new file mode 100644 index 0000000000000000000000000000000000000000..26b7bab2de2a2144016c929aca553204d7e40b3c --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/rational_horner3_11.hpp @@ -0,0 +1,482 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_RAT_EVAL_11_HPP +#define BOOST_MATH_TOOLS_RAT_EVAL_11_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]) / static_cast<V>(b[0]); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>((a[1] * x + a[0]) / (b[1] * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>(((a[2] * x + a[1]) * x + a[0]) / ((b[2] * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>((((a[3] * x + a[2]) * x + a[1]) * x + a[0]) / (((b[3] * x + b[2]) * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<5>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[4] * x2 + a[2]; + t[1] = a[3] * x2 + a[1]; + t[2] = b[4] * x2 + b[2]; + t[3] = b[3] * x2 + b[1]; + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[4]); + t[2] += static_cast<V>(b[4]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<6>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[5] * x2 + a[3]; + t[1] = a[4] * x2 + a[2]; + t[2] = b[5] * x2 + b[3]; + t[3] = b[4] * x2 + b[2]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[1]); + t[3] += static_cast<V>(b[0]); + t[0] *= x; + t[2] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z; + t[2] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<7>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[6] * x2 + a[4]; + t[1] = a[5] * x2 + a[3]; + t[2] = b[6] * x2 + b[4]; + t[3] = b[5] * x2 + b[3]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[2] += static_cast<V>(b[2]); + t[3] += static_cast<V>(b[1]); + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[6]); + t[2] += static_cast<V>(b[6]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<8>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[7] * x2 + a[5]; + t[1] = a[6] * x2 + a[4]; + t[2] = b[7] * x2 + b[5]; + t[3] = b[6] * x2 + b[4]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[2] += static_cast<V>(b[3]); + t[3] += static_cast<V>(b[2]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[1]); + t[3] += static_cast<V>(b[0]); + t[0] *= x; + t[2] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z; + t[2] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<9>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[8] * x2 + a[6]; + t[1] = a[7] * x2 + a[5]; + t[2] = b[8] * x2 + b[6]; + t[3] = b[7] * x2 + b[5]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[3]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[2] += static_cast<V>(b[2]); + t[3] += static_cast<V>(b[1]); + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[8]); + t[2] += static_cast<V>(b[8]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<10>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[9] * x2 + a[7]; + t[1] = a[8] * x2 + a[6]; + t[2] = b[9] * x2 + b[7]; + t[3] = b[8] * x2 + b[6]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[2] += static_cast<V>(b[5]); + t[3] += static_cast<V>(b[4]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[2] += static_cast<V>(b[3]); + t[3] += static_cast<V>(b[2]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[1]); + t[3] += static_cast<V>(b[0]); + t[0] *= x; + t[2] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[9]); + t[0] *= z; + t[2] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<11>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[10] * x2 + a[8]; + t[1] = a[9] * x2 + a[7]; + t[2] = b[10] * x2 + b[8]; + t[3] = b[9] * x2 + b[7]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[5]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[3]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[2] += static_cast<V>(b[2]); + t[3] += static_cast<V>(b[1]); + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[9]); + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[10]); + t[2] += static_cast<V>(b[10]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/rational_horner3_12.hpp b/Utilities/BGL/boost/math/tools/detail/rational_horner3_12.hpp new file mode 100644 index 0000000000000000000000000000000000000000..2bcb20c353a7ddf0b0d82f06096a95b89f8276ba --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/rational_horner3_12.hpp @@ -0,0 +1,576 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_RAT_EVAL_12_HPP +#define BOOST_MATH_TOOLS_RAT_EVAL_12_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]) / static_cast<V>(b[0]); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>((a[1] * x + a[0]) / (b[1] * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>(((a[2] * x + a[1]) * x + a[0]) / ((b[2] * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>((((a[3] * x + a[2]) * x + a[1]) * x + a[0]) / (((b[3] * x + b[2]) * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<5>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[4] * x2 + a[2]; + t[1] = a[3] * x2 + a[1]; + t[2] = b[4] * x2 + b[2]; + t[3] = b[3] * x2 + b[1]; + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[4]); + t[2] += static_cast<V>(b[4]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<6>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[5] * x2 + a[3]; + t[1] = a[4] * x2 + a[2]; + t[2] = b[5] * x2 + b[3]; + t[3] = b[4] * x2 + b[2]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[1]); + t[3] += static_cast<V>(b[0]); + t[0] *= x; + t[2] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z; + t[2] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<7>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[6] * x2 + a[4]; + t[1] = a[5] * x2 + a[3]; + t[2] = b[6] * x2 + b[4]; + t[3] = b[5] * x2 + b[3]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[2] += static_cast<V>(b[2]); + t[3] += static_cast<V>(b[1]); + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[6]); + t[2] += static_cast<V>(b[6]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<8>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[7] * x2 + a[5]; + t[1] = a[6] * x2 + a[4]; + t[2] = b[7] * x2 + b[5]; + t[3] = b[6] * x2 + b[4]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[2] += static_cast<V>(b[3]); + t[3] += static_cast<V>(b[2]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[1]); + t[3] += static_cast<V>(b[0]); + t[0] *= x; + t[2] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z; + t[2] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<9>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[8] * x2 + a[6]; + t[1] = a[7] * x2 + a[5]; + t[2] = b[8] * x2 + b[6]; + t[3] = b[7] * x2 + b[5]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[3]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[2] += static_cast<V>(b[2]); + t[3] += static_cast<V>(b[1]); + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[8]); + t[2] += static_cast<V>(b[8]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<10>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[9] * x2 + a[7]; + t[1] = a[8] * x2 + a[6]; + t[2] = b[9] * x2 + b[7]; + t[3] = b[8] * x2 + b[6]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[2] += static_cast<V>(b[5]); + t[3] += static_cast<V>(b[4]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[2] += static_cast<V>(b[3]); + t[3] += static_cast<V>(b[2]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[1]); + t[3] += static_cast<V>(b[0]); + t[0] *= x; + t[2] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[9]); + t[0] *= z; + t[2] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<11>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[10] * x2 + a[8]; + t[1] = a[9] * x2 + a[7]; + t[2] = b[10] * x2 + b[8]; + t[3] = b[9] * x2 + b[7]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[5]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[3]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[2] += static_cast<V>(b[2]); + t[3] += static_cast<V>(b[1]); + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[9]); + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[10]); + t[2] += static_cast<V>(b[10]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<12>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[11] * x2 + a[9]; + t[1] = a[10] * x2 + a[8]; + t[2] = b[11] * x2 + b[9]; + t[3] = b[10] * x2 + b[8]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[7]); + t[1] += static_cast<V>(a[6]); + t[2] += static_cast<V>(b[7]); + t[3] += static_cast<V>(b[6]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[2] += static_cast<V>(b[5]); + t[3] += static_cast<V>(b[4]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[2] += static_cast<V>(b[3]); + t[3] += static_cast<V>(b[2]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[1]); + t[3] += static_cast<V>(b[0]); + t[0] *= x; + t[2] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[9]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[11]); + t[2] += static_cast<V>(b[10]); + t[3] += static_cast<V>(b[11]); + t[0] *= z; + t[2] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/rational_horner3_13.hpp b/Utilities/BGL/boost/math/tools/detail/rational_horner3_13.hpp new file mode 100644 index 0000000000000000000000000000000000000000..b218c2aee316af37469531acf5327d5cbbb283e9 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/rational_horner3_13.hpp @@ -0,0 +1,678 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_RAT_EVAL_13_HPP +#define BOOST_MATH_TOOLS_RAT_EVAL_13_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]) / static_cast<V>(b[0]); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>((a[1] * x + a[0]) / (b[1] * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>(((a[2] * x + a[1]) * x + a[0]) / ((b[2] * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>((((a[3] * x + a[2]) * x + a[1]) * x + a[0]) / (((b[3] * x + b[2]) * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<5>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[4] * x2 + a[2]; + t[1] = a[3] * x2 + a[1]; + t[2] = b[4] * x2 + b[2]; + t[3] = b[3] * x2 + b[1]; + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[4]); + t[2] += static_cast<V>(b[4]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<6>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[5] * x2 + a[3]; + t[1] = a[4] * x2 + a[2]; + t[2] = b[5] * x2 + b[3]; + t[3] = b[4] * x2 + b[2]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[1]); + t[3] += static_cast<V>(b[0]); + t[0] *= x; + t[2] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z; + t[2] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<7>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[6] * x2 + a[4]; + t[1] = a[5] * x2 + a[3]; + t[2] = b[6] * x2 + b[4]; + t[3] = b[5] * x2 + b[3]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[2] += static_cast<V>(b[2]); + t[3] += static_cast<V>(b[1]); + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[6]); + t[2] += static_cast<V>(b[6]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<8>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[7] * x2 + a[5]; + t[1] = a[6] * x2 + a[4]; + t[2] = b[7] * x2 + b[5]; + t[3] = b[6] * x2 + b[4]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[2] += static_cast<V>(b[3]); + t[3] += static_cast<V>(b[2]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[1]); + t[3] += static_cast<V>(b[0]); + t[0] *= x; + t[2] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z; + t[2] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<9>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[8] * x2 + a[6]; + t[1] = a[7] * x2 + a[5]; + t[2] = b[8] * x2 + b[6]; + t[3] = b[7] * x2 + b[5]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[3]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[2] += static_cast<V>(b[2]); + t[3] += static_cast<V>(b[1]); + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[8]); + t[2] += static_cast<V>(b[8]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<10>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[9] * x2 + a[7]; + t[1] = a[8] * x2 + a[6]; + t[2] = b[9] * x2 + b[7]; + t[3] = b[8] * x2 + b[6]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[2] += static_cast<V>(b[5]); + t[3] += static_cast<V>(b[4]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[2] += static_cast<V>(b[3]); + t[3] += static_cast<V>(b[2]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[1]); + t[3] += static_cast<V>(b[0]); + t[0] *= x; + t[2] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[9]); + t[0] *= z; + t[2] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<11>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[10] * x2 + a[8]; + t[1] = a[9] * x2 + a[7]; + t[2] = b[10] * x2 + b[8]; + t[3] = b[9] * x2 + b[7]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[5]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[3]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[2] += static_cast<V>(b[2]); + t[3] += static_cast<V>(b[1]); + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[9]); + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[10]); + t[2] += static_cast<V>(b[10]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<12>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[11] * x2 + a[9]; + t[1] = a[10] * x2 + a[8]; + t[2] = b[11] * x2 + b[9]; + t[3] = b[10] * x2 + b[8]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[7]); + t[1] += static_cast<V>(a[6]); + t[2] += static_cast<V>(b[7]); + t[3] += static_cast<V>(b[6]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[2] += static_cast<V>(b[5]); + t[3] += static_cast<V>(b[4]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[2] += static_cast<V>(b[3]); + t[3] += static_cast<V>(b[2]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[1]); + t[3] += static_cast<V>(b[0]); + t[0] *= x; + t[2] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[9]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[11]); + t[2] += static_cast<V>(b[10]); + t[3] += static_cast<V>(b[11]); + t[0] *= z; + t[2] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<13>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[12] * x2 + a[10]; + t[1] = a[11] * x2 + a[9]; + t[2] = b[12] * x2 + b[10]; + t[3] = b[11] * x2 + b[9]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[7]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[5]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[3]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[2] += static_cast<V>(b[2]); + t[3] += static_cast<V>(b[1]); + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[9]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[11]); + t[2] += static_cast<V>(b[10]); + t[3] += static_cast<V>(b[11]); + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[12]); + t[2] += static_cast<V>(b[12]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/rational_horner3_14.hpp b/Utilities/BGL/boost/math/tools/detail/rational_horner3_14.hpp new file mode 100644 index 0000000000000000000000000000000000000000..319cf6edeff62098f375ca5979520e00054d215b --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/rational_horner3_14.hpp @@ -0,0 +1,788 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_RAT_EVAL_14_HPP +#define BOOST_MATH_TOOLS_RAT_EVAL_14_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]) / static_cast<V>(b[0]); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>((a[1] * x + a[0]) / (b[1] * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>(((a[2] * x + a[1]) * x + a[0]) / ((b[2] * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>((((a[3] * x + a[2]) * x + a[1]) * x + a[0]) / (((b[3] * x + b[2]) * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<5>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[4] * x2 + a[2]; + t[1] = a[3] * x2 + a[1]; + t[2] = b[4] * x2 + b[2]; + t[3] = b[3] * x2 + b[1]; + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[4]); + t[2] += static_cast<V>(b[4]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<6>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[5] * x2 + a[3]; + t[1] = a[4] * x2 + a[2]; + t[2] = b[5] * x2 + b[3]; + t[3] = b[4] * x2 + b[2]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[1]); + t[3] += static_cast<V>(b[0]); + t[0] *= x; + t[2] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z; + t[2] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<7>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[6] * x2 + a[4]; + t[1] = a[5] * x2 + a[3]; + t[2] = b[6] * x2 + b[4]; + t[3] = b[5] * x2 + b[3]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[2] += static_cast<V>(b[2]); + t[3] += static_cast<V>(b[1]); + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[6]); + t[2] += static_cast<V>(b[6]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<8>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[7] * x2 + a[5]; + t[1] = a[6] * x2 + a[4]; + t[2] = b[7] * x2 + b[5]; + t[3] = b[6] * x2 + b[4]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[2] += static_cast<V>(b[3]); + t[3] += static_cast<V>(b[2]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[1]); + t[3] += static_cast<V>(b[0]); + t[0] *= x; + t[2] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z; + t[2] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<9>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[8] * x2 + a[6]; + t[1] = a[7] * x2 + a[5]; + t[2] = b[8] * x2 + b[6]; + t[3] = b[7] * x2 + b[5]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[3]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[2] += static_cast<V>(b[2]); + t[3] += static_cast<V>(b[1]); + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[8]); + t[2] += static_cast<V>(b[8]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<10>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[9] * x2 + a[7]; + t[1] = a[8] * x2 + a[6]; + t[2] = b[9] * x2 + b[7]; + t[3] = b[8] * x2 + b[6]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[2] += static_cast<V>(b[5]); + t[3] += static_cast<V>(b[4]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[2] += static_cast<V>(b[3]); + t[3] += static_cast<V>(b[2]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[1]); + t[3] += static_cast<V>(b[0]); + t[0] *= x; + t[2] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[9]); + t[0] *= z; + t[2] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<11>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[10] * x2 + a[8]; + t[1] = a[9] * x2 + a[7]; + t[2] = b[10] * x2 + b[8]; + t[3] = b[9] * x2 + b[7]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[5]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[3]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[2] += static_cast<V>(b[2]); + t[3] += static_cast<V>(b[1]); + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[9]); + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[10]); + t[2] += static_cast<V>(b[10]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<12>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[11] * x2 + a[9]; + t[1] = a[10] * x2 + a[8]; + t[2] = b[11] * x2 + b[9]; + t[3] = b[10] * x2 + b[8]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[7]); + t[1] += static_cast<V>(a[6]); + t[2] += static_cast<V>(b[7]); + t[3] += static_cast<V>(b[6]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[2] += static_cast<V>(b[5]); + t[3] += static_cast<V>(b[4]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[2] += static_cast<V>(b[3]); + t[3] += static_cast<V>(b[2]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[1]); + t[3] += static_cast<V>(b[0]); + t[0] *= x; + t[2] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[9]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[11]); + t[2] += static_cast<V>(b[10]); + t[3] += static_cast<V>(b[11]); + t[0] *= z; + t[2] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<13>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[12] * x2 + a[10]; + t[1] = a[11] * x2 + a[9]; + t[2] = b[12] * x2 + b[10]; + t[3] = b[11] * x2 + b[9]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[7]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[5]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[3]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[2] += static_cast<V>(b[2]); + t[3] += static_cast<V>(b[1]); + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[9]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[11]); + t[2] += static_cast<V>(b[10]); + t[3] += static_cast<V>(b[11]); + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[12]); + t[2] += static_cast<V>(b[12]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<14>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[13] * x2 + a[11]; + t[1] = a[12] * x2 + a[10]; + t[2] = b[13] * x2 + b[11]; + t[3] = b[12] * x2 + b[10]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[9]); + t[1] += static_cast<V>(a[8]); + t[2] += static_cast<V>(b[9]); + t[3] += static_cast<V>(b[8]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[7]); + t[1] += static_cast<V>(a[6]); + t[2] += static_cast<V>(b[7]); + t[3] += static_cast<V>(b[6]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[2] += static_cast<V>(b[5]); + t[3] += static_cast<V>(b[4]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[2] += static_cast<V>(b[3]); + t[3] += static_cast<V>(b[2]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[1]); + t[3] += static_cast<V>(b[0]); + t[0] *= x; + t[2] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[9]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[11]); + t[2] += static_cast<V>(b[10]); + t[3] += static_cast<V>(b[11]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[12]); + t[1] += static_cast<V>(a[13]); + t[2] += static_cast<V>(b[12]); + t[3] += static_cast<V>(b[13]); + t[0] *= z; + t[2] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/rational_horner3_15.hpp b/Utilities/BGL/boost/math/tools/detail/rational_horner3_15.hpp new file mode 100644 index 0000000000000000000000000000000000000000..06ed68db92b2d4ab719c20d8d82168d1becee492 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/rational_horner3_15.hpp @@ -0,0 +1,906 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_RAT_EVAL_15_HPP +#define BOOST_MATH_TOOLS_RAT_EVAL_15_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]) / static_cast<V>(b[0]); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>((a[1] * x + a[0]) / (b[1] * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>(((a[2] * x + a[1]) * x + a[0]) / ((b[2] * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>((((a[3] * x + a[2]) * x + a[1]) * x + a[0]) / (((b[3] * x + b[2]) * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<5>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[4] * x2 + a[2]; + t[1] = a[3] * x2 + a[1]; + t[2] = b[4] * x2 + b[2]; + t[3] = b[3] * x2 + b[1]; + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[4]); + t[2] += static_cast<V>(b[4]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<6>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[5] * x2 + a[3]; + t[1] = a[4] * x2 + a[2]; + t[2] = b[5] * x2 + b[3]; + t[3] = b[4] * x2 + b[2]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[1]); + t[3] += static_cast<V>(b[0]); + t[0] *= x; + t[2] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z; + t[2] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<7>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[6] * x2 + a[4]; + t[1] = a[5] * x2 + a[3]; + t[2] = b[6] * x2 + b[4]; + t[3] = b[5] * x2 + b[3]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[2] += static_cast<V>(b[2]); + t[3] += static_cast<V>(b[1]); + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[6]); + t[2] += static_cast<V>(b[6]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<8>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[7] * x2 + a[5]; + t[1] = a[6] * x2 + a[4]; + t[2] = b[7] * x2 + b[5]; + t[3] = b[6] * x2 + b[4]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[2] += static_cast<V>(b[3]); + t[3] += static_cast<V>(b[2]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[1]); + t[3] += static_cast<V>(b[0]); + t[0] *= x; + t[2] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z; + t[2] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<9>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[8] * x2 + a[6]; + t[1] = a[7] * x2 + a[5]; + t[2] = b[8] * x2 + b[6]; + t[3] = b[7] * x2 + b[5]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[3]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[2] += static_cast<V>(b[2]); + t[3] += static_cast<V>(b[1]); + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[8]); + t[2] += static_cast<V>(b[8]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<10>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[9] * x2 + a[7]; + t[1] = a[8] * x2 + a[6]; + t[2] = b[9] * x2 + b[7]; + t[3] = b[8] * x2 + b[6]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[2] += static_cast<V>(b[5]); + t[3] += static_cast<V>(b[4]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[2] += static_cast<V>(b[3]); + t[3] += static_cast<V>(b[2]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[1]); + t[3] += static_cast<V>(b[0]); + t[0] *= x; + t[2] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[9]); + t[0] *= z; + t[2] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<11>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[10] * x2 + a[8]; + t[1] = a[9] * x2 + a[7]; + t[2] = b[10] * x2 + b[8]; + t[3] = b[9] * x2 + b[7]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[5]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[3]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[2] += static_cast<V>(b[2]); + t[3] += static_cast<V>(b[1]); + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[9]); + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[10]); + t[2] += static_cast<V>(b[10]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<12>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[11] * x2 + a[9]; + t[1] = a[10] * x2 + a[8]; + t[2] = b[11] * x2 + b[9]; + t[3] = b[10] * x2 + b[8]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[7]); + t[1] += static_cast<V>(a[6]); + t[2] += static_cast<V>(b[7]); + t[3] += static_cast<V>(b[6]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[2] += static_cast<V>(b[5]); + t[3] += static_cast<V>(b[4]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[2] += static_cast<V>(b[3]); + t[3] += static_cast<V>(b[2]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[1]); + t[3] += static_cast<V>(b[0]); + t[0] *= x; + t[2] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[9]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[11]); + t[2] += static_cast<V>(b[10]); + t[3] += static_cast<V>(b[11]); + t[0] *= z; + t[2] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<13>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[12] * x2 + a[10]; + t[1] = a[11] * x2 + a[9]; + t[2] = b[12] * x2 + b[10]; + t[3] = b[11] * x2 + b[9]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[7]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[5]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[3]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[2] += static_cast<V>(b[2]); + t[3] += static_cast<V>(b[1]); + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[9]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[11]); + t[2] += static_cast<V>(b[10]); + t[3] += static_cast<V>(b[11]); + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[12]); + t[2] += static_cast<V>(b[12]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<14>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[13] * x2 + a[11]; + t[1] = a[12] * x2 + a[10]; + t[2] = b[13] * x2 + b[11]; + t[3] = b[12] * x2 + b[10]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[9]); + t[1] += static_cast<V>(a[8]); + t[2] += static_cast<V>(b[9]); + t[3] += static_cast<V>(b[8]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[7]); + t[1] += static_cast<V>(a[6]); + t[2] += static_cast<V>(b[7]); + t[3] += static_cast<V>(b[6]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[2] += static_cast<V>(b[5]); + t[3] += static_cast<V>(b[4]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[2] += static_cast<V>(b[3]); + t[3] += static_cast<V>(b[2]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[1]); + t[3] += static_cast<V>(b[0]); + t[0] *= x; + t[2] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[9]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[11]); + t[2] += static_cast<V>(b[10]); + t[3] += static_cast<V>(b[11]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[12]); + t[1] += static_cast<V>(a[13]); + t[2] += static_cast<V>(b[12]); + t[3] += static_cast<V>(b[13]); + t[0] *= z; + t[2] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<15>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[14] * x2 + a[12]; + t[1] = a[13] * x2 + a[11]; + t[2] = b[14] * x2 + b[12]; + t[3] = b[13] * x2 + b[11]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[10]); + t[3] += static_cast<V>(b[9]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[7]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[5]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[3]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[2] += static_cast<V>(b[2]); + t[3] += static_cast<V>(b[1]); + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[9]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[11]); + t[2] += static_cast<V>(b[10]); + t[3] += static_cast<V>(b[11]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[12]); + t[1] += static_cast<V>(a[13]); + t[2] += static_cast<V>(b[12]); + t[3] += static_cast<V>(b[13]); + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[14]); + t[2] += static_cast<V>(b[14]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/rational_horner3_16.hpp b/Utilities/BGL/boost/math/tools/detail/rational_horner3_16.hpp new file mode 100644 index 0000000000000000000000000000000000000000..9bad7fce810fa3c12a8fab8449799802787b8dd7 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/rational_horner3_16.hpp @@ -0,0 +1,1032 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_RAT_EVAL_16_HPP +#define BOOST_MATH_TOOLS_RAT_EVAL_16_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]) / static_cast<V>(b[0]); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>((a[1] * x + a[0]) / (b[1] * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>(((a[2] * x + a[1]) * x + a[0]) / ((b[2] * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>((((a[3] * x + a[2]) * x + a[1]) * x + a[0]) / (((b[3] * x + b[2]) * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<5>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[4] * x2 + a[2]; + t[1] = a[3] * x2 + a[1]; + t[2] = b[4] * x2 + b[2]; + t[3] = b[3] * x2 + b[1]; + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[4]); + t[2] += static_cast<V>(b[4]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<6>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[5] * x2 + a[3]; + t[1] = a[4] * x2 + a[2]; + t[2] = b[5] * x2 + b[3]; + t[3] = b[4] * x2 + b[2]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[1]); + t[3] += static_cast<V>(b[0]); + t[0] *= x; + t[2] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z; + t[2] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<7>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[6] * x2 + a[4]; + t[1] = a[5] * x2 + a[3]; + t[2] = b[6] * x2 + b[4]; + t[3] = b[5] * x2 + b[3]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[2] += static_cast<V>(b[2]); + t[3] += static_cast<V>(b[1]); + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[6]); + t[2] += static_cast<V>(b[6]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<8>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[7] * x2 + a[5]; + t[1] = a[6] * x2 + a[4]; + t[2] = b[7] * x2 + b[5]; + t[3] = b[6] * x2 + b[4]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[2] += static_cast<V>(b[3]); + t[3] += static_cast<V>(b[2]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[1]); + t[3] += static_cast<V>(b[0]); + t[0] *= x; + t[2] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z; + t[2] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<9>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[8] * x2 + a[6]; + t[1] = a[7] * x2 + a[5]; + t[2] = b[8] * x2 + b[6]; + t[3] = b[7] * x2 + b[5]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[3]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[2] += static_cast<V>(b[2]); + t[3] += static_cast<V>(b[1]); + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[8]); + t[2] += static_cast<V>(b[8]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<10>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[9] * x2 + a[7]; + t[1] = a[8] * x2 + a[6]; + t[2] = b[9] * x2 + b[7]; + t[3] = b[8] * x2 + b[6]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[2] += static_cast<V>(b[5]); + t[3] += static_cast<V>(b[4]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[2] += static_cast<V>(b[3]); + t[3] += static_cast<V>(b[2]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[1]); + t[3] += static_cast<V>(b[0]); + t[0] *= x; + t[2] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[9]); + t[0] *= z; + t[2] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<11>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[10] * x2 + a[8]; + t[1] = a[9] * x2 + a[7]; + t[2] = b[10] * x2 + b[8]; + t[3] = b[9] * x2 + b[7]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[5]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[3]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[2] += static_cast<V>(b[2]); + t[3] += static_cast<V>(b[1]); + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[9]); + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[10]); + t[2] += static_cast<V>(b[10]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<12>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[11] * x2 + a[9]; + t[1] = a[10] * x2 + a[8]; + t[2] = b[11] * x2 + b[9]; + t[3] = b[10] * x2 + b[8]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[7]); + t[1] += static_cast<V>(a[6]); + t[2] += static_cast<V>(b[7]); + t[3] += static_cast<V>(b[6]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[2] += static_cast<V>(b[5]); + t[3] += static_cast<V>(b[4]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[2] += static_cast<V>(b[3]); + t[3] += static_cast<V>(b[2]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[1]); + t[3] += static_cast<V>(b[0]); + t[0] *= x; + t[2] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[9]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[11]); + t[2] += static_cast<V>(b[10]); + t[3] += static_cast<V>(b[11]); + t[0] *= z; + t[2] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<13>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[12] * x2 + a[10]; + t[1] = a[11] * x2 + a[9]; + t[2] = b[12] * x2 + b[10]; + t[3] = b[11] * x2 + b[9]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[7]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[5]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[3]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[2] += static_cast<V>(b[2]); + t[3] += static_cast<V>(b[1]); + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[9]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[11]); + t[2] += static_cast<V>(b[10]); + t[3] += static_cast<V>(b[11]); + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[12]); + t[2] += static_cast<V>(b[12]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<14>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[13] * x2 + a[11]; + t[1] = a[12] * x2 + a[10]; + t[2] = b[13] * x2 + b[11]; + t[3] = b[12] * x2 + b[10]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[9]); + t[1] += static_cast<V>(a[8]); + t[2] += static_cast<V>(b[9]); + t[3] += static_cast<V>(b[8]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[7]); + t[1] += static_cast<V>(a[6]); + t[2] += static_cast<V>(b[7]); + t[3] += static_cast<V>(b[6]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[2] += static_cast<V>(b[5]); + t[3] += static_cast<V>(b[4]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[2] += static_cast<V>(b[3]); + t[3] += static_cast<V>(b[2]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[1]); + t[3] += static_cast<V>(b[0]); + t[0] *= x; + t[2] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[9]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[11]); + t[2] += static_cast<V>(b[10]); + t[3] += static_cast<V>(b[11]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[12]); + t[1] += static_cast<V>(a[13]); + t[2] += static_cast<V>(b[12]); + t[3] += static_cast<V>(b[13]); + t[0] *= z; + t[2] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<15>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[14] * x2 + a[12]; + t[1] = a[13] * x2 + a[11]; + t[2] = b[14] * x2 + b[12]; + t[3] = b[13] * x2 + b[11]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[10]); + t[3] += static_cast<V>(b[9]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[7]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[5]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[3]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[2] += static_cast<V>(b[2]); + t[3] += static_cast<V>(b[1]); + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[9]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[11]); + t[2] += static_cast<V>(b[10]); + t[3] += static_cast<V>(b[11]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[12]); + t[1] += static_cast<V>(a[13]); + t[2] += static_cast<V>(b[12]); + t[3] += static_cast<V>(b[13]); + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[14]); + t[2] += static_cast<V>(b[14]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<16>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[15] * x2 + a[13]; + t[1] = a[14] * x2 + a[12]; + t[2] = b[15] * x2 + b[13]; + t[3] = b[14] * x2 + b[12]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[11]); + t[1] += static_cast<V>(a[10]); + t[2] += static_cast<V>(b[11]); + t[3] += static_cast<V>(b[10]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[9]); + t[1] += static_cast<V>(a[8]); + t[2] += static_cast<V>(b[9]); + t[3] += static_cast<V>(b[8]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[7]); + t[1] += static_cast<V>(a[6]); + t[2] += static_cast<V>(b[7]); + t[3] += static_cast<V>(b[6]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[2] += static_cast<V>(b[5]); + t[3] += static_cast<V>(b[4]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[2] += static_cast<V>(b[3]); + t[3] += static_cast<V>(b[2]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[1]); + t[3] += static_cast<V>(b[0]); + t[0] *= x; + t[2] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[9]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[11]); + t[2] += static_cast<V>(b[10]); + t[3] += static_cast<V>(b[11]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[12]); + t[1] += static_cast<V>(a[13]); + t[2] += static_cast<V>(b[12]); + t[3] += static_cast<V>(b[13]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[14]); + t[1] += static_cast<V>(a[15]); + t[2] += static_cast<V>(b[14]); + t[3] += static_cast<V>(b[15]); + t[0] *= z; + t[2] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/rational_horner3_17.hpp b/Utilities/BGL/boost/math/tools/detail/rational_horner3_17.hpp new file mode 100644 index 0000000000000000000000000000000000000000..cb82af4e078cf40fee5b5282d7c426a972252ae6 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/rational_horner3_17.hpp @@ -0,0 +1,1166 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_RAT_EVAL_17_HPP +#define BOOST_MATH_TOOLS_RAT_EVAL_17_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]) / static_cast<V>(b[0]); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>((a[1] * x + a[0]) / (b[1] * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>(((a[2] * x + a[1]) * x + a[0]) / ((b[2] * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>((((a[3] * x + a[2]) * x + a[1]) * x + a[0]) / (((b[3] * x + b[2]) * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<5>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[4] * x2 + a[2]; + t[1] = a[3] * x2 + a[1]; + t[2] = b[4] * x2 + b[2]; + t[3] = b[3] * x2 + b[1]; + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[4]); + t[2] += static_cast<V>(b[4]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<6>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[5] * x2 + a[3]; + t[1] = a[4] * x2 + a[2]; + t[2] = b[5] * x2 + b[3]; + t[3] = b[4] * x2 + b[2]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[1]); + t[3] += static_cast<V>(b[0]); + t[0] *= x; + t[2] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z; + t[2] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<7>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[6] * x2 + a[4]; + t[1] = a[5] * x2 + a[3]; + t[2] = b[6] * x2 + b[4]; + t[3] = b[5] * x2 + b[3]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[2] += static_cast<V>(b[2]); + t[3] += static_cast<V>(b[1]); + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[6]); + t[2] += static_cast<V>(b[6]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<8>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[7] * x2 + a[5]; + t[1] = a[6] * x2 + a[4]; + t[2] = b[7] * x2 + b[5]; + t[3] = b[6] * x2 + b[4]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[2] += static_cast<V>(b[3]); + t[3] += static_cast<V>(b[2]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[1]); + t[3] += static_cast<V>(b[0]); + t[0] *= x; + t[2] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z; + t[2] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<9>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[8] * x2 + a[6]; + t[1] = a[7] * x2 + a[5]; + t[2] = b[8] * x2 + b[6]; + t[3] = b[7] * x2 + b[5]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[3]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[2] += static_cast<V>(b[2]); + t[3] += static_cast<V>(b[1]); + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[8]); + t[2] += static_cast<V>(b[8]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<10>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[9] * x2 + a[7]; + t[1] = a[8] * x2 + a[6]; + t[2] = b[9] * x2 + b[7]; + t[3] = b[8] * x2 + b[6]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[2] += static_cast<V>(b[5]); + t[3] += static_cast<V>(b[4]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[2] += static_cast<V>(b[3]); + t[3] += static_cast<V>(b[2]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[1]); + t[3] += static_cast<V>(b[0]); + t[0] *= x; + t[2] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[9]); + t[0] *= z; + t[2] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<11>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[10] * x2 + a[8]; + t[1] = a[9] * x2 + a[7]; + t[2] = b[10] * x2 + b[8]; + t[3] = b[9] * x2 + b[7]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[5]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[3]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[2] += static_cast<V>(b[2]); + t[3] += static_cast<V>(b[1]); + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[9]); + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[10]); + t[2] += static_cast<V>(b[10]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<12>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[11] * x2 + a[9]; + t[1] = a[10] * x2 + a[8]; + t[2] = b[11] * x2 + b[9]; + t[3] = b[10] * x2 + b[8]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[7]); + t[1] += static_cast<V>(a[6]); + t[2] += static_cast<V>(b[7]); + t[3] += static_cast<V>(b[6]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[2] += static_cast<V>(b[5]); + t[3] += static_cast<V>(b[4]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[2] += static_cast<V>(b[3]); + t[3] += static_cast<V>(b[2]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[1]); + t[3] += static_cast<V>(b[0]); + t[0] *= x; + t[2] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[9]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[11]); + t[2] += static_cast<V>(b[10]); + t[3] += static_cast<V>(b[11]); + t[0] *= z; + t[2] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<13>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[12] * x2 + a[10]; + t[1] = a[11] * x2 + a[9]; + t[2] = b[12] * x2 + b[10]; + t[3] = b[11] * x2 + b[9]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[7]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[5]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[3]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[2] += static_cast<V>(b[2]); + t[3] += static_cast<V>(b[1]); + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[9]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[11]); + t[2] += static_cast<V>(b[10]); + t[3] += static_cast<V>(b[11]); + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[12]); + t[2] += static_cast<V>(b[12]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<14>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[13] * x2 + a[11]; + t[1] = a[12] * x2 + a[10]; + t[2] = b[13] * x2 + b[11]; + t[3] = b[12] * x2 + b[10]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[9]); + t[1] += static_cast<V>(a[8]); + t[2] += static_cast<V>(b[9]); + t[3] += static_cast<V>(b[8]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[7]); + t[1] += static_cast<V>(a[6]); + t[2] += static_cast<V>(b[7]); + t[3] += static_cast<V>(b[6]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[2] += static_cast<V>(b[5]); + t[3] += static_cast<V>(b[4]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[2] += static_cast<V>(b[3]); + t[3] += static_cast<V>(b[2]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[1]); + t[3] += static_cast<V>(b[0]); + t[0] *= x; + t[2] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[9]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[11]); + t[2] += static_cast<V>(b[10]); + t[3] += static_cast<V>(b[11]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[12]); + t[1] += static_cast<V>(a[13]); + t[2] += static_cast<V>(b[12]); + t[3] += static_cast<V>(b[13]); + t[0] *= z; + t[2] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<15>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[14] * x2 + a[12]; + t[1] = a[13] * x2 + a[11]; + t[2] = b[14] * x2 + b[12]; + t[3] = b[13] * x2 + b[11]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[10]); + t[3] += static_cast<V>(b[9]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[7]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[5]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[3]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[2] += static_cast<V>(b[2]); + t[3] += static_cast<V>(b[1]); + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[9]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[11]); + t[2] += static_cast<V>(b[10]); + t[3] += static_cast<V>(b[11]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[12]); + t[1] += static_cast<V>(a[13]); + t[2] += static_cast<V>(b[12]); + t[3] += static_cast<V>(b[13]); + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[14]); + t[2] += static_cast<V>(b[14]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<16>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[15] * x2 + a[13]; + t[1] = a[14] * x2 + a[12]; + t[2] = b[15] * x2 + b[13]; + t[3] = b[14] * x2 + b[12]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[11]); + t[1] += static_cast<V>(a[10]); + t[2] += static_cast<V>(b[11]); + t[3] += static_cast<V>(b[10]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[9]); + t[1] += static_cast<V>(a[8]); + t[2] += static_cast<V>(b[9]); + t[3] += static_cast<V>(b[8]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[7]); + t[1] += static_cast<V>(a[6]); + t[2] += static_cast<V>(b[7]); + t[3] += static_cast<V>(b[6]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[2] += static_cast<V>(b[5]); + t[3] += static_cast<V>(b[4]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[2] += static_cast<V>(b[3]); + t[3] += static_cast<V>(b[2]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[1]); + t[3] += static_cast<V>(b[0]); + t[0] *= x; + t[2] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[9]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[11]); + t[2] += static_cast<V>(b[10]); + t[3] += static_cast<V>(b[11]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[12]); + t[1] += static_cast<V>(a[13]); + t[2] += static_cast<V>(b[12]); + t[3] += static_cast<V>(b[13]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[14]); + t[1] += static_cast<V>(a[15]); + t[2] += static_cast<V>(b[14]); + t[3] += static_cast<V>(b[15]); + t[0] *= z; + t[2] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<17>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[16] * x2 + a[14]; + t[1] = a[15] * x2 + a[13]; + t[2] = b[16] * x2 + b[14]; + t[3] = b[15] * x2 + b[13]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[12]); + t[1] += static_cast<V>(a[11]); + t[2] += static_cast<V>(b[12]); + t[3] += static_cast<V>(b[11]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[10]); + t[3] += static_cast<V>(b[9]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[7]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[5]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[3]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[2] += static_cast<V>(b[2]); + t[3] += static_cast<V>(b[1]); + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[9]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[11]); + t[2] += static_cast<V>(b[10]); + t[3] += static_cast<V>(b[11]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[12]); + t[1] += static_cast<V>(a[13]); + t[2] += static_cast<V>(b[12]); + t[3] += static_cast<V>(b[13]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[14]); + t[1] += static_cast<V>(a[15]); + t[2] += static_cast<V>(b[14]); + t[3] += static_cast<V>(b[15]); + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[16]); + t[2] += static_cast<V>(b[16]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/rational_horner3_18.hpp b/Utilities/BGL/boost/math/tools/detail/rational_horner3_18.hpp new file mode 100644 index 0000000000000000000000000000000000000000..055e2049cc4f7f4fe46ac503137c60f48e515d20 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/rational_horner3_18.hpp @@ -0,0 +1,1308 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_RAT_EVAL_18_HPP +#define BOOST_MATH_TOOLS_RAT_EVAL_18_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]) / static_cast<V>(b[0]); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>((a[1] * x + a[0]) / (b[1] * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>(((a[2] * x + a[1]) * x + a[0]) / ((b[2] * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>((((a[3] * x + a[2]) * x + a[1]) * x + a[0]) / (((b[3] * x + b[2]) * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<5>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[4] * x2 + a[2]; + t[1] = a[3] * x2 + a[1]; + t[2] = b[4] * x2 + b[2]; + t[3] = b[3] * x2 + b[1]; + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[4]); + t[2] += static_cast<V>(b[4]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<6>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[5] * x2 + a[3]; + t[1] = a[4] * x2 + a[2]; + t[2] = b[5] * x2 + b[3]; + t[3] = b[4] * x2 + b[2]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[1]); + t[3] += static_cast<V>(b[0]); + t[0] *= x; + t[2] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z; + t[2] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<7>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[6] * x2 + a[4]; + t[1] = a[5] * x2 + a[3]; + t[2] = b[6] * x2 + b[4]; + t[3] = b[5] * x2 + b[3]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[2] += static_cast<V>(b[2]); + t[3] += static_cast<V>(b[1]); + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[6]); + t[2] += static_cast<V>(b[6]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<8>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[7] * x2 + a[5]; + t[1] = a[6] * x2 + a[4]; + t[2] = b[7] * x2 + b[5]; + t[3] = b[6] * x2 + b[4]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[2] += static_cast<V>(b[3]); + t[3] += static_cast<V>(b[2]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[1]); + t[3] += static_cast<V>(b[0]); + t[0] *= x; + t[2] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z; + t[2] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<9>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[8] * x2 + a[6]; + t[1] = a[7] * x2 + a[5]; + t[2] = b[8] * x2 + b[6]; + t[3] = b[7] * x2 + b[5]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[3]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[2] += static_cast<V>(b[2]); + t[3] += static_cast<V>(b[1]); + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[8]); + t[2] += static_cast<V>(b[8]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<10>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[9] * x2 + a[7]; + t[1] = a[8] * x2 + a[6]; + t[2] = b[9] * x2 + b[7]; + t[3] = b[8] * x2 + b[6]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[2] += static_cast<V>(b[5]); + t[3] += static_cast<V>(b[4]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[2] += static_cast<V>(b[3]); + t[3] += static_cast<V>(b[2]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[1]); + t[3] += static_cast<V>(b[0]); + t[0] *= x; + t[2] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[9]); + t[0] *= z; + t[2] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<11>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[10] * x2 + a[8]; + t[1] = a[9] * x2 + a[7]; + t[2] = b[10] * x2 + b[8]; + t[3] = b[9] * x2 + b[7]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[5]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[3]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[2] += static_cast<V>(b[2]); + t[3] += static_cast<V>(b[1]); + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[9]); + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[10]); + t[2] += static_cast<V>(b[10]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<12>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[11] * x2 + a[9]; + t[1] = a[10] * x2 + a[8]; + t[2] = b[11] * x2 + b[9]; + t[3] = b[10] * x2 + b[8]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[7]); + t[1] += static_cast<V>(a[6]); + t[2] += static_cast<V>(b[7]); + t[3] += static_cast<V>(b[6]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[2] += static_cast<V>(b[5]); + t[3] += static_cast<V>(b[4]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[2] += static_cast<V>(b[3]); + t[3] += static_cast<V>(b[2]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[1]); + t[3] += static_cast<V>(b[0]); + t[0] *= x; + t[2] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[9]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[11]); + t[2] += static_cast<V>(b[10]); + t[3] += static_cast<V>(b[11]); + t[0] *= z; + t[2] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<13>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[12] * x2 + a[10]; + t[1] = a[11] * x2 + a[9]; + t[2] = b[12] * x2 + b[10]; + t[3] = b[11] * x2 + b[9]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[7]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[5]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[3]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[2] += static_cast<V>(b[2]); + t[3] += static_cast<V>(b[1]); + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[9]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[11]); + t[2] += static_cast<V>(b[10]); + t[3] += static_cast<V>(b[11]); + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[12]); + t[2] += static_cast<V>(b[12]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<14>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[13] * x2 + a[11]; + t[1] = a[12] * x2 + a[10]; + t[2] = b[13] * x2 + b[11]; + t[3] = b[12] * x2 + b[10]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[9]); + t[1] += static_cast<V>(a[8]); + t[2] += static_cast<V>(b[9]); + t[3] += static_cast<V>(b[8]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[7]); + t[1] += static_cast<V>(a[6]); + t[2] += static_cast<V>(b[7]); + t[3] += static_cast<V>(b[6]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[2] += static_cast<V>(b[5]); + t[3] += static_cast<V>(b[4]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[2] += static_cast<V>(b[3]); + t[3] += static_cast<V>(b[2]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[1]); + t[3] += static_cast<V>(b[0]); + t[0] *= x; + t[2] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[9]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[11]); + t[2] += static_cast<V>(b[10]); + t[3] += static_cast<V>(b[11]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[12]); + t[1] += static_cast<V>(a[13]); + t[2] += static_cast<V>(b[12]); + t[3] += static_cast<V>(b[13]); + t[0] *= z; + t[2] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<15>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[14] * x2 + a[12]; + t[1] = a[13] * x2 + a[11]; + t[2] = b[14] * x2 + b[12]; + t[3] = b[13] * x2 + b[11]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[10]); + t[3] += static_cast<V>(b[9]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[7]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[5]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[3]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[2] += static_cast<V>(b[2]); + t[3] += static_cast<V>(b[1]); + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[9]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[11]); + t[2] += static_cast<V>(b[10]); + t[3] += static_cast<V>(b[11]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[12]); + t[1] += static_cast<V>(a[13]); + t[2] += static_cast<V>(b[12]); + t[3] += static_cast<V>(b[13]); + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[14]); + t[2] += static_cast<V>(b[14]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<16>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[15] * x2 + a[13]; + t[1] = a[14] * x2 + a[12]; + t[2] = b[15] * x2 + b[13]; + t[3] = b[14] * x2 + b[12]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[11]); + t[1] += static_cast<V>(a[10]); + t[2] += static_cast<V>(b[11]); + t[3] += static_cast<V>(b[10]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[9]); + t[1] += static_cast<V>(a[8]); + t[2] += static_cast<V>(b[9]); + t[3] += static_cast<V>(b[8]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[7]); + t[1] += static_cast<V>(a[6]); + t[2] += static_cast<V>(b[7]); + t[3] += static_cast<V>(b[6]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[2] += static_cast<V>(b[5]); + t[3] += static_cast<V>(b[4]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[2] += static_cast<V>(b[3]); + t[3] += static_cast<V>(b[2]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[1]); + t[3] += static_cast<V>(b[0]); + t[0] *= x; + t[2] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[9]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[11]); + t[2] += static_cast<V>(b[10]); + t[3] += static_cast<V>(b[11]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[12]); + t[1] += static_cast<V>(a[13]); + t[2] += static_cast<V>(b[12]); + t[3] += static_cast<V>(b[13]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[14]); + t[1] += static_cast<V>(a[15]); + t[2] += static_cast<V>(b[14]); + t[3] += static_cast<V>(b[15]); + t[0] *= z; + t[2] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<17>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[16] * x2 + a[14]; + t[1] = a[15] * x2 + a[13]; + t[2] = b[16] * x2 + b[14]; + t[3] = b[15] * x2 + b[13]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[12]); + t[1] += static_cast<V>(a[11]); + t[2] += static_cast<V>(b[12]); + t[3] += static_cast<V>(b[11]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[10]); + t[3] += static_cast<V>(b[9]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[7]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[5]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[3]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[2] += static_cast<V>(b[2]); + t[3] += static_cast<V>(b[1]); + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[9]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[11]); + t[2] += static_cast<V>(b[10]); + t[3] += static_cast<V>(b[11]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[12]); + t[1] += static_cast<V>(a[13]); + t[2] += static_cast<V>(b[12]); + t[3] += static_cast<V>(b[13]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[14]); + t[1] += static_cast<V>(a[15]); + t[2] += static_cast<V>(b[14]); + t[3] += static_cast<V>(b[15]); + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[16]); + t[2] += static_cast<V>(b[16]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<18>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[17] * x2 + a[15]; + t[1] = a[16] * x2 + a[14]; + t[2] = b[17] * x2 + b[15]; + t[3] = b[16] * x2 + b[14]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[13]); + t[1] += static_cast<V>(a[12]); + t[2] += static_cast<V>(b[13]); + t[3] += static_cast<V>(b[12]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[11]); + t[1] += static_cast<V>(a[10]); + t[2] += static_cast<V>(b[11]); + t[3] += static_cast<V>(b[10]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[9]); + t[1] += static_cast<V>(a[8]); + t[2] += static_cast<V>(b[9]); + t[3] += static_cast<V>(b[8]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[7]); + t[1] += static_cast<V>(a[6]); + t[2] += static_cast<V>(b[7]); + t[3] += static_cast<V>(b[6]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[2] += static_cast<V>(b[5]); + t[3] += static_cast<V>(b[4]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[2] += static_cast<V>(b[3]); + t[3] += static_cast<V>(b[2]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[1]); + t[3] += static_cast<V>(b[0]); + t[0] *= x; + t[2] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[9]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[11]); + t[2] += static_cast<V>(b[10]); + t[3] += static_cast<V>(b[11]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[12]); + t[1] += static_cast<V>(a[13]); + t[2] += static_cast<V>(b[12]); + t[3] += static_cast<V>(b[13]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[14]); + t[1] += static_cast<V>(a[15]); + t[2] += static_cast<V>(b[14]); + t[3] += static_cast<V>(b[15]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[16]); + t[1] += static_cast<V>(a[17]); + t[2] += static_cast<V>(b[16]); + t[3] += static_cast<V>(b[17]); + t[0] *= z; + t[2] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/rational_horner3_19.hpp b/Utilities/BGL/boost/math/tools/detail/rational_horner3_19.hpp new file mode 100644 index 0000000000000000000000000000000000000000..863c2cde8e0cc7d0bc6f00642b049eaa8057e479 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/rational_horner3_19.hpp @@ -0,0 +1,1458 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_RAT_EVAL_19_HPP +#define BOOST_MATH_TOOLS_RAT_EVAL_19_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]) / static_cast<V>(b[0]); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>((a[1] * x + a[0]) / (b[1] * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>(((a[2] * x + a[1]) * x + a[0]) / ((b[2] * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>((((a[3] * x + a[2]) * x + a[1]) * x + a[0]) / (((b[3] * x + b[2]) * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<5>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[4] * x2 + a[2]; + t[1] = a[3] * x2 + a[1]; + t[2] = b[4] * x2 + b[2]; + t[3] = b[3] * x2 + b[1]; + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[4]); + t[2] += static_cast<V>(b[4]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<6>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[5] * x2 + a[3]; + t[1] = a[4] * x2 + a[2]; + t[2] = b[5] * x2 + b[3]; + t[3] = b[4] * x2 + b[2]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[1]); + t[3] += static_cast<V>(b[0]); + t[0] *= x; + t[2] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z; + t[2] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<7>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[6] * x2 + a[4]; + t[1] = a[5] * x2 + a[3]; + t[2] = b[6] * x2 + b[4]; + t[3] = b[5] * x2 + b[3]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[2] += static_cast<V>(b[2]); + t[3] += static_cast<V>(b[1]); + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[6]); + t[2] += static_cast<V>(b[6]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<8>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[7] * x2 + a[5]; + t[1] = a[6] * x2 + a[4]; + t[2] = b[7] * x2 + b[5]; + t[3] = b[6] * x2 + b[4]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[2] += static_cast<V>(b[3]); + t[3] += static_cast<V>(b[2]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[1]); + t[3] += static_cast<V>(b[0]); + t[0] *= x; + t[2] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z; + t[2] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<9>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[8] * x2 + a[6]; + t[1] = a[7] * x2 + a[5]; + t[2] = b[8] * x2 + b[6]; + t[3] = b[7] * x2 + b[5]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[3]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[2] += static_cast<V>(b[2]); + t[3] += static_cast<V>(b[1]); + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[8]); + t[2] += static_cast<V>(b[8]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<10>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[9] * x2 + a[7]; + t[1] = a[8] * x2 + a[6]; + t[2] = b[9] * x2 + b[7]; + t[3] = b[8] * x2 + b[6]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[2] += static_cast<V>(b[5]); + t[3] += static_cast<V>(b[4]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[2] += static_cast<V>(b[3]); + t[3] += static_cast<V>(b[2]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[1]); + t[3] += static_cast<V>(b[0]); + t[0] *= x; + t[2] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[9]); + t[0] *= z; + t[2] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<11>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[10] * x2 + a[8]; + t[1] = a[9] * x2 + a[7]; + t[2] = b[10] * x2 + b[8]; + t[3] = b[9] * x2 + b[7]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[5]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[3]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[2] += static_cast<V>(b[2]); + t[3] += static_cast<V>(b[1]); + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[9]); + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[10]); + t[2] += static_cast<V>(b[10]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<12>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[11] * x2 + a[9]; + t[1] = a[10] * x2 + a[8]; + t[2] = b[11] * x2 + b[9]; + t[3] = b[10] * x2 + b[8]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[7]); + t[1] += static_cast<V>(a[6]); + t[2] += static_cast<V>(b[7]); + t[3] += static_cast<V>(b[6]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[2] += static_cast<V>(b[5]); + t[3] += static_cast<V>(b[4]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[2] += static_cast<V>(b[3]); + t[3] += static_cast<V>(b[2]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[1]); + t[3] += static_cast<V>(b[0]); + t[0] *= x; + t[2] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[9]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[11]); + t[2] += static_cast<V>(b[10]); + t[3] += static_cast<V>(b[11]); + t[0] *= z; + t[2] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<13>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[12] * x2 + a[10]; + t[1] = a[11] * x2 + a[9]; + t[2] = b[12] * x2 + b[10]; + t[3] = b[11] * x2 + b[9]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[7]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[5]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[3]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[2] += static_cast<V>(b[2]); + t[3] += static_cast<V>(b[1]); + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[9]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[11]); + t[2] += static_cast<V>(b[10]); + t[3] += static_cast<V>(b[11]); + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[12]); + t[2] += static_cast<V>(b[12]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<14>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[13] * x2 + a[11]; + t[1] = a[12] * x2 + a[10]; + t[2] = b[13] * x2 + b[11]; + t[3] = b[12] * x2 + b[10]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[9]); + t[1] += static_cast<V>(a[8]); + t[2] += static_cast<V>(b[9]); + t[3] += static_cast<V>(b[8]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[7]); + t[1] += static_cast<V>(a[6]); + t[2] += static_cast<V>(b[7]); + t[3] += static_cast<V>(b[6]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[2] += static_cast<V>(b[5]); + t[3] += static_cast<V>(b[4]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[2] += static_cast<V>(b[3]); + t[3] += static_cast<V>(b[2]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[1]); + t[3] += static_cast<V>(b[0]); + t[0] *= x; + t[2] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[9]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[11]); + t[2] += static_cast<V>(b[10]); + t[3] += static_cast<V>(b[11]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[12]); + t[1] += static_cast<V>(a[13]); + t[2] += static_cast<V>(b[12]); + t[3] += static_cast<V>(b[13]); + t[0] *= z; + t[2] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<15>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[14] * x2 + a[12]; + t[1] = a[13] * x2 + a[11]; + t[2] = b[14] * x2 + b[12]; + t[3] = b[13] * x2 + b[11]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[10]); + t[3] += static_cast<V>(b[9]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[7]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[5]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[3]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[2] += static_cast<V>(b[2]); + t[3] += static_cast<V>(b[1]); + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[9]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[11]); + t[2] += static_cast<V>(b[10]); + t[3] += static_cast<V>(b[11]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[12]); + t[1] += static_cast<V>(a[13]); + t[2] += static_cast<V>(b[12]); + t[3] += static_cast<V>(b[13]); + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[14]); + t[2] += static_cast<V>(b[14]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<16>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[15] * x2 + a[13]; + t[1] = a[14] * x2 + a[12]; + t[2] = b[15] * x2 + b[13]; + t[3] = b[14] * x2 + b[12]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[11]); + t[1] += static_cast<V>(a[10]); + t[2] += static_cast<V>(b[11]); + t[3] += static_cast<V>(b[10]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[9]); + t[1] += static_cast<V>(a[8]); + t[2] += static_cast<V>(b[9]); + t[3] += static_cast<V>(b[8]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[7]); + t[1] += static_cast<V>(a[6]); + t[2] += static_cast<V>(b[7]); + t[3] += static_cast<V>(b[6]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[2] += static_cast<V>(b[5]); + t[3] += static_cast<V>(b[4]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[2] += static_cast<V>(b[3]); + t[3] += static_cast<V>(b[2]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[1]); + t[3] += static_cast<V>(b[0]); + t[0] *= x; + t[2] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[9]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[11]); + t[2] += static_cast<V>(b[10]); + t[3] += static_cast<V>(b[11]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[12]); + t[1] += static_cast<V>(a[13]); + t[2] += static_cast<V>(b[12]); + t[3] += static_cast<V>(b[13]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[14]); + t[1] += static_cast<V>(a[15]); + t[2] += static_cast<V>(b[14]); + t[3] += static_cast<V>(b[15]); + t[0] *= z; + t[2] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<17>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[16] * x2 + a[14]; + t[1] = a[15] * x2 + a[13]; + t[2] = b[16] * x2 + b[14]; + t[3] = b[15] * x2 + b[13]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[12]); + t[1] += static_cast<V>(a[11]); + t[2] += static_cast<V>(b[12]); + t[3] += static_cast<V>(b[11]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[10]); + t[3] += static_cast<V>(b[9]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[7]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[5]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[3]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[2] += static_cast<V>(b[2]); + t[3] += static_cast<V>(b[1]); + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[9]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[11]); + t[2] += static_cast<V>(b[10]); + t[3] += static_cast<V>(b[11]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[12]); + t[1] += static_cast<V>(a[13]); + t[2] += static_cast<V>(b[12]); + t[3] += static_cast<V>(b[13]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[14]); + t[1] += static_cast<V>(a[15]); + t[2] += static_cast<V>(b[14]); + t[3] += static_cast<V>(b[15]); + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[16]); + t[2] += static_cast<V>(b[16]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<18>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[17] * x2 + a[15]; + t[1] = a[16] * x2 + a[14]; + t[2] = b[17] * x2 + b[15]; + t[3] = b[16] * x2 + b[14]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[13]); + t[1] += static_cast<V>(a[12]); + t[2] += static_cast<V>(b[13]); + t[3] += static_cast<V>(b[12]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[11]); + t[1] += static_cast<V>(a[10]); + t[2] += static_cast<V>(b[11]); + t[3] += static_cast<V>(b[10]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[9]); + t[1] += static_cast<V>(a[8]); + t[2] += static_cast<V>(b[9]); + t[3] += static_cast<V>(b[8]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[7]); + t[1] += static_cast<V>(a[6]); + t[2] += static_cast<V>(b[7]); + t[3] += static_cast<V>(b[6]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[2] += static_cast<V>(b[5]); + t[3] += static_cast<V>(b[4]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[2] += static_cast<V>(b[3]); + t[3] += static_cast<V>(b[2]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[1]); + t[3] += static_cast<V>(b[0]); + t[0] *= x; + t[2] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[9]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[11]); + t[2] += static_cast<V>(b[10]); + t[3] += static_cast<V>(b[11]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[12]); + t[1] += static_cast<V>(a[13]); + t[2] += static_cast<V>(b[12]); + t[3] += static_cast<V>(b[13]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[14]); + t[1] += static_cast<V>(a[15]); + t[2] += static_cast<V>(b[14]); + t[3] += static_cast<V>(b[15]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[16]); + t[1] += static_cast<V>(a[17]); + t[2] += static_cast<V>(b[16]); + t[3] += static_cast<V>(b[17]); + t[0] *= z; + t[2] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<19>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[18] * x2 + a[16]; + t[1] = a[17] * x2 + a[15]; + t[2] = b[18] * x2 + b[16]; + t[3] = b[17] * x2 + b[15]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[14]); + t[1] += static_cast<V>(a[13]); + t[2] += static_cast<V>(b[14]); + t[3] += static_cast<V>(b[13]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[12]); + t[1] += static_cast<V>(a[11]); + t[2] += static_cast<V>(b[12]); + t[3] += static_cast<V>(b[11]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[10]); + t[3] += static_cast<V>(b[9]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[7]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[5]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[3]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[2] += static_cast<V>(b[2]); + t[3] += static_cast<V>(b[1]); + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[9]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[11]); + t[2] += static_cast<V>(b[10]); + t[3] += static_cast<V>(b[11]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[12]); + t[1] += static_cast<V>(a[13]); + t[2] += static_cast<V>(b[12]); + t[3] += static_cast<V>(b[13]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[14]); + t[1] += static_cast<V>(a[15]); + t[2] += static_cast<V>(b[14]); + t[3] += static_cast<V>(b[15]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[16]); + t[1] += static_cast<V>(a[17]); + t[2] += static_cast<V>(b[16]); + t[3] += static_cast<V>(b[17]); + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[18]); + t[2] += static_cast<V>(b[18]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/rational_horner3_2.hpp b/Utilities/BGL/boost/math/tools/detail/rational_horner3_2.hpp new file mode 100644 index 0000000000000000000000000000000000000000..5373d144f6c795e4aa14bb4c8fb6ee24707b03db --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/rational_horner3_2.hpp @@ -0,0 +1,48 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_RAT_EVAL_2_HPP +#define BOOST_MATH_TOOLS_RAT_EVAL_2_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]) / static_cast<V>(b[0]); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>((a[1] * x + a[0]) / (b[1] * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>(((a[2] * x + a[1]) * x + a[0]) / ((b[2] * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>((((a[3] * x + a[2]) * x + a[1]) * x + a[0]) / (((b[3] * x + b[2]) * x + b[1]) * x + b[0])); +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/rational_horner3_20.hpp b/Utilities/BGL/boost/math/tools/detail/rational_horner3_20.hpp new file mode 100644 index 0000000000000000000000000000000000000000..056cac551e7580f9dd53103f123dee1f7051caeb --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/rational_horner3_20.hpp @@ -0,0 +1,1616 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_RAT_EVAL_20_HPP +#define BOOST_MATH_TOOLS_RAT_EVAL_20_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]) / static_cast<V>(b[0]); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>((a[1] * x + a[0]) / (b[1] * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>(((a[2] * x + a[1]) * x + a[0]) / ((b[2] * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>((((a[3] * x + a[2]) * x + a[1]) * x + a[0]) / (((b[3] * x + b[2]) * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<5>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[4] * x2 + a[2]; + t[1] = a[3] * x2 + a[1]; + t[2] = b[4] * x2 + b[2]; + t[3] = b[3] * x2 + b[1]; + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[4]); + t[2] += static_cast<V>(b[4]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<6>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[5] * x2 + a[3]; + t[1] = a[4] * x2 + a[2]; + t[2] = b[5] * x2 + b[3]; + t[3] = b[4] * x2 + b[2]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[1]); + t[3] += static_cast<V>(b[0]); + t[0] *= x; + t[2] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z; + t[2] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<7>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[6] * x2 + a[4]; + t[1] = a[5] * x2 + a[3]; + t[2] = b[6] * x2 + b[4]; + t[3] = b[5] * x2 + b[3]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[2] += static_cast<V>(b[2]); + t[3] += static_cast<V>(b[1]); + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[6]); + t[2] += static_cast<V>(b[6]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<8>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[7] * x2 + a[5]; + t[1] = a[6] * x2 + a[4]; + t[2] = b[7] * x2 + b[5]; + t[3] = b[6] * x2 + b[4]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[2] += static_cast<V>(b[3]); + t[3] += static_cast<V>(b[2]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[1]); + t[3] += static_cast<V>(b[0]); + t[0] *= x; + t[2] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z; + t[2] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<9>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[8] * x2 + a[6]; + t[1] = a[7] * x2 + a[5]; + t[2] = b[8] * x2 + b[6]; + t[3] = b[7] * x2 + b[5]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[3]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[2] += static_cast<V>(b[2]); + t[3] += static_cast<V>(b[1]); + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[8]); + t[2] += static_cast<V>(b[8]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<10>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[9] * x2 + a[7]; + t[1] = a[8] * x2 + a[6]; + t[2] = b[9] * x2 + b[7]; + t[3] = b[8] * x2 + b[6]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[2] += static_cast<V>(b[5]); + t[3] += static_cast<V>(b[4]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[2] += static_cast<V>(b[3]); + t[3] += static_cast<V>(b[2]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[1]); + t[3] += static_cast<V>(b[0]); + t[0] *= x; + t[2] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[9]); + t[0] *= z; + t[2] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<11>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[10] * x2 + a[8]; + t[1] = a[9] * x2 + a[7]; + t[2] = b[10] * x2 + b[8]; + t[3] = b[9] * x2 + b[7]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[5]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[3]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[2] += static_cast<V>(b[2]); + t[3] += static_cast<V>(b[1]); + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[9]); + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[10]); + t[2] += static_cast<V>(b[10]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<12>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[11] * x2 + a[9]; + t[1] = a[10] * x2 + a[8]; + t[2] = b[11] * x2 + b[9]; + t[3] = b[10] * x2 + b[8]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[7]); + t[1] += static_cast<V>(a[6]); + t[2] += static_cast<V>(b[7]); + t[3] += static_cast<V>(b[6]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[2] += static_cast<V>(b[5]); + t[3] += static_cast<V>(b[4]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[2] += static_cast<V>(b[3]); + t[3] += static_cast<V>(b[2]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[1]); + t[3] += static_cast<V>(b[0]); + t[0] *= x; + t[2] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[9]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[11]); + t[2] += static_cast<V>(b[10]); + t[3] += static_cast<V>(b[11]); + t[0] *= z; + t[2] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<13>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[12] * x2 + a[10]; + t[1] = a[11] * x2 + a[9]; + t[2] = b[12] * x2 + b[10]; + t[3] = b[11] * x2 + b[9]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[7]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[5]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[3]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[2] += static_cast<V>(b[2]); + t[3] += static_cast<V>(b[1]); + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[9]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[11]); + t[2] += static_cast<V>(b[10]); + t[3] += static_cast<V>(b[11]); + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[12]); + t[2] += static_cast<V>(b[12]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<14>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[13] * x2 + a[11]; + t[1] = a[12] * x2 + a[10]; + t[2] = b[13] * x2 + b[11]; + t[3] = b[12] * x2 + b[10]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[9]); + t[1] += static_cast<V>(a[8]); + t[2] += static_cast<V>(b[9]); + t[3] += static_cast<V>(b[8]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[7]); + t[1] += static_cast<V>(a[6]); + t[2] += static_cast<V>(b[7]); + t[3] += static_cast<V>(b[6]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[2] += static_cast<V>(b[5]); + t[3] += static_cast<V>(b[4]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[2] += static_cast<V>(b[3]); + t[3] += static_cast<V>(b[2]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[1]); + t[3] += static_cast<V>(b[0]); + t[0] *= x; + t[2] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[9]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[11]); + t[2] += static_cast<V>(b[10]); + t[3] += static_cast<V>(b[11]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[12]); + t[1] += static_cast<V>(a[13]); + t[2] += static_cast<V>(b[12]); + t[3] += static_cast<V>(b[13]); + t[0] *= z; + t[2] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<15>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[14] * x2 + a[12]; + t[1] = a[13] * x2 + a[11]; + t[2] = b[14] * x2 + b[12]; + t[3] = b[13] * x2 + b[11]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[10]); + t[3] += static_cast<V>(b[9]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[7]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[5]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[3]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[2] += static_cast<V>(b[2]); + t[3] += static_cast<V>(b[1]); + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[9]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[11]); + t[2] += static_cast<V>(b[10]); + t[3] += static_cast<V>(b[11]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[12]); + t[1] += static_cast<V>(a[13]); + t[2] += static_cast<V>(b[12]); + t[3] += static_cast<V>(b[13]); + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[14]); + t[2] += static_cast<V>(b[14]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<16>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[15] * x2 + a[13]; + t[1] = a[14] * x2 + a[12]; + t[2] = b[15] * x2 + b[13]; + t[3] = b[14] * x2 + b[12]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[11]); + t[1] += static_cast<V>(a[10]); + t[2] += static_cast<V>(b[11]); + t[3] += static_cast<V>(b[10]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[9]); + t[1] += static_cast<V>(a[8]); + t[2] += static_cast<V>(b[9]); + t[3] += static_cast<V>(b[8]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[7]); + t[1] += static_cast<V>(a[6]); + t[2] += static_cast<V>(b[7]); + t[3] += static_cast<V>(b[6]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[2] += static_cast<V>(b[5]); + t[3] += static_cast<V>(b[4]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[2] += static_cast<V>(b[3]); + t[3] += static_cast<V>(b[2]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[1]); + t[3] += static_cast<V>(b[0]); + t[0] *= x; + t[2] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[9]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[11]); + t[2] += static_cast<V>(b[10]); + t[3] += static_cast<V>(b[11]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[12]); + t[1] += static_cast<V>(a[13]); + t[2] += static_cast<V>(b[12]); + t[3] += static_cast<V>(b[13]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[14]); + t[1] += static_cast<V>(a[15]); + t[2] += static_cast<V>(b[14]); + t[3] += static_cast<V>(b[15]); + t[0] *= z; + t[2] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<17>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[16] * x2 + a[14]; + t[1] = a[15] * x2 + a[13]; + t[2] = b[16] * x2 + b[14]; + t[3] = b[15] * x2 + b[13]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[12]); + t[1] += static_cast<V>(a[11]); + t[2] += static_cast<V>(b[12]); + t[3] += static_cast<V>(b[11]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[10]); + t[3] += static_cast<V>(b[9]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[7]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[5]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[3]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[2] += static_cast<V>(b[2]); + t[3] += static_cast<V>(b[1]); + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[9]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[11]); + t[2] += static_cast<V>(b[10]); + t[3] += static_cast<V>(b[11]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[12]); + t[1] += static_cast<V>(a[13]); + t[2] += static_cast<V>(b[12]); + t[3] += static_cast<V>(b[13]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[14]); + t[1] += static_cast<V>(a[15]); + t[2] += static_cast<V>(b[14]); + t[3] += static_cast<V>(b[15]); + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[16]); + t[2] += static_cast<V>(b[16]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<18>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[17] * x2 + a[15]; + t[1] = a[16] * x2 + a[14]; + t[2] = b[17] * x2 + b[15]; + t[3] = b[16] * x2 + b[14]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[13]); + t[1] += static_cast<V>(a[12]); + t[2] += static_cast<V>(b[13]); + t[3] += static_cast<V>(b[12]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[11]); + t[1] += static_cast<V>(a[10]); + t[2] += static_cast<V>(b[11]); + t[3] += static_cast<V>(b[10]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[9]); + t[1] += static_cast<V>(a[8]); + t[2] += static_cast<V>(b[9]); + t[3] += static_cast<V>(b[8]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[7]); + t[1] += static_cast<V>(a[6]); + t[2] += static_cast<V>(b[7]); + t[3] += static_cast<V>(b[6]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[2] += static_cast<V>(b[5]); + t[3] += static_cast<V>(b[4]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[2] += static_cast<V>(b[3]); + t[3] += static_cast<V>(b[2]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[1]); + t[3] += static_cast<V>(b[0]); + t[0] *= x; + t[2] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[9]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[11]); + t[2] += static_cast<V>(b[10]); + t[3] += static_cast<V>(b[11]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[12]); + t[1] += static_cast<V>(a[13]); + t[2] += static_cast<V>(b[12]); + t[3] += static_cast<V>(b[13]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[14]); + t[1] += static_cast<V>(a[15]); + t[2] += static_cast<V>(b[14]); + t[3] += static_cast<V>(b[15]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[16]); + t[1] += static_cast<V>(a[17]); + t[2] += static_cast<V>(b[16]); + t[3] += static_cast<V>(b[17]); + t[0] *= z; + t[2] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<19>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[18] * x2 + a[16]; + t[1] = a[17] * x2 + a[15]; + t[2] = b[18] * x2 + b[16]; + t[3] = b[17] * x2 + b[15]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[14]); + t[1] += static_cast<V>(a[13]); + t[2] += static_cast<V>(b[14]); + t[3] += static_cast<V>(b[13]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[12]); + t[1] += static_cast<V>(a[11]); + t[2] += static_cast<V>(b[12]); + t[3] += static_cast<V>(b[11]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[10]); + t[3] += static_cast<V>(b[9]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[7]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[5]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[3]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[2] += static_cast<V>(b[2]); + t[3] += static_cast<V>(b[1]); + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[9]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[11]); + t[2] += static_cast<V>(b[10]); + t[3] += static_cast<V>(b[11]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[12]); + t[1] += static_cast<V>(a[13]); + t[2] += static_cast<V>(b[12]); + t[3] += static_cast<V>(b[13]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[14]); + t[1] += static_cast<V>(a[15]); + t[2] += static_cast<V>(b[14]); + t[3] += static_cast<V>(b[15]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[16]); + t[1] += static_cast<V>(a[17]); + t[2] += static_cast<V>(b[16]); + t[3] += static_cast<V>(b[17]); + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[18]); + t[2] += static_cast<V>(b[18]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<20>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[19] * x2 + a[17]; + t[1] = a[18] * x2 + a[16]; + t[2] = b[19] * x2 + b[17]; + t[3] = b[18] * x2 + b[16]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[15]); + t[1] += static_cast<V>(a[14]); + t[2] += static_cast<V>(b[15]); + t[3] += static_cast<V>(b[14]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[13]); + t[1] += static_cast<V>(a[12]); + t[2] += static_cast<V>(b[13]); + t[3] += static_cast<V>(b[12]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[11]); + t[1] += static_cast<V>(a[10]); + t[2] += static_cast<V>(b[11]); + t[3] += static_cast<V>(b[10]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[9]); + t[1] += static_cast<V>(a[8]); + t[2] += static_cast<V>(b[9]); + t[3] += static_cast<V>(b[8]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[7]); + t[1] += static_cast<V>(a[6]); + t[2] += static_cast<V>(b[7]); + t[3] += static_cast<V>(b[6]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[5]); + t[1] += static_cast<V>(a[4]); + t[2] += static_cast<V>(b[5]); + t[3] += static_cast<V>(b[4]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[2] += static_cast<V>(b[3]); + t[3] += static_cast<V>(b[2]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[1]); + t[3] += static_cast<V>(b[0]); + t[0] *= x; + t[2] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[8]); + t[1] += static_cast<V>(a[9]); + t[2] += static_cast<V>(b[8]); + t[3] += static_cast<V>(b[9]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[10]); + t[1] += static_cast<V>(a[11]); + t[2] += static_cast<V>(b[10]); + t[3] += static_cast<V>(b[11]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[12]); + t[1] += static_cast<V>(a[13]); + t[2] += static_cast<V>(b[12]); + t[3] += static_cast<V>(b[13]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[14]); + t[1] += static_cast<V>(a[15]); + t[2] += static_cast<V>(b[14]); + t[3] += static_cast<V>(b[15]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[16]); + t[1] += static_cast<V>(a[17]); + t[2] += static_cast<V>(b[16]); + t[3] += static_cast<V>(b[17]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[18]); + t[1] += static_cast<V>(a[19]); + t[2] += static_cast<V>(b[18]); + t[3] += static_cast<V>(b[19]); + t[0] *= z; + t[2] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/rational_horner3_3.hpp b/Utilities/BGL/boost/math/tools/detail/rational_horner3_3.hpp new file mode 100644 index 0000000000000000000000000000000000000000..f1897e145f3035d587678533f40a09fee3cda2d0 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/rational_horner3_3.hpp @@ -0,0 +1,48 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_RAT_EVAL_3_HPP +#define BOOST_MATH_TOOLS_RAT_EVAL_3_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]) / static_cast<V>(b[0]); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>((a[1] * x + a[0]) / (b[1] * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>(((a[2] * x + a[1]) * x + a[0]) / ((b[2] * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>((((a[3] * x + a[2]) * x + a[1]) * x + a[0]) / (((b[3] * x + b[2]) * x + b[1]) * x + b[0])); +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/rational_horner3_4.hpp b/Utilities/BGL/boost/math/tools/detail/rational_horner3_4.hpp new file mode 100644 index 0000000000000000000000000000000000000000..e7d6ccd13068e74326be5d48ce46f289900dd1d8 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/rational_horner3_4.hpp @@ -0,0 +1,48 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_RAT_EVAL_4_HPP +#define BOOST_MATH_TOOLS_RAT_EVAL_4_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]) / static_cast<V>(b[0]); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>((a[1] * x + a[0]) / (b[1] * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>(((a[2] * x + a[1]) * x + a[0]) / ((b[2] * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>((((a[3] * x + a[2]) * x + a[1]) * x + a[0]) / (((b[3] * x + b[2]) * x + b[1]) * x + b[0])); +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/rational_horner3_5.hpp b/Utilities/BGL/boost/math/tools/detail/rational_horner3_5.hpp new file mode 100644 index 0000000000000000000000000000000000000000..abdd80b6d63ab8994b41eefa730cf63900f9667b --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/rational_horner3_5.hpp @@ -0,0 +1,86 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_RAT_EVAL_5_HPP +#define BOOST_MATH_TOOLS_RAT_EVAL_5_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]) / static_cast<V>(b[0]); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>((a[1] * x + a[0]) / (b[1] * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>(((a[2] * x + a[1]) * x + a[0]) / ((b[2] * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>((((a[3] * x + a[2]) * x + a[1]) * x + a[0]) / (((b[3] * x + b[2]) * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<5>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[4] * x2 + a[2]; + t[1] = a[3] * x2 + a[1]; + t[2] = b[4] * x2 + b[2]; + t[3] = b[3] * x2 + b[1]; + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[4]); + t[2] += static_cast<V>(b[4]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/rational_horner3_6.hpp b/Utilities/BGL/boost/math/tools/detail/rational_horner3_6.hpp new file mode 100644 index 0000000000000000000000000000000000000000..3b0ed94f69ab88c232d2d9d0f1a3bc550134379f --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/rational_horner3_6.hpp @@ -0,0 +1,132 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_RAT_EVAL_6_HPP +#define BOOST_MATH_TOOLS_RAT_EVAL_6_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]) / static_cast<V>(b[0]); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>((a[1] * x + a[0]) / (b[1] * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>(((a[2] * x + a[1]) * x + a[0]) / ((b[2] * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>((((a[3] * x + a[2]) * x + a[1]) * x + a[0]) / (((b[3] * x + b[2]) * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<5>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[4] * x2 + a[2]; + t[1] = a[3] * x2 + a[1]; + t[2] = b[4] * x2 + b[2]; + t[3] = b[3] * x2 + b[1]; + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[4]); + t[2] += static_cast<V>(b[4]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<6>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[5] * x2 + a[3]; + t[1] = a[4] * x2 + a[2]; + t[2] = b[5] * x2 + b[3]; + t[3] = b[4] * x2 + b[2]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[1]); + t[3] += static_cast<V>(b[0]); + t[0] *= x; + t[2] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z; + t[2] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/rational_horner3_7.hpp b/Utilities/BGL/boost/math/tools/detail/rational_horner3_7.hpp new file mode 100644 index 0000000000000000000000000000000000000000..e7ab5b6f09394a30bd9b0de5ff709cbb803c1ce3 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/rational_horner3_7.hpp @@ -0,0 +1,186 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_RAT_EVAL_7_HPP +#define BOOST_MATH_TOOLS_RAT_EVAL_7_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]) / static_cast<V>(b[0]); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>((a[1] * x + a[0]) / (b[1] * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>(((a[2] * x + a[1]) * x + a[0]) / ((b[2] * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>((((a[3] * x + a[2]) * x + a[1]) * x + a[0]) / (((b[3] * x + b[2]) * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<5>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[4] * x2 + a[2]; + t[1] = a[3] * x2 + a[1]; + t[2] = b[4] * x2 + b[2]; + t[3] = b[3] * x2 + b[1]; + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[4]); + t[2] += static_cast<V>(b[4]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<6>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[5] * x2 + a[3]; + t[1] = a[4] * x2 + a[2]; + t[2] = b[5] * x2 + b[3]; + t[3] = b[4] * x2 + b[2]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[1]); + t[3] += static_cast<V>(b[0]); + t[0] *= x; + t[2] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z; + t[2] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<7>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[6] * x2 + a[4]; + t[1] = a[5] * x2 + a[3]; + t[2] = b[6] * x2 + b[4]; + t[3] = b[5] * x2 + b[3]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[2] += static_cast<V>(b[2]); + t[3] += static_cast<V>(b[1]); + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[6]); + t[2] += static_cast<V>(b[6]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/rational_horner3_8.hpp b/Utilities/BGL/boost/math/tools/detail/rational_horner3_8.hpp new file mode 100644 index 0000000000000000000000000000000000000000..11473d39d4d56673ba25c83d6b7247daf7e33ee9 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/rational_horner3_8.hpp @@ -0,0 +1,248 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_RAT_EVAL_8_HPP +#define BOOST_MATH_TOOLS_RAT_EVAL_8_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]) / static_cast<V>(b[0]); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>((a[1] * x + a[0]) / (b[1] * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>(((a[2] * x + a[1]) * x + a[0]) / ((b[2] * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>((((a[3] * x + a[2]) * x + a[1]) * x + a[0]) / (((b[3] * x + b[2]) * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<5>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[4] * x2 + a[2]; + t[1] = a[3] * x2 + a[1]; + t[2] = b[4] * x2 + b[2]; + t[3] = b[3] * x2 + b[1]; + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[4]); + t[2] += static_cast<V>(b[4]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<6>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[5] * x2 + a[3]; + t[1] = a[4] * x2 + a[2]; + t[2] = b[5] * x2 + b[3]; + t[3] = b[4] * x2 + b[2]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[1]); + t[3] += static_cast<V>(b[0]); + t[0] *= x; + t[2] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z; + t[2] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<7>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[6] * x2 + a[4]; + t[1] = a[5] * x2 + a[3]; + t[2] = b[6] * x2 + b[4]; + t[3] = b[5] * x2 + b[3]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[2] += static_cast<V>(b[2]); + t[3] += static_cast<V>(b[1]); + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[6]); + t[2] += static_cast<V>(b[6]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<8>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[7] * x2 + a[5]; + t[1] = a[6] * x2 + a[4]; + t[2] = b[7] * x2 + b[5]; + t[3] = b[6] * x2 + b[4]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[2] += static_cast<V>(b[3]); + t[3] += static_cast<V>(b[2]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[1]); + t[3] += static_cast<V>(b[0]); + t[0] *= x; + t[2] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z; + t[2] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/detail/rational_horner3_9.hpp b/Utilities/BGL/boost/math/tools/detail/rational_horner3_9.hpp new file mode 100644 index 0000000000000000000000000000000000000000..9a47da8960a09aa7bef34e2b92ac6a17e9413e5e --- /dev/null +++ b/Utilities/BGL/boost/math/tools/detail/rational_horner3_9.hpp @@ -0,0 +1,318 @@ +// (C) Copyright John Maddock 2007. +// Use, modification and distribution are subject to 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) +// +// This file is machine generated, do not edit by hand + +// Polynomial evaluation using second order Horners rule +#ifndef BOOST_MATH_TOOLS_RAT_EVAL_9_HPP +#define BOOST_MATH_TOOLS_RAT_EVAL_9_HPP + +namespace boost{ namespace math{ namespace tools{ namespace detail{ + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<0>*) +{ + return static_cast<V>(0); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<1>*) +{ + return static_cast<V>(a[0]) / static_cast<V>(b[0]); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<2>*) +{ + return static_cast<V>((a[1] * x + a[0]) / (b[1] * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<3>*) +{ + return static_cast<V>(((a[2] * x + a[1]) * x + a[0]) / ((b[2] * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<4>*) +{ + return static_cast<V>((((a[3] * x + a[2]) * x + a[1]) * x + a[0]) / (((b[3] * x + b[2]) * x + b[1]) * x + b[0])); +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<5>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[4] * x2 + a[2]; + t[1] = a[3] * x2 + a[1]; + t[2] = b[4] * x2 + b[2]; + t[3] = b[3] * x2 + b[1]; + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[4]); + t[2] += static_cast<V>(b[4]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<6>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[5] * x2 + a[3]; + t[1] = a[4] * x2 + a[2]; + t[2] = b[5] * x2 + b[3]; + t[3] = b[4] * x2 + b[2]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[1]); + t[3] += static_cast<V>(b[0]); + t[0] *= x; + t[2] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z; + t[2] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<7>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[6] * x2 + a[4]; + t[1] = a[5] * x2 + a[3]; + t[2] = b[6] * x2 + b[4]; + t[3] = b[5] * x2 + b[3]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[2] += static_cast<V>(b[2]); + t[3] += static_cast<V>(b[1]); + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[6]); + t[2] += static_cast<V>(b[6]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<8>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[7] * x2 + a[5]; + t[1] = a[6] * x2 + a[4]; + t[2] = b[7] * x2 + b[5]; + t[3] = b[6] * x2 + b[4]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[3]); + t[1] += static_cast<V>(a[2]); + t[2] += static_cast<V>(b[3]); + t[3] += static_cast<V>(b[2]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[1]); + t[1] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[1]); + t[3] += static_cast<V>(b[0]); + t[0] *= x; + t[2] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z; + t[2] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + +template <class T, class U, class V> +inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<9>*) +{ + if(x <= 1) + { + V x2 = x * x; + V t[4]; + t[0] = a[8] * x2 + a[6]; + t[1] = a[7] * x2 + a[5]; + t[2] = b[8] * x2 + b[6]; + t[3] = b[7] * x2 + b[5]; + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[3]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[3]); + t[0] *= x2; + t[1] *= x2; + t[2] *= x2; + t[3] *= x2; + t[0] += static_cast<V>(a[2]); + t[1] += static_cast<V>(a[1]); + t[2] += static_cast<V>(b[2]); + t[3] += static_cast<V>(b[1]); + t[0] *= x2; + t[2] *= x2; + t[0] += static_cast<V>(a[0]); + t[2] += static_cast<V>(b[0]); + t[1] *= x; + t[3] *= x; + return (t[0] + t[1]) / (t[2] + t[3]); + } + else + { + V z = 1 / x; + V z2 = 1 / (x * x); + V t[4]; + t[0] = a[0] * z2 + a[2]; + t[1] = a[1] * z2 + a[3]; + t[2] = b[0] * z2 + b[2]; + t[3] = b[1] * z2 + b[3]; + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[4]); + t[1] += static_cast<V>(a[5]); + t[2] += static_cast<V>(b[4]); + t[3] += static_cast<V>(b[5]); + t[0] *= z2; + t[1] *= z2; + t[2] *= z2; + t[3] *= z2; + t[0] += static_cast<V>(a[6]); + t[1] += static_cast<V>(a[7]); + t[2] += static_cast<V>(b[6]); + t[3] += static_cast<V>(b[7]); + t[0] *= z2; + t[2] *= z2; + t[0] += static_cast<V>(a[8]); + t[2] += static_cast<V>(b[8]); + t[1] *= z; + t[3] *= z; + return (t[0] + t[1]) / (t[2] + t[3]); + } +} + + +}}}} // namespaces + +#endif // include guard + diff --git a/Utilities/BGL/boost/math/tools/fraction.hpp b/Utilities/BGL/boost/math/tools/fraction.hpp new file mode 100644 index 0000000000000000000000000000000000000000..5a427d1e35f7cee8f92a173fca16578a3530ad0c --- /dev/null +++ b/Utilities/BGL/boost/math/tools/fraction.hpp @@ -0,0 +1,252 @@ +// (C) Copyright John Maddock 2005-2006. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_TOOLS_FRACTION_INCLUDED +#define BOOST_MATH_TOOLS_FRACTION_INCLUDED + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/config/no_tr1/cmath.hpp> +#include <boost/cstdint.hpp> +#include <boost/type_traits/integral_constant.hpp> +#include <boost/mpl/if.hpp> +#include <boost/math/tools/precision.hpp> + +namespace boost{ namespace math{ namespace tools{ + +namespace detail +{ + + template <class T> + struct is_pair : public boost::false_type{}; + + template <class T, class U> + struct is_pair<std::pair<T,U> > : public boost::true_type{}; + + template <class Gen> + struct fraction_traits_simple + { + typedef typename Gen::result_type result_type; + typedef typename Gen::result_type value_type; + + static result_type a(const value_type& v) + { + return 1; + } + static result_type b(const value_type& v) + { + return v; + } + }; + + template <class Gen> + struct fraction_traits_pair + { + typedef typename Gen::result_type value_type; + typedef typename value_type::first_type result_type; + + static result_type a(const value_type& v) + { + return v.first; + } + static result_type b(const value_type& v) + { + return v.second; + } + }; + + template <class Gen> + struct fraction_traits + : public boost::mpl::if_c< + is_pair<typename Gen::result_type>::value, + fraction_traits_pair<Gen>, + fraction_traits_simple<Gen> >::type + { + }; + +} // namespace detail + +// +// continued_fraction_b +// Evaluates: +// +// b0 + a1 +// --------------- +// b1 + a2 +// ---------- +// b2 + a3 +// ----- +// b3 + ... +// +// Note that the first a0 returned by generator Gen is disarded. +// +template <class Gen, class U> +inline typename detail::fraction_traits<Gen>::result_type continued_fraction_b(Gen& g, const U& factor, boost::uintmax_t& max_terms) +{ + BOOST_MATH_STD_USING // ADL of std names + + typedef detail::fraction_traits<Gen> traits; + typedef typename traits::result_type result_type; + typedef typename traits::value_type value_type; + + result_type tiny = tools::min_value<result_type>(); + + value_type v = g(); + + result_type f, C, D, delta; + f = traits::b(v); + if(f == 0) + f = tiny; + C = f; + D = 0; + + boost::uintmax_t counter(max_terms); + + do{ + v = g(); + D = traits::b(v) + traits::a(v) * D; + if(D == 0) + D = tiny; + C = traits::b(v) + traits::a(v) / C; + if(C == 0) + C = tiny; + D = 1/D; + delta = C*D; + f = f * delta; + }while((fabs(delta - 1) > factor) && --counter); + + max_terms = max_terms - counter; + + return f; +} + +template <class Gen, class U> +inline typename detail::fraction_traits<Gen>::result_type continued_fraction_b(Gen& g, const U& factor) +{ + boost::uintmax_t max_terms = (std::numeric_limits<boost::uintmax_t>::max)(); + return continued_fraction_b(g, factor, max_terms); +} + +template <class Gen> +inline typename detail::fraction_traits<Gen>::result_type continued_fraction_b(Gen& g, int bits) +{ + BOOST_MATH_STD_USING // ADL of std names + + typedef detail::fraction_traits<Gen> traits; + typedef typename traits::result_type result_type; + + result_type factor = ldexp(1.0f, 1 - bits); // 1 / pow(result_type(2), bits); + boost::uintmax_t max_terms = (std::numeric_limits<boost::uintmax_t>::max)(); + return continued_fraction_b(g, factor, max_terms); +} + +template <class Gen> +inline typename detail::fraction_traits<Gen>::result_type continued_fraction_b(Gen& g, int bits, boost::uintmax_t& max_terms) +{ + BOOST_MATH_STD_USING // ADL of std names + + typedef detail::fraction_traits<Gen> traits; + typedef typename traits::result_type result_type; + + result_type factor = ldexp(1.0f, 1 - bits); // 1 / pow(result_type(2), bits); + return continued_fraction_b(g, factor, max_terms); +} + +// +// continued_fraction_a +// Evaluates: +// +// a1 +// --------------- +// b1 + a2 +// ---------- +// b2 + a3 +// ----- +// b3 + ... +// +// Note that the first a1 and b1 returned by generator Gen are both used. +// +template <class Gen, class U> +inline typename detail::fraction_traits<Gen>::result_type continued_fraction_a(Gen& g, const U& factor, boost::uintmax_t& max_terms) +{ + BOOST_MATH_STD_USING // ADL of std names + + typedef detail::fraction_traits<Gen> traits; + typedef typename traits::result_type result_type; + typedef typename traits::value_type value_type; + + result_type tiny = tools::min_value<result_type>(); + + value_type v = g(); + + result_type f, C, D, delta, a0; + f = traits::b(v); + a0 = traits::a(v); + if(f == 0) + f = tiny; + C = f; + D = 0; + + boost::uintmax_t counter(max_terms); + + do{ + v = g(); + D = traits::b(v) + traits::a(v) * D; + if(D == 0) + D = tiny; + C = traits::b(v) + traits::a(v) / C; + if(C == 0) + C = tiny; + D = 1/D; + delta = C*D; + f = f * delta; + }while((fabs(delta - 1) > factor) && --counter); + + max_terms = max_terms - counter; + + return a0/f; +} + +template <class Gen, class U> +inline typename detail::fraction_traits<Gen>::result_type continued_fraction_a(Gen& g, const U& factor) +{ + boost::uintmax_t max_iter = (std::numeric_limits<boost::uintmax_t>::max)(); + return continued_fraction_a(g, factor, max_iter); +} + +template <class Gen> +inline typename detail::fraction_traits<Gen>::result_type continued_fraction_a(Gen& g, int bits) +{ + BOOST_MATH_STD_USING // ADL of std names + + typedef detail::fraction_traits<Gen> traits; + typedef typename traits::result_type result_type; + + result_type factor = ldexp(1.0f, 1-bits); // 1 / pow(result_type(2), bits); + boost::uintmax_t max_iter = (std::numeric_limits<boost::uintmax_t>::max)(); + + return continued_fraction_a(g, factor, max_iter); +} + +template <class Gen> +inline typename detail::fraction_traits<Gen>::result_type continued_fraction_a(Gen& g, int bits, boost::uintmax_t& max_terms) +{ + BOOST_MATH_STD_USING // ADL of std names + + typedef detail::fraction_traits<Gen> traits; + typedef typename traits::result_type result_type; + + result_type factor = ldexp(1.0f, 1-bits); // 1 / pow(result_type(2), bits); + return continued_fraction_a(g, factor, max_terms); +} + +} // namespace tools +} // namespace math +} // namespace boost + +#endif // BOOST_MATH_TOOLS_FRACTION_INCLUDED + diff --git a/Utilities/BGL/boost/math/tools/minima.hpp b/Utilities/BGL/boost/math/tools/minima.hpp new file mode 100644 index 0000000000000000000000000000000000000000..e1fab1f9e0104208d26177e2198d32e25122507d --- /dev/null +++ b/Utilities/BGL/boost/math/tools/minima.hpp @@ -0,0 +1,152 @@ +// (C) Copyright John Maddock 2006. +// Use, modification and distribution are subject to 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) + + +#ifndef BOOST_MATH_TOOLS_MINIMA_HPP +#define BOOST_MATH_TOOLS_MINIMA_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <utility> +#include <boost/config/no_tr1/cmath.hpp> +#include <boost/math/tools/precision.hpp> +#include <boost/math/policies/policy.hpp> +#include <boost/cstdint.hpp> + +namespace boost{ namespace math{ namespace tools{ + +template <class F, class T> +std::pair<T, T> brent_find_minima(F f, T min, T max, int bits, boost::uintmax_t& max_iter) +{ + BOOST_MATH_STD_USING + bits = (std::min)(policies::digits<T, policies::policy<> >() / 2, bits); + T tolerance = static_cast<T>(ldexp(1.0, 1-bits)); + T x; // minima so far + T w; // second best point + T v; // previous value of w + T u; // most recent evaluation point + T delta; // The distance moved in the last step + T delta2; // The distance moved in the step before last + T fu, fv, fw, fx; // function evaluations at u, v, w, x + T mid; // midpoint of min and max + T fract1, fract2; // minimal relative movement in x + + static const T golden = 0.3819660f; // golden ratio, don't need too much precision here! + + x = w = v = max; + fw = fv = fx = f(x); + delta2 = delta = 0; + + uintmax_t count = max_iter; + + do{ + // get midpoint + mid = (min + max) / 2; + // work out if we're done already: + fract1 = tolerance * fabs(x) + tolerance / 4; + fract2 = 2 * fract1; + if(fabs(x - mid) <= (fract2 - (max - min) / 2)) + break; + + if(fabs(delta2) > fract1) + { + // try and construct a parabolic fit: + T r = (x - w) * (fx - fv); + T q = (x - v) * (fx - fw); + T p = (x - v) * q - (x - w) * r; + q = 2 * (q - r); + if(q > 0) + p = -p; + q = fabs(q); + T td = delta2; + delta2 = delta; + // determine whether a parabolic step is acceptible or not: + if((fabs(p) >= fabs(q * td / 2)) || (p <= q * (min - x)) || (p >= q * (max - x))) + { + // nope, try golden section instead + delta2 = (x >= mid) ? min - x : max - x; + delta = golden * delta2; + } + else + { + // whew, parabolic fit: + delta = p / q; + u = x + delta; + if(((u - min) < fract2) || ((max- u) < fract2)) + delta = (mid - x) < 0 ? (T)-fabs(fract1) : (T)fabs(fract1); + } + } + else + { + // golden section: + delta2 = (x >= mid) ? min - x : max - x; + delta = golden * delta2; + } + // update current position: + u = (fabs(delta) >= fract1) ? T(x + delta) : (delta > 0 ? T(x + fabs(fract1)) : T(x - fabs(fract1))); + fu = f(u); + if(fu <= fx) + { + // good new point is an improvement! + // update brackets: + if(u >= x) + min = x; + else + max = x; + // update control points: + v = w; + w = x; + x = u; + fv = fw; + fw = fx; + fx = fu; + } + else + { + // Oh dear, point u is worse than what we have already, + // even so it *must* be better than one of our endpoints: + if(u < x) + min = u; + else + max = u; + if((fu <= fw) || (w == x)) + { + // however it is at least second best: + v = w; + w = u; + fv = fw; + fw = fu; + } + else if((fu <= fv) || (v == x) || (v == w)) + { + // third best: + v = u; + fv = fu; + } + } + + }while(--count); + + max_iter -= count; + + return std::make_pair(x, fx); +} + +template <class F, class T> +inline std::pair<T, T> brent_find_minima(F f, T min, T max, int digits) +{ + boost::uintmax_t m = (std::numeric_limits<boost::uintmax_t>::max)(); + return brent_find_minima(f, min, max, digits, m); +} + +}}} // namespaces + +#endif + + + + diff --git a/Utilities/BGL/boost/math/tools/polynomial.hpp b/Utilities/BGL/boost/math/tools/polynomial.hpp new file mode 100644 index 0000000000000000000000000000000000000000..8225736b9e5838303d7bcfccdd76d9094ff3e022 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/polynomial.hpp @@ -0,0 +1,323 @@ +// (C) Copyright John Maddock 2006. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_TOOLS_POLYNOMIAL_HPP +#define BOOST_MATH_TOOLS_POLYNOMIAL_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/assert.hpp> +#include <boost/math/tools/rational.hpp> +#include <boost/math/tools/real_cast.hpp> +#include <boost/math/special_functions/binomial.hpp> + +#include <vector> +#include <ostream> +#include <algorithm> + +namespace boost{ namespace math{ namespace tools{ + +template <class T> +T chebyshev_coefficient(unsigned n, unsigned m) +{ + BOOST_MATH_STD_USING + if(m > n) + return 0; + if((n & 1) != (m & 1)) + return 0; + if(n == 0) + return 1; + T result = T(n) / 2; + unsigned r = n - m; + r /= 2; + + BOOST_ASSERT(n - 2 * r == m); + + if(r & 1) + result = -result; + result /= n - r; + result *= boost::math::binomial_coefficient<T>(n - r, r); + result *= ldexp(1.0f, m); + return result; +} + +template <class Seq> +Seq polynomial_to_chebyshev(const Seq& s) +{ + // Converts a Polynomial into Chebyshev form: + typedef typename Seq::value_type value_type; + typedef typename Seq::difference_type difference_type; + Seq result(s); + difference_type order = s.size() - 1; + difference_type even_order = order & 1 ? order - 1 : order; + difference_type odd_order = order & 1 ? order : order - 1; + + for(difference_type i = even_order; i >= 0; i -= 2) + { + value_type val = s[i]; + for(difference_type k = even_order; k > i; k -= 2) + { + val -= result[k] * chebyshev_coefficient<value_type>(static_cast<unsigned>(k), static_cast<unsigned>(i)); + } + val /= chebyshev_coefficient<value_type>(static_cast<unsigned>(i), static_cast<unsigned>(i)); + result[i] = val; + } + result[0] *= 2; + + for(difference_type i = odd_order; i >= 0; i -= 2) + { + value_type val = s[i]; + for(difference_type k = odd_order; k > i; k -= 2) + { + val -= result[k] * chebyshev_coefficient<value_type>(static_cast<unsigned>(k), static_cast<unsigned>(i)); + } + val /= chebyshev_coefficient<value_type>(static_cast<unsigned>(i), static_cast<unsigned>(i)); + result[i] = val; + } + return result; +} + +template <class Seq, class T> +T evaluate_chebyshev(const Seq& a, const T& x) +{ + // Clenshaw's formula: + typedef typename Seq::difference_type difference_type; + T yk2 = 0; + T yk1 = 0; + T yk = 0; + for(difference_type i = a.size() - 1; i >= 1; --i) + { + yk2 = yk1; + yk1 = yk; + yk = 2 * x * yk1 - yk2 + a[i]; + } + return a[0] / 2 + yk * x - yk1; +} + +template <class T> +class polynomial +{ +public: + // typedefs: + typedef typename std::vector<T>::value_type value_type; + typedef typename std::vector<T>::size_type size_type; + + // construct: + polynomial(){} + template <class U> + polynomial(const U* data, unsigned order) + : m_data(data, data + order + 1) + { + } + template <class U> + polynomial(const U& point) + { + m_data.push_back(point); + } + + // copy: + polynomial(const polynomial& p) + : m_data(p.m_data) { } + + template <class U> + polynomial(const polynomial<U>& p) + { + for(unsigned i = 0; i < p.size(); ++i) + { + m_data.push_back(boost::math::tools::real_cast<T>(p[i])); + } + } + + // access: + size_type size()const { return m_data.size(); } + size_type degree()const { return m_data.size() - 1; } + value_type& operator[](size_type i) + { + return m_data[i]; + } + const value_type& operator[](size_type i)const + { + return m_data[i]; + } + T evaluate(T z)const + { + return boost::math::tools::evaluate_polynomial(&m_data[0], z, m_data.size());; + } + std::vector<T> chebyshev()const + { + return polynomial_to_chebyshev(m_data); + } + + // operators: + template <class U> + polynomial& operator +=(const U& value) + { + if(m_data.size() == 0) + m_data.push_back(value); + else + { + m_data[0] += value; + } + return *this; + } + template <class U> + polynomial& operator -=(const U& value) + { + if(m_data.size() == 0) + m_data.push_back(-value); + else + { + m_data[0] -= value; + } + return *this; + } + template <class U> + polynomial& operator *=(const U& value) + { + for(size_type i = 0; i < m_data.size(); ++i) + m_data[i] *= value; + return *this; + } + template <class U> + polynomial& operator +=(const polynomial<U>& value) + { + size_type s1 = (std::min)(m_data.size(), value.size()); + for(size_type i = 0; i < s1; ++i) + m_data[i] += value[i]; + for(size_type i = s1; i < value.size(); ++i) + m_data.push_back(value[i]); + return *this; + } + template <class U> + polynomial& operator -=(const polynomial<U>& value) + { + size_type s1 = (std::min)(m_data.size(), value.size()); + for(size_type i = 0; i < s1; ++i) + m_data[i] -= value[i]; + for(size_type i = s1; i < value.size(); ++i) + m_data.push_back(-value[i]); + return *this; + } + template <class U> + polynomial& operator *=(const polynomial<U>& value) + { + // TODO: FIXME: use O(N log(N)) algorithm!!! + BOOST_ASSERT(value.size()); + polynomial base(*this); + *this *= value[0]; + for(size_type i = 1; i < value.size(); ++i) + { + polynomial t(base); + t *= value[i]; + size_type s = size() - i; + for(size_type j = 0; j < s; ++j) + { + m_data[i+j] += t[j]; + } + for(size_type j = s; j < t.size(); ++j) + m_data.push_back(t[j]); + } + return *this; + } + +private: + std::vector<T> m_data; +}; + +template <class T> +inline polynomial<T> operator + (const polynomial<T>& a, const polynomial<T>& b) +{ + polynomial<T> result(a); + result += b; + return result; +} + +template <class T> +inline polynomial<T> operator - (const polynomial<T>& a, const polynomial<T>& b) +{ + polynomial<T> result(a); + result -= b; + return result; +} + +template <class T> +inline polynomial<T> operator * (const polynomial<T>& a, const polynomial<T>& b) +{ + polynomial<T> result(a); + result *= b; + return result; +} + +template <class T, class U> +inline polynomial<T> operator + (const polynomial<T>& a, const U& b) +{ + polynomial<T> result(a); + result += b; + return result; +} + +template <class T, class U> +inline polynomial<T> operator - (const polynomial<T>& a, const U& b) +{ + polynomial<T> result(a); + result -= b; + return result; +} + +template <class T, class U> +inline polynomial<T> operator * (const polynomial<T>& a, const U& b) +{ + polynomial<T> result(a); + result *= b; + return result; +} + +template <class U, class T> +inline polynomial<T> operator + (const U& a, const polynomial<T>& b) +{ + polynomial<T> result(b); + result += a; + return result; +} + +template <class U, class T> +inline polynomial<T> operator - (const U& a, const polynomial<T>& b) +{ + polynomial<T> result(a); + result -= b; + return result; +} + +template <class U, class T> +inline polynomial<T> operator * (const U& a, const polynomial<T>& b) +{ + polynomial<T> result(b); + result *= a; + return result; +} + +template <class charT, class traits, class T> +inline std::basic_ostream<charT, traits>& operator << (std::basic_ostream<charT, traits>& os, const polynomial<T>& poly) +{ + os << "{ "; + for(unsigned i = 0; i < poly.size(); ++i) + { + if(i) os << ", "; + os << poly[i]; + } + os << " }"; + return os; +} + +} // namespace tools +} // namespace math +} // namespace boost + +#endif // BOOST_MATH_TOOLS_POLYNOMIAL_HPP + + + diff --git a/Utilities/BGL/boost/math/tools/precision.hpp b/Utilities/BGL/boost/math/tools/precision.hpp new file mode 100644 index 0000000000000000000000000000000000000000..dbdfc87c2c5b435b03199e5da6f28f2580b0b413 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/precision.hpp @@ -0,0 +1,322 @@ +// Copyright John Maddock 2005-2006. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_TOOLS_PRECISION_INCLUDED +#define BOOST_MATH_TOOLS_PRECISION_INCLUDED + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/limits.hpp> +#include <boost/assert.hpp> +#include <boost/static_assert.hpp> +#include <boost/mpl/int.hpp> +#include <boost/mpl/bool.hpp> +#include <boost/mpl/if.hpp> +#include <boost/math/policies/policy.hpp> + +#include <iostream> +#include <iomanip> +// These two are for LDBL_MAN_DIG: +#include <limits.h> +#include <math.h> + +namespace boost{ namespace math +{ +namespace tools +{ +// If T is not specialized, the functions digits, max_value and min_value, +// all get synthesised automatically from std::numeric_limits. +// However, if numeric_limits is not specialised for type RealType, +// for example with NTL::RR type, then you will get a compiler error +// when code tries to use these functions, unless you explicitly specialise them. + +// For example if the precision of RealType varies at runtime, +// then numeric_limits support may not be appropriate, +// see boost/math/tools/ntl.hpp for examples like +// template <> NTL::RR max_value<NTL::RR> ... +// See Conceptual Requirements for Real Number Types. + +template <class T> +inline int digits(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(T)) +{ +#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS + BOOST_STATIC_ASSERT( ::std::numeric_limits<T>::is_specialized); +#else + BOOST_ASSERT(::std::numeric_limits<T>::is_specialized); +#endif + return std::numeric_limits<T>::digits; +} + +template <class T> +inline T max_value(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(T)) +{ +#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS + BOOST_STATIC_ASSERT( ::std::numeric_limits<T>::is_specialized); +#else + BOOST_ASSERT(::std::numeric_limits<T>::is_specialized); +#endif + return (std::numeric_limits<T>::max)(); +} // Also used as a finite 'infinite' value for - and +infinity, for example: +// -max_value<double> = -1.79769e+308, max_value<double> = 1.79769e+308. + +template <class T> +inline T min_value(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(T)) +{ +#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS + BOOST_STATIC_ASSERT( ::std::numeric_limits<T>::is_specialized); +#else + BOOST_ASSERT(::std::numeric_limits<T>::is_specialized); +#endif + return (std::numeric_limits<T>::min)(); +} + +namespace detail{ +// +// Logarithmic limits come next, note that although +// we can compute these from the log of the max value +// that is not in general thread safe (if we cache the value) +// so it's better to specialise these: +// +// For type float first: +// +template <class T> +inline T log_max_value(const mpl::int_<128>& BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE(T)) +{ + return 88.0f; +} + +template <class T> +inline T log_min_value(const mpl::int_<128>& BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE(T)) +{ + return -87.0f; +} +// +// Now double: +// +template <class T> +inline T log_max_value(const mpl::int_<1024>& BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE(T)) +{ + return 709.0; +} + +template <class T> +inline T log_min_value(const mpl::int_<1024>& BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE(T)) +{ + return -708.0; +} +// +// 80 and 128-bit long doubles: +// +template <class T> +inline T log_max_value(const mpl::int_<16384>& BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE(T)) +{ + return 11356.0L; +} + +template <class T> +inline T log_min_value(const mpl::int_<16384>& BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE(T)) +{ + return -11355.0L; +} + +template <class T> +inline T log_max_value(const mpl::int_<0>& BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE(T)) +{ +#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS + BOOST_STATIC_ASSERT( ::std::numeric_limits<T>::is_specialized); +#else + BOOST_ASSERT(::std::numeric_limits<T>::is_specialized); +#endif + BOOST_MATH_STD_USING + static const T val = log((std::numeric_limits<T>::max)()); + return val; +} + +template <class T> +inline T log_min_value(const mpl::int_<0>& BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE(T)) +{ +#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS + BOOST_STATIC_ASSERT( ::std::numeric_limits<T>::is_specialized); +#else + BOOST_ASSERT(::std::numeric_limits<T>::is_specialized); +#endif + BOOST_MATH_STD_USING + static const T val = log((std::numeric_limits<T>::max)()); + return val; +} + +template <class T> +inline T epsilon(const mpl::true_& BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE(T)) +{ + return std::numeric_limits<T>::epsilon(); +} + +#if (defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__)) && ((LDBL_MANT_DIG == 106) || (__LDBL_MANT_DIG__ == 106)) +template <> +inline long double epsilon<long double>(const mpl::true_& BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE(long double)) +{ + // numeric_limits on Darwin tells lies here. + // This static assert fails for some unknown reason, so + // disabled for now... + // BOOST_STATIC_ASSERT(std::numeric_limits<long double>::digits == 106); + return 2.4651903288156618919116517665087e-32L; +} +#endif + +template <class T> +inline T epsilon(const mpl::false_& BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE(T)) +{ + BOOST_MATH_STD_USING // for ADL of std names + static const T eps = ldexp(static_cast<T>(1), 1-policies::digits<T, policies::policy<> >()); + return eps; +} + +} // namespace detail + +template <class T> +inline T log_max_value(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(T)) +{ +#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS + typedef typename mpl::if_c< + std::numeric_limits<T>::max_exponent == 128 + || std::numeric_limits<T>::max_exponent == 1024 + || std::numeric_limits<T>::max_exponent == 16384, + mpl::int_<std::numeric_limits<T>::max_exponent>, + mpl::int_<0> + >::type tag_type; + BOOST_STATIC_ASSERT( ::std::numeric_limits<T>::is_specialized); + return detail::log_max_value<T>(tag_type()); +#else + BOOST_ASSERT(::std::numeric_limits<T>::is_specialized); + BOOST_MATH_STD_USING + static const T val = log((std::numeric_limits<T>::max)()); + return val; +#endif +} + +template <class T> +inline T log_min_value(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(T)) +{ +#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS + typedef typename mpl::if_c< + std::numeric_limits<T>::max_exponent == 128 + || std::numeric_limits<T>::max_exponent == 1024 + || std::numeric_limits<T>::max_exponent == 16384, + mpl::int_<std::numeric_limits<T>::max_exponent>, + mpl::int_<0> + >::type tag_type; + + BOOST_STATIC_ASSERT( ::std::numeric_limits<T>::is_specialized); + return detail::log_min_value<T>(tag_type()); +#else + BOOST_ASSERT(::std::numeric_limits<T>::is_specialized); + BOOST_MATH_STD_USING + static const T val = log((std::numeric_limits<T>::min)()); + return val; +#endif +} + +template <class T> +inline T epsilon(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(T)) +{ +#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS + return detail::epsilon<T>(mpl::bool_< ::std::numeric_limits<T>::is_specialized>()); +#else + return ::std::numeric_limits<T>::is_specialized ? + detail::epsilon<T>(mpl::true_()) : + detail::epsilon<T>(mpl::false_()); +#endif +} + +namespace detail{ + +template <class T> +inline T root_epsilon_imp(const mpl::int_<24>&) +{ + return static_cast<T>(0.00034526698300124390839884978618400831996329879769945L); +} + +template <class T> +inline T root_epsilon_imp(const T*, const mpl::int_<53>&) +{ + return static_cast<T>(0.1490116119384765625e-7L); +} + +template <class T> +inline T root_epsilon_imp(const T*, const mpl::int_<64>&) +{ + return static_cast<T>(0.32927225399135962333569506281281311031656150598474e-9L); +} + +template <class T> +inline T root_epsilon_imp(const T*, const mpl::int_<113>&) +{ + return static_cast<T>(0.1387778780781445675529539585113525390625e-16L); +} + +template <class T, class Tag> +inline T root_epsilon_imp(const T*, const Tag&) +{ + BOOST_MATH_STD_USING + static const T r_eps = sqrt(tools::epsilon<T>()); + return r_eps; +} + +template <class T> +inline T forth_root_epsilon_imp(const T*, const mpl::int_<24>&) +{ + return static_cast<T>(0.018581361171917516667460937040007436176452688944747L); +} + +template <class T> +inline T forth_root_epsilon_imp(const T*, const mpl::int_<53>&) +{ + return static_cast<T>(0.0001220703125L); +} + +template <class T> +inline T forth_root_epsilon_imp(const T*, const mpl::int_<64>&) +{ + return static_cast<T>(0.18145860519450699870567321328132261891067079047605e-4L); +} + +template <class T> +inline T forth_root_epsilon_imp(const T*, const mpl::int_<113>&) +{ + return static_cast<T>(0.37252902984619140625e-8L); +} + +template <class T, class Tag> +inline T forth_root_epsilon_imp(const T*, const Tag&) +{ + BOOST_MATH_STD_USING + static const T r_eps = sqrt(sqrt(tools::epsilon<T>())); + return r_eps; +} + +} + +template <class T> +inline T root_epsilon() +{ + typedef mpl::int_<std::numeric_limits<T>::digits> tag_type; + return detail::root_epsilon_imp(static_cast<T const*>(0), tag_type()); +} + +template <class T> +inline T forth_root_epsilon() +{ + typedef mpl::int_<std::numeric_limits<T>::digits> tag_type; + return detail::forth_root_epsilon_imp(static_cast<T const*>(0), tag_type()); +} + +} // namespace tools +} // namespace math +} // namespace boost + +#endif // BOOST_MATH_TOOLS_PRECISION_INCLUDED + diff --git a/Utilities/BGL/boost/math/tools/promotion.hpp b/Utilities/BGL/boost/math/tools/promotion.hpp new file mode 100644 index 0000000000000000000000000000000000000000..cff6916577ea37ddaeb561972b67e77c3c57429c --- /dev/null +++ b/Utilities/BGL/boost/math/tools/promotion.hpp @@ -0,0 +1,149 @@ +// boost\math\tools\promotion.hpp + +// Copyright John Maddock 2006. +// Copyright Paul A. Bristow 2006. + +// Use, modification and distribution are subject to 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) + +// Promote arguments functions to allow math functions to have arguments +// provided as integer OR real (floating-point, built-in or UDT) +// (called ArithmeticType in functions that use promotion) +// that help to reduce the risk of creating multiple instantiations. +// Allows creation of an inline wrapper that forwards to a foo(RT, RT) function, +// so you never get to instantiate any mixed foo(RT, IT) functions. + +#ifndef BOOST_MATH_PROMOTION_HPP +#define BOOST_MATH_PROMOTION_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +// Boost type traits: +#include <boost/math/tools/config.hpp> +#include <boost/type_traits/is_floating_point.hpp> // for boost::is_floating_point; +#include <boost/type_traits/is_integral.hpp> // for boost::is_integral +#include <boost/type_traits/is_convertible.hpp> // for boost::is_convertible +#include <boost/type_traits/is_same.hpp>// for boost::is_same +#include <boost/type_traits/remove_cv.hpp>// for boost::remove_cv +// Boost Template meta programming: +#include <boost/mpl/if.hpp> // for boost::mpl::if_c. +#include <boost/mpl/and.hpp> // for boost::mpl::if_c. +#include <boost/mpl/or.hpp> // for boost::mpl::if_c. + +#ifdef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS +#include <boost/static_assert.hpp> +#endif + +namespace boost +{ + namespace math + { + namespace tools + { + // If either T1 or T2 is an integer type, + // pretend it was a double (for the purposes of further analysis). + // Then pick the wider of the two floating-point types + // as the actual signature to forward to. + // For example: + // foo(int, short) -> double foo(double, double); + // foo(int, float) -> double foo(double, double); + // Note: NOT float foo(float, float) + // foo(int, double) -> foo(double, double); + // foo(double, float) -> double foo(double, double); + // foo(double, float) -> double foo(double, double); + // foo(any-int-or-float-type, long double) -> foo(long double, long double); + // but ONLY float foo(float, float) is unchanged. + // So the only way to get an entirely float version is to call foo(1.F, 2.F), + // But since most (all?) the math functions convert to double internally, + // probably there would not be the hoped-for gain by using float here. + + // This follows the C-compatible conversion rules of pow, etc + // where pow(int, float) is converted to pow(double, double). + + template <class T> + struct promote_arg + { // If T is integral type, then promote to double. + typedef typename mpl::if_<is_integral<T>, double, T>::type type; + }; + // These full specialisations reduce mpl::if_ usage and speed up + // compilation: + template <> struct promote_arg<float> { typedef float type; }; + template <> struct promote_arg<double>{ typedef double type; }; + template <> struct promote_arg<long double> { typedef long double type; }; + template <> struct promote_arg<int> { typedef double type; }; + + template <class T1, class T2> + struct promote_args_2 + { // Promote, if necessary, & pick the wider of the two floating-point types. + // for both parameter types, if integral promote to double. + typedef typename promote_arg<T1>::type T1P; // T1 perhaps promoted. + typedef typename promote_arg<T2>::type T2P; // T2 perhaps promoted. + + typedef typename mpl::if_< + typename mpl::and_<is_floating_point<T1P>, is_floating_point<T2P> >::type, // both T1P and T2P are floating-point? + typename mpl::if_< typename mpl::or_<is_same<long double, T1P>, is_same<long double, T2P> >::type, // either long double? + long double, // then result type is long double. + typename mpl::if_< typename mpl::or_<is_same<double, T1P>, is_same<double, T2P> >::type, // either double? + double, // result type is double. + float // else result type is float. + >::type + >::type, + // else one or the other is a user-defined type: + typename mpl::if_< ::boost::is_convertible<T1P, T2P>, T2P, T1P>::type>::type type; + }; // promote_arg2 + // These full specialisations reduce mpl::if_ usage and speed up + // compilation: + template <> struct promote_args_2<float, float> { typedef float type; }; + template <> struct promote_args_2<double, double>{ typedef double type; }; + template <> struct promote_args_2<long double, long double> { typedef long double type; }; + template <> struct promote_args_2<int, int> { typedef double type; }; + template <> struct promote_args_2<int, float> { typedef double type; }; + template <> struct promote_args_2<float, int> { typedef double type; }; + template <> struct promote_args_2<int, double> { typedef double type; }; + template <> struct promote_args_2<double, int> { typedef double type; }; + template <> struct promote_args_2<int, long double> { typedef long double type; }; + template <> struct promote_args_2<long double, int> { typedef long double type; }; + template <> struct promote_args_2<float, double> { typedef double type; }; + template <> struct promote_args_2<double, float> { typedef double type; }; + template <> struct promote_args_2<float, long double> { typedef long double type; }; + template <> struct promote_args_2<long double, float> { typedef long double type; }; + template <> struct promote_args_2<double, long double> { typedef long double type; }; + template <> struct promote_args_2<long double, double> { typedef long double type; }; + + template <class T1, class T2=float, class T3=float, class T4=float, class T5=float, class T6=float> + struct promote_args + { + typedef typename promote_args_2< + typename remove_cv<T1>::type, + typename promote_args_2< + typename remove_cv<T2>::type, + typename promote_args_2< + typename remove_cv<T3>::type, + typename promote_args_2< + typename remove_cv<T4>::type, + typename promote_args_2< + typename remove_cv<T5>::type, typename remove_cv<T6>::type + >::type + >::type + >::type + >::type + >::type type; + +#ifdef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS + // + // Guard against use of long double if it's not supported: + // + BOOST_STATIC_ASSERT((0 == ::boost::is_same<type, long double>::value)); +#endif + }; + + } // namespace tools + } // namespace math +} // namespace boost + +#endif // BOOST_MATH_PROMOTION_HPP + diff --git a/Utilities/BGL/boost/math/tools/rational.hpp b/Utilities/BGL/boost/math/tools/rational.hpp new file mode 100644 index 0000000000000000000000000000000000000000..9f80a13262fc933eb51e9c04319a7313eb2efbc1 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/rational.hpp @@ -0,0 +1,333 @@ +// (C) Copyright John Maddock 2006. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_TOOLS_RATIONAL_HPP +#define BOOST_MATH_TOOLS_RATIONAL_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/array.hpp> +#include <boost/math/tools/config.hpp> +#include <boost/mpl/int.hpp> + +#if BOOST_MATH_POLY_METHOD == 1 +# define BOOST_HEADER() <BOOST_JOIN(boost/math/tools/detail/polynomial_horner1_, BOOST_MATH_MAX_POLY_ORDER).hpp> +# include BOOST_HEADER() +# undef BOOST_HEADER +#elif BOOST_MATH_POLY_METHOD == 2 +# define BOOST_HEADER() <BOOST_JOIN(boost/math/tools/detail/polynomial_horner2_, BOOST_MATH_MAX_POLY_ORDER).hpp> +# include BOOST_HEADER() +# undef BOOST_HEADER +#elif BOOST_MATH_POLY_METHOD == 3 +# define BOOST_HEADER() <BOOST_JOIN(boost/math/tools/detail/polynomial_horner3_, BOOST_MATH_MAX_POLY_ORDER).hpp> +# include BOOST_HEADER() +# undef BOOST_HEADER +#endif +#if BOOST_MATH_RATIONAL_METHOD == 1 +# define BOOST_HEADER() <BOOST_JOIN(boost/math/tools/detail/rational_horner1_, BOOST_MATH_MAX_POLY_ORDER).hpp> +# include BOOST_HEADER() +# undef BOOST_HEADER +#elif BOOST_MATH_RATIONAL_METHOD == 2 +# define BOOST_HEADER() <BOOST_JOIN(boost/math/tools/detail/rational_horner2_, BOOST_MATH_MAX_POLY_ORDER).hpp> +# include BOOST_HEADER() +# undef BOOST_HEADER +#elif BOOST_MATH_RATIONAL_METHOD == 3 +# define BOOST_HEADER() <BOOST_JOIN(boost/math/tools/detail/rational_horner3_, BOOST_MATH_MAX_POLY_ORDER).hpp> +# include BOOST_HEADER() +# undef BOOST_HEADER +#endif + +#if 0 +// +// This just allows dependency trackers to find the headers +// used in the above PP-magic. +// +#include <boost/math/tools/detail/polynomial_horner1_2.hpp> +#include <boost/math/tools/detail/polynomial_horner1_3.hpp> +#include <boost/math/tools/detail/polynomial_horner1_4.hpp> +#include <boost/math/tools/detail/polynomial_horner1_5.hpp> +#include <boost/math/tools/detail/polynomial_horner1_6.hpp> +#include <boost/math/tools/detail/polynomial_horner1_7.hpp> +#include <boost/math/tools/detail/polynomial_horner1_8.hpp> +#include <boost/math/tools/detail/polynomial_horner1_9.hpp> +#include <boost/math/tools/detail/polynomial_horner1_10.hpp> +#include <boost/math/tools/detail/polynomial_horner1_11.hpp> +#include <boost/math/tools/detail/polynomial_horner1_12.hpp> +#include <boost/math/tools/detail/polynomial_horner1_13.hpp> +#include <boost/math/tools/detail/polynomial_horner1_14.hpp> +#include <boost/math/tools/detail/polynomial_horner1_15.hpp> +#include <boost/math/tools/detail/polynomial_horner1_16.hpp> +#include <boost/math/tools/detail/polynomial_horner1_17.hpp> +#include <boost/math/tools/detail/polynomial_horner1_18.hpp> +#include <boost/math/tools/detail/polynomial_horner1_19.hpp> +#include <boost/math/tools/detail/polynomial_horner1_20.hpp> +#include <boost/math/tools/detail/polynomial_horner2_2.hpp> +#include <boost/math/tools/detail/polynomial_horner2_3.hpp> +#include <boost/math/tools/detail/polynomial_horner2_4.hpp> +#include <boost/math/tools/detail/polynomial_horner2_5.hpp> +#include <boost/math/tools/detail/polynomial_horner2_6.hpp> +#include <boost/math/tools/detail/polynomial_horner2_7.hpp> +#include <boost/math/tools/detail/polynomial_horner2_8.hpp> +#include <boost/math/tools/detail/polynomial_horner2_9.hpp> +#include <boost/math/tools/detail/polynomial_horner2_10.hpp> +#include <boost/math/tools/detail/polynomial_horner2_11.hpp> +#include <boost/math/tools/detail/polynomial_horner2_12.hpp> +#include <boost/math/tools/detail/polynomial_horner2_13.hpp> +#include <boost/math/tools/detail/polynomial_horner2_14.hpp> +#include <boost/math/tools/detail/polynomial_horner2_15.hpp> +#include <boost/math/tools/detail/polynomial_horner2_16.hpp> +#include <boost/math/tools/detail/polynomial_horner2_17.hpp> +#include <boost/math/tools/detail/polynomial_horner2_18.hpp> +#include <boost/math/tools/detail/polynomial_horner2_19.hpp> +#include <boost/math/tools/detail/polynomial_horner2_20.hpp> +#include <boost/math/tools/detail/polynomial_horner3_2.hpp> +#include <boost/math/tools/detail/polynomial_horner3_3.hpp> +#include <boost/math/tools/detail/polynomial_horner3_4.hpp> +#include <boost/math/tools/detail/polynomial_horner3_5.hpp> +#include <boost/math/tools/detail/polynomial_horner3_6.hpp> +#include <boost/math/tools/detail/polynomial_horner3_7.hpp> +#include <boost/math/tools/detail/polynomial_horner3_8.hpp> +#include <boost/math/tools/detail/polynomial_horner3_9.hpp> +#include <boost/math/tools/detail/polynomial_horner3_10.hpp> +#include <boost/math/tools/detail/polynomial_horner3_11.hpp> +#include <boost/math/tools/detail/polynomial_horner3_12.hpp> +#include <boost/math/tools/detail/polynomial_horner3_13.hpp> +#include <boost/math/tools/detail/polynomial_horner3_14.hpp> +#include <boost/math/tools/detail/polynomial_horner3_15.hpp> +#include <boost/math/tools/detail/polynomial_horner3_16.hpp> +#include <boost/math/tools/detail/polynomial_horner3_17.hpp> +#include <boost/math/tools/detail/polynomial_horner3_18.hpp> +#include <boost/math/tools/detail/polynomial_horner3_19.hpp> +#include <boost/math/tools/detail/polynomial_horner3_20.hpp> +#include <boost/math/tools/detail/rational_horner1_2.hpp> +#include <boost/math/tools/detail/rational_horner1_3.hpp> +#include <boost/math/tools/detail/rational_horner1_4.hpp> +#include <boost/math/tools/detail/rational_horner1_5.hpp> +#include <boost/math/tools/detail/rational_horner1_6.hpp> +#include <boost/math/tools/detail/rational_horner1_7.hpp> +#include <boost/math/tools/detail/rational_horner1_8.hpp> +#include <boost/math/tools/detail/rational_horner1_9.hpp> +#include <boost/math/tools/detail/rational_horner1_10.hpp> +#include <boost/math/tools/detail/rational_horner1_11.hpp> +#include <boost/math/tools/detail/rational_horner1_12.hpp> +#include <boost/math/tools/detail/rational_horner1_13.hpp> +#include <boost/math/tools/detail/rational_horner1_14.hpp> +#include <boost/math/tools/detail/rational_horner1_15.hpp> +#include <boost/math/tools/detail/rational_horner1_16.hpp> +#include <boost/math/tools/detail/rational_horner1_17.hpp> +#include <boost/math/tools/detail/rational_horner1_18.hpp> +#include <boost/math/tools/detail/rational_horner1_19.hpp> +#include <boost/math/tools/detail/rational_horner1_20.hpp> +#include <boost/math/tools/detail/rational_horner2_2.hpp> +#include <boost/math/tools/detail/rational_horner2_3.hpp> +#include <boost/math/tools/detail/rational_horner2_4.hpp> +#include <boost/math/tools/detail/rational_horner2_5.hpp> +#include <boost/math/tools/detail/rational_horner2_6.hpp> +#include <boost/math/tools/detail/rational_horner2_7.hpp> +#include <boost/math/tools/detail/rational_horner2_8.hpp> +#include <boost/math/tools/detail/rational_horner2_9.hpp> +#include <boost/math/tools/detail/rational_horner2_10.hpp> +#include <boost/math/tools/detail/rational_horner2_11.hpp> +#include <boost/math/tools/detail/rational_horner2_12.hpp> +#include <boost/math/tools/detail/rational_horner2_13.hpp> +#include <boost/math/tools/detail/rational_horner2_14.hpp> +#include <boost/math/tools/detail/rational_horner2_15.hpp> +#include <boost/math/tools/detail/rational_horner2_16.hpp> +#include <boost/math/tools/detail/rational_horner2_17.hpp> +#include <boost/math/tools/detail/rational_horner2_18.hpp> +#include <boost/math/tools/detail/rational_horner2_19.hpp> +#include <boost/math/tools/detail/rational_horner2_20.hpp> +#include <boost/math/tools/detail/rational_horner3_2.hpp> +#include <boost/math/tools/detail/rational_horner3_3.hpp> +#include <boost/math/tools/detail/rational_horner3_4.hpp> +#include <boost/math/tools/detail/rational_horner3_5.hpp> +#include <boost/math/tools/detail/rational_horner3_6.hpp> +#include <boost/math/tools/detail/rational_horner3_7.hpp> +#include <boost/math/tools/detail/rational_horner3_8.hpp> +#include <boost/math/tools/detail/rational_horner3_9.hpp> +#include <boost/math/tools/detail/rational_horner3_10.hpp> +#include <boost/math/tools/detail/rational_horner3_11.hpp> +#include <boost/math/tools/detail/rational_horner3_12.hpp> +#include <boost/math/tools/detail/rational_horner3_13.hpp> +#include <boost/math/tools/detail/rational_horner3_14.hpp> +#include <boost/math/tools/detail/rational_horner3_15.hpp> +#include <boost/math/tools/detail/rational_horner3_16.hpp> +#include <boost/math/tools/detail/rational_horner3_17.hpp> +#include <boost/math/tools/detail/rational_horner3_18.hpp> +#include <boost/math/tools/detail/rational_horner3_19.hpp> +#include <boost/math/tools/detail/rational_horner3_20.hpp> +#endif + +namespace boost{ namespace math{ namespace tools{ + +// +// Forward declaration to keep two phase lookup happy: +// +template <class T, class U> +U evaluate_polynomial(const T* poly, U const& z, std::size_t count); + +namespace detail{ + +template <class T, class V, class Tag> +inline V evaluate_polynomial_c_imp(const T* a, const V& val, const Tag*) +{ + return evaluate_polynomial(a, val, Tag::value); +} + +} // namespace detail + +// +// Polynomial evaluation with runtime size. +// This requires a for-loop which may be more expensive than +// the loop expanded versions above: +// +template <class T, class U> +inline U evaluate_polynomial(const T* poly, U const& z, std::size_t count) +{ + BOOST_ASSERT(count > 0); + U sum = static_cast<U>(poly[count - 1]); + for(int i = static_cast<int>(count) - 2; i >= 0; --i) + { + sum *= z; + sum += static_cast<U>(poly[i]); + } + return sum; +} +// +// Compile time sized polynomials, just inline forwarders to the +// implementations above: +// +template <std::size_t N, class T, class V> +inline V evaluate_polynomial(const T(&a)[N], const V& val) +{ + typedef mpl::int_<N> tag_type; + return detail::evaluate_polynomial_c_imp(static_cast<const T*>(a), val, static_cast<tag_type const*>(0)); +} + +template <std::size_t N, class T, class V> +inline V evaluate_polynomial(const boost::array<T,N>& a, const V& val) +{ + typedef mpl::int_<N> tag_type; + return detail::evaluate_polynomial_c_imp(static_cast<const T*>(a.data()), val, static_cast<tag_type const*>(0)); +} +// +// Even polynomials are trivial: just square the argument! +// +template <class T, class U> +inline U evaluate_even_polynomial(const T* poly, U z, std::size_t count) +{ + return evaluate_polynomial(poly, U(z*z), count); +} + +template <std::size_t N, class T, class V> +inline V evaluate_even_polynomial(const T(&a)[N], const V& z) +{ + return evaluate_polynomial(a, V(z*z)); +} + +template <std::size_t N, class T, class V> +inline V evaluate_even_polynomial(const boost::array<T,N>& a, const V& z) +{ + return evaluate_polynomial(a, V(z*z)); +} +// +// Odd polynomials come next: +// +template <class T, class U> +inline U evaluate_odd_polynomial(const T* poly, U z, std::size_t count) +{ + return poly[0] + z * evaluate_polynomial(poly+1, U(z*z), count-1); +} + +template <std::size_t N, class T, class V> +inline V evaluate_odd_polynomial(const T(&a)[N], const V& z) +{ + typedef mpl::int_<N-1> tag_type; + return a[0] + z * detail::evaluate_polynomial_c_imp(static_cast<const T*>(a) + 1, V(z*z), static_cast<tag_type const*>(0)); +} + +template <std::size_t N, class T, class V> +inline V evaluate_odd_polynomial(const boost::array<T,N>& a, const V& z) +{ + typedef mpl::int_<N-1> tag_type; + return a[0] + z * detail::evaluate_polynomial_c_imp(static_cast<const T*>(a.data()) + 1, V(z*z), static_cast<tag_type const*>(0)); +} + +template <class T, class U, class V> +V evaluate_rational(const T* num, const U* denom, const V& z_, std::size_t count); + +namespace detail{ + +template <class T, class U, class V, class Tag> +inline V evaluate_rational_c_imp(const T* num, const U* denom, const V& z, const Tag*) +{ + return boost::math::tools::evaluate_rational(num, denom, z, Tag::value); +} + +} +// +// Rational functions: numerator and denominator must be +// equal in size. These always have a for-loop and so may be less +// efficient than evaluating a pair of polynomials. However, there +// are some tricks we can use to prevent overflow that might otherwise +// occur in polynomial evaluation, if z is large. This is important +// in our Lanczos code for example. +// +template <class T, class U, class V> +V evaluate_rational(const T* num, const U* denom, const V& z_, std::size_t count) +{ + V z(z_); + V s1, s2; + if(z <= 1) + { + s1 = static_cast<V>(num[count-1]); + s2 = static_cast<V>(denom[count-1]); + for(int i = (int)count - 2; i >= 0; --i) + { + s1 *= z; + s2 *= z; + s1 += num[i]; + s2 += denom[i]; + } + } + else + { + z = 1 / z; + s1 = static_cast<V>(num[0]); + s2 = static_cast<V>(denom[0]); + for(unsigned i = 1; i < count; ++i) + { + s1 *= z; + s2 *= z; + s1 += num[i]; + s2 += denom[i]; + } + } + return s1 / s2; +} + +template <std::size_t N, class T, class U, class V> +inline V evaluate_rational(const T(&a)[N], const U(&b)[N], const V& z) +{ + return detail::evaluate_rational_c_imp(a, b, z, static_cast<const mpl::int_<N>*>(0)); +} + +template <std::size_t N, class T, class U, class V> +inline V evaluate_rational(const boost::array<T,N>& a, const boost::array<U,N>& b, const V& z) +{ + return detail::evaluate_rational_c_imp(a.data(), b.data(), z, static_cast<mpl::int_<N>*>(0)); +} + +} // namespace tools +} // namespace math +} // namespace boost + +#endif // BOOST_MATH_TOOLS_RATIONAL_HPP + + + + diff --git a/Utilities/BGL/boost/math/tools/real_cast.hpp b/Utilities/BGL/boost/math/tools/real_cast.hpp new file mode 100644 index 0000000000000000000000000000000000000000..8bcb273d6d294beb42f507136e3c830dc7f1552d --- /dev/null +++ b/Utilities/BGL/boost/math/tools/real_cast.hpp @@ -0,0 +1,29 @@ +// Copyright John Maddock 2006. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_TOOLS_REAL_CAST_HPP +#define BOOST_MATH_TOOLS_REAL_CAST_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +namespace boost{ namespace math +{ + namespace tools + { + template <class To, class T> + inline To real_cast(T t) + { + return static_cast<To>(t); + } + } // namespace tools +} // namespace math +} // namespace boost + +#endif // BOOST_MATH_TOOLS_REAL_CAST_HPP + + + diff --git a/Utilities/BGL/boost/math/tools/remez.hpp b/Utilities/BGL/boost/math/tools/remez.hpp new file mode 100644 index 0000000000000000000000000000000000000000..b5573106024964587844d0417b04e4c2eed82e54 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/remez.hpp @@ -0,0 +1,667 @@ +// (C) Copyright John Maddock 2006. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_TOOLS_REMEZ_HPP +#define BOOST_MATH_TOOLS_REMEZ_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/math/tools/solve.hpp> +#include <boost/math/tools/minima.hpp> +#include <boost/math/tools/roots.hpp> +#include <boost/math/tools/polynomial.hpp> +#include <boost/function/function1.hpp> +#include <boost/scoped_array.hpp> +#include <boost/math/constants/constants.hpp> +#include <boost/math/policies/policy.hpp> + +namespace boost{ namespace math{ namespace tools{ + +namespace detail{ + +// +// The error function: the difference between F(x) and +// the current approximation. This is the function +// for which we must find the extema. +// +template <class T> +struct remez_error_function +{ + typedef boost::function1<T, T const &> function_type; +public: + remez_error_function( + function_type f_, + const polynomial<T>& n, + const polynomial<T>& d, + bool rel_err) + : f(f_), numerator(n), denominator(d), rel_error(rel_err) {} + + T operator()(const T& z)const + { + T y = f(z); + T abs = y - (numerator.evaluate(z) / denominator.evaluate(z)); + T err; + if(rel_error) + { + if(y != 0) + err = abs / fabs(y); + else if(0 == abs) + { + // we must be at a root, or it's not recoverable: + BOOST_ASSERT(0 == abs); + err = 0; + } + else + { + // We have a divide by zero! + // Lets assume that f(x) is zero as a result of + // internal cancellation error that occurs as a result + // of shifting a root at point z to the origin so that + // the approximation can be "pinned" to pass through + // the origin: in that case it really + // won't matter what our approximation calculates here + // as long as it's a small number, return the absolute error: + err = abs; + } + } + else + err = abs; + return err; + } +private: + function_type f; + polynomial<T> numerator; + polynomial<T> denominator; + bool rel_error; +}; +// +// This function adapts the error function so that it's minima +// are the extema of the error function. We can find the minima +// with standard techniques. +// +template <class T> +struct remez_max_error_function +{ + remez_max_error_function(const remez_error_function<T>& f) + : func(f) {} + + T operator()(const T& x) + { + BOOST_MATH_STD_USING + return -fabs(func(x)); + } +private: + remez_error_function<T> func; +}; + +} // detail + +template <class T> +class remez_minimax +{ +public: + typedef boost::function1<T, T const &> function_type; + typedef boost::numeric::ublas::vector<T> vector_type; + typedef boost::numeric::ublas::matrix<T> matrix_type; + + remez_minimax(function_type f, unsigned oN, unsigned oD, T a, T b, bool pin = true, bool rel_err = false, int sk = 0, int bits = 0); + remez_minimax(function_type f, unsigned oN, unsigned oD, T a, T b, bool pin, bool rel_err, int sk, int bits, const vector_type& points); + + void reset(unsigned oN, unsigned oD, T a, T b, bool pin = true, bool rel_err = false, int sk = 0, int bits = 0); + void reset(unsigned oN, unsigned oD, T a, T b, bool pin, bool rel_err, int sk, int bits, const vector_type& points); + + void set_brake(int b) + { + BOOST_ASSERT(b < 100); + BOOST_ASSERT(b >= 0); + m_brake = b; + } + + T iterate(); + + polynomial<T> denominator()const; + polynomial<T> numerator()const; + + vector_type const& chebyshev_points()const + { + return control_points; + } + + vector_type const& zero_points()const + { + return zeros; + } + + T error_term()const + { + return solution[solution.size() - 1]; + } + T max_error()const + { + return m_max_error; + } + T max_change()const + { + return m_max_change; + } + void rotate() + { + --orderN; + ++orderD; + } + void rescale(T a, T b) + { + T scale = (b - a) / (max - min); + for(unsigned i = 0; i < control_points.size(); ++i) + { + control_points[i] = (control_points[i] - min) * scale + a; + } + min = a; + max = b; + } +private: + + void init_chebyshev(); + + function_type func; // The function to approximate. + vector_type control_points; // Current control points to be used for the next iteration. + vector_type solution; // Solution from the last iteration contains all unknowns including the error term. + vector_type zeros; // Location of points of zero error from last iteration, plus the two end points. + vector_type maxima; // Location of maxima of the error function, actually contains the control points used for the last iteration. + T m_max_error; // Maximum error found in last approximation. + T m_max_change; // Maximum change in location of control points after last iteration. + unsigned orderN; // Order of the numerator polynomial. + unsigned orderD; // Order of the denominator polynomial. + T min, max; // End points of the range to optimise over. + bool rel_error; // If true optimise for relative not absolute error. + bool pinned; // If true the approximation is "pinned" to go through the origin. + unsigned unknowns; // Total number of unknowns. + int m_precision; // Number of bits precision to which the zeros and maxima are found. + T m_max_change_history[2]; // Past history of changes to control points. + int m_brake; // amount to break by in percentage points. + int m_skew; // amount to skew starting points by in percentage points: -100-100 +}; + +#ifndef BRAKE +#define BRAKE 0 +#endif +#ifndef SKEW +#define SKEW 0 +#endif + +template <class T> +void remez_minimax<T>::init_chebyshev() +{ + BOOST_MATH_STD_USING + // + // Fill in the zeros: + // + unsigned terms = pinned ? orderD + orderN : orderD + orderN + 1; + + for(unsigned i = 0; i < terms; ++i) + { + T cheb = cos((2 * terms - 1 - 2 * i) * constants::pi<T>() / (2 * terms)); + cheb += 1; + cheb /= 2; + if(m_skew != 0) + { + T p = static_cast<T>(200 + m_skew) / 200; + cheb = pow(cheb, p); + } + cheb *= (max - min); + cheb += min; + zeros[i+1] = cheb; + } + zeros[0] = min; + zeros[unknowns] = max; + // perform a regular interpolation fit: + matrix_type A(terms, terms); + vector_type b(terms); + // fill in the y values: + for(unsigned i = 0; i < b.size(); ++i) + { + b[i] = func(zeros[i+1]); + } + // fill in powers of x evaluated at each of the control points: + unsigned offsetN = pinned ? 0 : 1; + unsigned offsetD = offsetN + orderN; + unsigned maxorder = (std::max)(orderN, orderD); + for(unsigned i = 0; i < b.size(); ++i) + { + T x0 = zeros[i+1]; + T x = x0; + if(!pinned) + A(i, 0) = 1; + for(unsigned j = 0; j < maxorder; ++j) + { + if(j < orderN) + A(i, j + offsetN) = x; + if(j < orderD) + { + A(i, j + offsetD) = -x * b[i]; + } + x *= x0; + } + } + // + // Now go ahead and solve the expression to get our solution: + // + vector_type l_solution = boost::math::tools::solve(A, b); + // need to add a "fake" error term: + l_solution.resize(unknowns); + l_solution[unknowns-1] = 0; + solution = l_solution; + // + // Now find all the extrema of the error function: + // + detail::remez_error_function<T> Err(func, this->numerator(), this->denominator(), rel_error); + detail::remez_max_error_function<T> Ex(Err); + m_max_error = 0; + int max_err_location = 0; + for(unsigned i = 0; i < unknowns; ++i) + { + std::pair<T, T> r = brent_find_minima(Ex, zeros[i], zeros[i+1], m_precision); + maxima[i] = r.first; + T rel_err = fabs(r.second); + if(rel_err > m_max_error) + { + m_max_error = fabs(r.second); + max_err_location = i; + } + } + control_points = maxima; +} + +template <class T> +void remez_minimax<T>::reset( + unsigned oN, + unsigned oD, + T a, + T b, + bool pin, + bool rel_err, + int sk, + int bits) +{ + control_points = vector_type(oN + oD + (pin ? 1 : 2)); + solution = control_points; + zeros = vector_type(oN + oD + (pin ? 2 : 3)); + maxima = control_points; + orderN = oN; + orderD = oD; + rel_error = rel_err; + pinned = pin; + m_skew = sk; + min = a; + max = b; + m_max_error = 0; + unknowns = orderN + orderD + (pinned ? 1 : 2); + // guess our initial control points: + control_points[0] = min; + control_points[unknowns - 1] = max; + T interval = (max - min) / (unknowns - 1); + T spot = min + interval; + for(unsigned i = 1; i < control_points.size(); ++i) + { + control_points[i] = spot; + spot += interval; + } + solution[unknowns - 1] = 0; + m_max_error = 0; + if(bits == 0) + { + // don't bother about more than float precision: + m_precision = (std::min)(24, (boost::math::policies::digits<T, boost::math::policies::policy<> >() / 2) - 2); + } + else + { + // can't be more accurate than half the bits of T: + m_precision = (std::min)(bits, (boost::math::policies::digits<T, boost::math::policies::policy<> >() / 2) - 2); + } + m_max_change_history[0] = m_max_change_history[1] = 1; + init_chebyshev(); + // do one iteration whatever: + //iterate(); +} + +template <class T> +inline remez_minimax<T>::remez_minimax( + typename remez_minimax<T>::function_type f, + unsigned oN, + unsigned oD, + T a, + T b, + bool pin, + bool rel_err, + int sk, + int bits) + : func(f) +{ + m_brake = 0; + reset(oN, oD, a, b, pin, rel_err, sk, bits); +} + +template <class T> +void remez_minimax<T>::reset( + unsigned oN, + unsigned oD, + T a, + T b, + bool pin, + bool rel_err, + int sk, + int bits, + const vector_type& points) +{ + control_points = vector_type(oN + oD + (pin ? 1 : 2)); + solution = control_points; + zeros = vector_type(oN + oD + (pin ? 2 : 3)); + maxima = control_points; + orderN = oN; + orderD = oD; + rel_error = rel_err; + pinned = pin; + m_skew = sk; + min = a; + max = b; + m_max_error = 0; + unknowns = orderN + orderD + (pinned ? 1 : 2); + control_points = points; + solution[unknowns - 1] = 0; + m_max_error = 0; + if(bits == 0) + { + // don't bother about more than float precision: + m_precision = (std::min)(24, (boost::math::policies::digits<T, boost::math::policies::policy<> >() / 2) - 2); + } + else + { + // can't be more accurate than half the bits of T: + m_precision = (std::min)(bits, (boost::math::policies::digits<T, boost::math::policies::policy<> >() / 2) - 2); + } + m_max_change_history[0] = m_max_change_history[1] = 1; + // do one iteration whatever: + //iterate(); +} + +template <class T> +inline remez_minimax<T>::remez_minimax( + typename remez_minimax<T>::function_type f, + unsigned oN, + unsigned oD, + T a, + T b, + bool pin, + bool rel_err, + int sk, + int bits, + const vector_type& points) + : func(f) +{ + m_brake = 0; + reset(oN, oD, a, b, pin, rel_err, sk, bits, points); +} + +template <class T> +T remez_minimax<T>::iterate() +{ + BOOST_MATH_STD_USING + matrix_type A(unknowns, unknowns); + vector_type b(unknowns); + + // fill in evaluation of f(x) at each of the control points: + for(unsigned i = 0; i < b.size(); ++i) + { + // take care that none of our control points are at the origin: + if(pinned && (control_points[i] == 0)) + { + if(i) + control_points[i] = control_points[i-1] / 3; + else + control_points[i] = control_points[i+1] / 3; + } + b[i] = func(control_points[i]); + } + + T err_err; + unsigned convergence_count = 0; + do{ + // fill in powers of x evaluated at each of the control points: + int sign = 1; + unsigned offsetN = pinned ? 0 : 1; + unsigned offsetD = offsetN + orderN; + unsigned maxorder = (std::max)(orderN, orderD); + T Elast = solution[unknowns - 1]; + + for(unsigned i = 0; i < b.size(); ++i) + { + T x0 = control_points[i]; + T x = x0; + if(!pinned) + A(i, 0) = 1; + for(unsigned j = 0; j < maxorder; ++j) + { + if(j < orderN) + A(i, j + offsetN) = x; + if(j < orderD) + { + T mult = rel_error ? (b[i] - sign * fabs(b[i]) * Elast): (b[i] - sign * Elast); + A(i, j + offsetD) = -x * mult; + } + x *= x0; + } + // The last variable to be solved for is the error term, + // sign changes with each control point: + T E = rel_error ? sign * fabs(b[i]) : sign; + A(i, unknowns - 1) = E; + sign = -sign; + } + + #ifdef BOOST_MATH_INSTRUMENT + for(unsigned i = 0; i < b.size(); ++i) + std::cout << b[i] << " "; + std::cout << "\n\n"; + for(unsigned i = 0; i < b.size(); ++i) + { + for(unsigned j = 0; j < b.size(); ++ j) + std::cout << A(i, j) << " "; + std::cout << "\n"; + } + std::cout << std::endl; + #endif + // + // Now go ahead and solve the expression to get our solution: + // + solution = boost::math::tools::solve(A, b); + + err_err = (Elast != 0) ? fabs((fabs(solution[unknowns-1]) - fabs(Elast)) / fabs(Elast)) : 1; + }while(orderD && (convergence_count++ < 80) && (err_err > 0.001)); + + // + // Perform a sanity check to verify that the solution to the equations + // is not so much in error as to be useless. The matrix inversion can + // be very close to singular, so this can be a real problem. + // + vector_type sanity = prod(A, solution); + for(unsigned i = 0; i < b.size(); ++i) + { + T err = fabs((b[i] - sanity[i]) / fabs(b[i])); + if(err > sqrt(epsilon<T>())) + { + std::cerr << "Sanity check failed: more than half the digits in the found solution are in error." << std::endl; + } + } + + // + // Next comes another sanity check, we want to verify that all the control + // points do actually alternate in sign, in practice we may have + // additional roots in the error function that cause this to fail. + // Failure here is always fatal: even though this code attempts to correct + // the problem it usually only postpones the inevitable. + // + polynomial<T> num, denom; + num = this->numerator(); + denom = this->denominator(); + T e1 = b[0] - num.evaluate(control_points[0]) / denom.evaluate(control_points[0]); +#ifdef BOOST_MATH_INSTRUMENT + std::cout << e1; +#endif + for(unsigned i = 1; i < b.size(); ++i) + { + T e2 = b[i] - num.evaluate(control_points[i]) / denom.evaluate(control_points[i]); +#ifdef BOOST_MATH_INSTRUMENT + std::cout << " " << e2; +#endif + if(e2 * e1 > 0) + { + std::cerr << std::flush << "Basic sanity check failed: Error term does not alternate in sign, non-recoverable error may follow..." << std::endl; + T perturbation = 0.05; + do{ + T point = control_points[i] * (1 - perturbation) + control_points[i-1] * perturbation; + e2 = func(point) - num.evaluate(point) / denom.evaluate(point); + if(e2 * e1 < 0) + { + control_points[i] = point; + break; + } + perturbation += 0.05; + }while(perturbation < 0.8); + + if((e2 * e1 > 0) && (i + 1 < b.size())) + { + perturbation = 0.05; + do{ + T point = control_points[i] * (1 - perturbation) + control_points[i+1] * perturbation; + e2 = func(point) - num.evaluate(point) / denom.evaluate(point); + if(e2 * e1 < 0) + { + control_points[i] = point; + break; + } + perturbation += 0.05; + }while(perturbation < 0.8); + } + + } + e1 = e2; + } + +#ifdef BOOST_MATH_INSTRUMENT + for(unsigned i = 0; i < solution.size(); ++i) + std::cout << solution[i] << " "; + std::cout << std::endl << this->numerator() << std::endl; + std::cout << this->denominator() << std::endl; + std::cout << std::endl; +#endif + + // + // The next step is to find all the intervals in which our maxima + // lie: + // + detail::remez_error_function<T> Err(func, this->numerator(), this->denominator(), rel_error); + zeros[0] = min; + zeros[unknowns] = max; + for(unsigned i = 1; i < control_points.size(); ++i) + { + eps_tolerance<T> tol(m_precision); + boost::uintmax_t max_iter = 1000; + std::pair<T, T> p = toms748_solve( + Err, + control_points[i-1], + control_points[i], + tol, + max_iter); + zeros[i] = (p.first + p.second) / 2; + //zeros[i] = bisect(Err, control_points[i-1], control_points[i], m_precision); + } + // + // Now find all the extrema of the error function: + // + detail::remez_max_error_function<T> Ex(Err); + m_max_error = 0; + int max_err_location = 0; + for(unsigned i = 0; i < unknowns; ++i) + { + std::pair<T, T> r = brent_find_minima(Ex, zeros[i], zeros[i+1], m_precision); + maxima[i] = r.first; + T rel_err = fabs(r.second); + if(rel_err > m_max_error) + { + m_max_error = fabs(r.second); + max_err_location = i; + } + } + // + // Almost done now! we just need to set our control points + // to the extrema, and calculate how much each point has changed + // (this will be our termination condition): + // + swap(control_points, maxima); + m_max_change = 0; + int max_change_location = 0; + for(unsigned i = 0; i < unknowns; ++i) + { + control_points[i] = (control_points[i] * (100 - m_brake) + maxima[i] * m_brake) / 100; + T change = fabs((control_points[i] - maxima[i]) / control_points[i]); +#if 0 + if(change > m_max_change_history[1]) + { + // divergence!!! try capping the change: + std::cerr << "Possible divergent step, change will be capped!!" << std::endl; + change = m_max_change_history[1]; + if(control_points[i] < maxima[i]) + control_points[i] = maxima[i] - change * maxima[i]; + else + control_points[i] = maxima[i] + change * maxima[i]; + } +#endif + if(change > m_max_change) + { + m_max_change = change; + max_change_location = i; + } + } + // + // store max change information: + // + m_max_change_history[0] = m_max_change_history[1]; + m_max_change_history[1] = fabs(m_max_change); + + return m_max_change; +} + +template <class T> +polynomial<T> remez_minimax<T>::numerator()const +{ + boost::scoped_array<T> a(new T[orderN + 1]); + if(pinned) + a[0] = 0; + unsigned terms = pinned ? orderN : orderN + 1; + for(unsigned i = 0; i < terms; ++i) + a[pinned ? i+1 : i] = solution[i]; + return boost::math::tools::polynomial<T>(&a[0], orderN); +} + +template <class T> +polynomial<T> remez_minimax<T>::denominator()const +{ + unsigned terms = orderD + 1; + unsigned offsetD = pinned ? orderN : (orderN + 1); + boost::scoped_array<T> a(new T[terms]); + a[0] = 1; + for(unsigned i = 0; i < orderD; ++i) + a[i+1] = solution[i + offsetD]; + return boost::math::tools::polynomial<T>(&a[0], orderD); +} + + +}}} // namespaces + +#endif // BOOST_MATH_TOOLS_REMEZ_HPP + + + diff --git a/Utilities/BGL/boost/math/tools/roots.hpp b/Utilities/BGL/boost/math/tools/roots.hpp new file mode 100644 index 0000000000000000000000000000000000000000..a8eb660b74d71e7b44928a4967ad2aa65512cce9 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/roots.hpp @@ -0,0 +1,534 @@ +// (C) Copyright John Maddock 2006. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_TOOLS_NEWTON_SOLVER_HPP +#define BOOST_MATH_TOOLS_NEWTON_SOLVER_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <utility> +#include <boost/config/no_tr1/cmath.hpp> +#include <stdexcept> + +#include <boost/tr1/tuple.hpp> +#include <boost/math/tools/config.hpp> +#include <boost/cstdint.hpp> +#include <boost/assert.hpp> +#include <boost/throw_exception.hpp> + +#ifdef BOOST_MSVC +#pragma warning(push) +#pragma warning(disable: 4512) +#endif +#include <boost/tr1/tuple.hpp> +#ifdef BOOST_MSVC +#pragma warning(pop) +#endif + +#include <boost/math/special_functions/sign.hpp> +#include <boost/math/tools/toms748_solve.hpp> +#include <boost/math/policies/error_handling.hpp> + +namespace boost{ namespace math{ namespace tools{ + +namespace detail{ + +template <class Tuple, class T> +inline void unpack_0(const Tuple& t, T& val) +{ val = std::tr1::get<0>(t); } + +template <class F, class T> +void handle_zero_derivative(F f, + T& last_f0, + const T& f0, + T& delta, + T& result, + T& guess, + const T& min, + const T& max) +{ + if(last_f0 == 0) + { + // this must be the first iteration, pretend that we had a + // previous one at either min or max: + if(result == min) + { + guess = max; + } + else + { + guess = min; + } + unpack_0(f(guess), last_f0); + //last_f0 = std::tr1::get<0>(f(guess)); + delta = guess - result; + } + if(sign(last_f0) * sign(f0) < 0) + { + // we've crossed over so move in opposite direction to last step: + if(delta < 0) + { + delta = (result - min) / 2; + } + else + { + delta = (result - max) / 2; + } + } + else + { + // move in same direction as last step: + if(delta < 0) + { + delta = (result - max) / 2; + } + else + { + delta = (result - min) / 2; + } + } +} + +} // namespace + +template <class F, class T, class Tol, class Policy> +std::pair<T, T> bisect(F f, T min, T max, Tol tol, boost::uintmax_t& max_iter, const Policy& pol) +{ + T fmin = f(min); + T fmax = f(max); + if(fmin == 0) + return std::make_pair(min, min); + if(fmax == 0) + return std::make_pair(max, max); + + // + // Error checking: + // + static const char* function = "boost::math::tools::bisect<%1%>"; + if(min >= max) + { + policies::raise_evaluation_error(function, + "Arguments in wrong order in boost::math::tools::bisect (first arg=%1%)", min, pol); + } + if(fmin * fmax >= 0) + { + policies::raise_evaluation_error(function, + "No change of sign in boost::math::tools::bisect, either there is no root to find, or there are multiple roots in the interval (f(min) = %1%).", fmin, pol); + } + + // + // Three function invocations so far: + // + boost::uintmax_t count = max_iter; + if(count < 3) + count = 0; + else + count -= 3; + + while(count && (0 == tol(min, max))) + { + T mid = (min + max) / 2; + T fmid = f(mid); + if((mid == max) || (mid == min)) + break; + if(fmid == 0) + { + min = max = mid; + break; + } + else if(sign(fmid) * sign(fmin) < 0) + { + max = mid; + fmax = fmid; + } + else + { + min = mid; + fmin = fmid; + } + --count; + } + + max_iter -= count; + +#ifdef BOOST_MATH_INSTRUMENT + std::cout << "Bisection iteration, final count = " << max_iter << std::endl; + + static boost::uintmax_t max_count = 0; + if(max_iter > max_count) + { + max_count = max_iter; + std::cout << "Maximum iterations: " << max_iter << std::endl; + } +#endif + + return std::make_pair(min, max); +} + +template <class F, class T, class Tol> +inline std::pair<T, T> bisect(F f, T min, T max, Tol tol, boost::uintmax_t& max_iter) +{ + return bisect(f, min, max, tol, max_iter, policies::policy<>()); +} + +template <class F, class T, class Tol> +inline std::pair<T, T> bisect(F f, T min, T max, Tol tol) +{ + boost::uintmax_t m = (std::numeric_limits<boost::uintmax_t>::max)(); + return bisect(f, min, max, tol, m, policies::policy<>()); +} + +template <class F, class T> +T newton_raphson_iterate(F f, T guess, T min, T max, int digits, boost::uintmax_t& max_iter) +{ + BOOST_MATH_STD_USING + + T f0(0), f1, last_f0(0); + T result = guess; + + T factor = static_cast<T>(ldexp(1.0, 1 - digits)); + T delta = 1; + T delta1 = tools::max_value<T>(); + T delta2 = tools::max_value<T>(); + + boost::uintmax_t count(max_iter); + + do{ + last_f0 = f0; + delta2 = delta1; + delta1 = delta; + std::tr1::tie(f0, f1) = f(result); + if(0 == f0) + break; + if(f1 == 0) + { + // Oops zero derivative!!! +#ifdef BOOST_MATH_INSTRUMENT + std::cout << "Newton iteration, zero derivative found" << std::endl; +#endif + detail::handle_zero_derivative(f, last_f0, f0, delta, result, guess, min, max); + } + else + { + delta = f0 / f1; + } +#ifdef BOOST_MATH_INSTRUMENT + std::cout << "Newton iteration, delta = " << delta << std::endl; +#endif + if(fabs(delta * 2) > fabs(delta2)) + { + // last two steps haven't converged, try bisection: + delta = (delta > 0) ? (result - min) / 2 : (result - max) / 2; + } + guess = result; + result -= delta; + if(result <= min) + { + delta = 0.5F * (guess - min); + result = guess - delta; + if((result == min) || (result == max)) + break; + } + else if(result >= max) + { + delta = 0.5F * (guess - max); + result = guess - delta; + if((result == min) || (result == max)) + break; + } + // update brackets: + if(delta > 0) + max = guess; + else + min = guess; + }while(--count && (fabs(result * factor) < fabs(delta))); + + max_iter -= count; + +#ifdef BOOST_MATH_INSTRUMENT + std::cout << "Newton Raphson iteration, final count = " << max_iter << std::endl; + + static boost::uintmax_t max_count = 0; + if(max_iter > max_count) + { + max_count = max_iter; + std::cout << "Maximum iterations: " << max_iter << std::endl; + } +#endif + + return result; +} + +template <class F, class T> +inline T newton_raphson_iterate(F f, T guess, T min, T max, int digits) +{ + boost::uintmax_t m = (std::numeric_limits<boost::uintmax_t>::max)(); + return newton_raphson_iterate(f, guess, min, max, digits, m); +} + +template <class F, class T> +T halley_iterate(F f, T guess, T min, T max, int digits, boost::uintmax_t& max_iter) +{ + BOOST_MATH_STD_USING + + T f0(0), f1, f2; + T result = guess; + + T factor = static_cast<T>(ldexp(1.0, 1 - digits)); + T delta = (std::max)(T(10000000 * guess), T(10000000)); // arbitarily large delta + T last_f0 = 0; + T delta1 = delta; + T delta2 = delta; + + bool out_of_bounds_sentry = false; + +#ifdef BOOST_MATH_INSTRUMENT + std::cout << "Halley iteration, limit = " << factor << std::endl; +#endif + + boost::uintmax_t count(max_iter); + + do{ + last_f0 = f0; + delta2 = delta1; + delta1 = delta; + std::tr1::tie(f0, f1, f2) = f(result); + + BOOST_MATH_INSTRUMENT_VARIABLE(f0); + BOOST_MATH_INSTRUMENT_VARIABLE(f1); + BOOST_MATH_INSTRUMENT_VARIABLE(f2); + + if(0 == f0) + break; + if((f1 == 0) && (f2 == 0)) + { + // Oops zero derivative!!! +#ifdef BOOST_MATH_INSTRUMENT + std::cout << "Halley iteration, zero derivative found" << std::endl; +#endif + detail::handle_zero_derivative(f, last_f0, f0, delta, result, guess, min, max); + } + else + { + if(f2 != 0) + { + T denom = 2 * f0; + T num = 2 * f1 - f0 * (f2 / f1); + + BOOST_MATH_INSTRUMENT_VARIABLE(denom); + BOOST_MATH_INSTRUMENT_VARIABLE(num); + + if((fabs(num) < 1) && (fabs(denom) >= fabs(num) * tools::max_value<T>())) + { + // possible overflow, use Newton step: + delta = f0 / f1; + } + else + delta = denom / num; + if(delta * f1 / f0 < 0) + { + // probably cancellation error, try a Newton step instead: + delta = f0 / f1; + } + } + else + delta = f0 / f1; + } +#ifdef BOOST_MATH_INSTRUMENT + std::cout << "Halley iteration, delta = " << delta << std::endl; +#endif + T convergence = fabs(delta / delta2); + if((convergence > 0.8) && (convergence < 2)) + { + // last two steps haven't converged, try bisection: + delta = (delta > 0) ? (result - min) / 2 : (result - max) / 2; + if(fabs(delta) > result) + delta = sign(delta) * result; // protect against huge jumps! + // reset delta2 so that this branch will *not* be taken on the + // next iteration: + delta2 = delta * 3; + BOOST_MATH_INSTRUMENT_VARIABLE(delta); + } + guess = result; + result -= delta; + BOOST_MATH_INSTRUMENT_VARIABLE(result); + + // check for out of bounds step: + if(result < min) + { + T diff = ((fabs(min) < 1) && (fabs(result) > 1) && (tools::max_value<T>() / fabs(result) < fabs(min))) ? T(1000) : T(result / min); + if(fabs(diff) < 1) + diff = 1 / diff; + if(!out_of_bounds_sentry && (diff > 0) && (diff < 3)) + { + // Only a small out of bounds step, lets assume that the result + // is probably approximately at min: + delta = 0.99f * (guess - min); + result = guess - delta; + out_of_bounds_sentry = true; // only take this branch once! + } + else + { + delta = (guess - min) / 2; + result = guess - delta; + if((result == min) || (result == max)) + break; + } + } + else if(result > max) + { + T diff = ((fabs(max) < 1) && (fabs(result) > 1) && (tools::max_value<T>() / fabs(result) < fabs(max))) ? T(1000) : T(result / max); + if(fabs(diff) < 1) + diff = 1 / diff; + if(!out_of_bounds_sentry && (diff > 0) && (diff < 3)) + { + // Only a small out of bounds step, lets assume that the result + // is probably approximately at min: + delta = 0.99f * (guess - max); + result = guess - delta; + out_of_bounds_sentry = true; // only take this branch once! + } + else + { + delta = (guess - max) / 2; + result = guess - delta; + if((result == min) || (result == max)) + break; + } + } + // update brackets: + if(delta > 0) + max = guess; + else + min = guess; + }while(--count && (fabs(result * factor) < fabs(delta))); + + max_iter -= count; + +#ifdef BOOST_MATH_INSTRUMENT + std::cout << "Halley iteration, final count = " << max_iter << std::endl; +#endif + + return result; +} + +template <class F, class T> +inline T halley_iterate(F f, T guess, T min, T max, int digits) +{ + boost::uintmax_t m = (std::numeric_limits<boost::uintmax_t>::max)(); + return halley_iterate(f, guess, min, max, digits, m); +} + +template <class F, class T> +T schroeder_iterate(F f, T guess, T min, T max, int digits, boost::uintmax_t& max_iter) +{ + BOOST_MATH_STD_USING + + T f0(0), f1, f2, last_f0(0); + T result = guess; + + T factor = static_cast<T>(ldexp(1.0, 1 - digits)); + T delta = 0; + T delta1 = tools::max_value<T>(); + T delta2 = tools::max_value<T>(); + +#ifdef BOOST_MATH_INSTRUMENT + std::cout << "Schroeder iteration, limit = " << factor << std::endl; +#endif + + boost::uintmax_t count(max_iter); + + do{ + last_f0 = f0; + delta2 = delta1; + delta1 = delta; + std::tr1::tie(f0, f1, f2) = f(result); + if(0 == f0) + break; + if((f1 == 0) && (f2 == 0)) + { + // Oops zero derivative!!! +#ifdef BOOST_MATH_INSTRUMENT + std::cout << "Halley iteration, zero derivative found" << std::endl; +#endif + detail::handle_zero_derivative(f, last_f0, f0, delta, result, guess, min, max); + } + else + { + T ratio = f0 / f1; + if(ratio / result < 0.1) + { + delta = ratio + (f2 / (2 * f1)) * ratio * ratio; + // check second derivative doesn't over compensate: + if(delta * ratio < 0) + delta = ratio; + } + else + delta = ratio; // fall back to Newton iteration. + } + if(fabs(delta * 2) > fabs(delta2)) + { + // last two steps haven't converged, try bisection: + delta = (delta > 0) ? (result - min) / 2 : (result - max) / 2; + } + guess = result; + result -= delta; +#ifdef BOOST_MATH_INSTRUMENT + std::cout << "Halley iteration, delta = " << delta << std::endl; +#endif + if(result <= min) + { + delta = 0.5F * (guess - min); + result = guess - delta; + if((result == min) || (result == max)) + break; + } + else if(result >= max) + { + delta = 0.5F * (guess - max); + result = guess - delta; + if((result == min) || (result == max)) + break; + } + // update brackets: + if(delta > 0) + max = guess; + else + min = guess; + }while(--count && (fabs(result * factor) < fabs(delta))); + + max_iter -= count; + +#ifdef BOOST_MATH_INSTRUMENT + std::cout << "Schroeder iteration, final count = " << max_iter << std::endl; + + static boost::uintmax_t max_count = 0; + if(max_iter > max_count) + { + max_count = max_iter; + std::cout << "Maximum iterations: " << max_iter << std::endl; + } +#endif + + return result; +} + +template <class F, class T> +inline T schroeder_iterate(F f, T guess, T min, T max, int digits) +{ + boost::uintmax_t m = (std::numeric_limits<boost::uintmax_t>::max)(); + return schroeder_iterate(f, guess, min, max, digits, m); +} + +} // namespace tools +} // namespace math +} // namespace boost + +#endif // BOOST_MATH_TOOLS_NEWTON_SOLVER_HPP + + + diff --git a/Utilities/BGL/boost/math/tools/series.hpp b/Utilities/BGL/boost/math/tools/series.hpp new file mode 100644 index 0000000000000000000000000000000000000000..36b50764c4110b5c8025388e25e7fdfb4f334956 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/series.hpp @@ -0,0 +1,158 @@ +// (C) Copyright John Maddock 2005-2006. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_TOOLS_SERIES_INCLUDED +#define BOOST_MATH_TOOLS_SERIES_INCLUDED + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/config/no_tr1/cmath.hpp> +#include <boost/cstdint.hpp> +#include <boost/limits.hpp> +#include <boost/math/tools/config.hpp> + +namespace boost{ namespace math{ namespace tools{ + +// +// Simple series summation come first: +// +template <class Functor, class U, class V> +inline typename Functor::result_type sum_series(Functor& func, const U& factor, boost::uintmax_t& max_terms, const V& init_value) +{ + BOOST_MATH_STD_USING + + typedef typename Functor::result_type result_type; + + boost::uintmax_t counter = max_terms; + + result_type result = init_value; + result_type next_term; + do{ + next_term = func(); + result += next_term; + } + while((fabs(factor * result) < fabs(next_term)) && --counter); + + // set max_terms to the actual number of terms of the series evaluated: + max_terms = max_terms - counter; + + return result; +} + +template <class Functor, class U> +inline typename Functor::result_type sum_series(Functor& func, const U& factor, boost::uintmax_t& max_terms) +{ + typename Functor::result_type init_value = 0; + return sum_series(func, factor, max_terms, init_value); +} + +template <class Functor, class U> +inline typename Functor::result_type sum_series(Functor& func, int bits, boost::uintmax_t& max_terms, const U& init_value) +{ + BOOST_MATH_STD_USING + typedef typename Functor::result_type result_type; + result_type factor = ldexp(result_type(1), 1 - bits); + return sum_series(func, factor, max_terms, init_value); +} + +template <class Functor> +inline typename Functor::result_type sum_series(Functor& func, int bits) +{ + BOOST_MATH_STD_USING + typedef typename Functor::result_type result_type; + boost::uintmax_t iters = (std::numeric_limits<boost::uintmax_t>::max)(); + result_type init_val = 0; + return sum_series(func, bits, iters, init_val); +} + +template <class Functor> +inline typename Functor::result_type sum_series(Functor& func, int bits, boost::uintmax_t& max_terms) +{ + BOOST_MATH_STD_USING + typedef typename Functor::result_type result_type; + result_type init_val = 0; + return sum_series(func, bits, max_terms, init_val); +} + +template <class Functor, class U> +inline typename Functor::result_type sum_series(Functor& func, int bits, const U& init_value) +{ + BOOST_MATH_STD_USING + boost::uintmax_t iters = (std::numeric_limits<boost::uintmax_t>::max)(); + return sum_series(func, bits, iters, init_value); +} + +// +// Algorithm kahan_sum_series invokes Functor func until the N'th +// term is too small to have any effect on the total, the terms +// are added using the Kahan summation method. +// +// CAUTION: Optimizing compilers combined with extended-precision +// machine registers conspire to render this algorithm partly broken: +// double rounding of intermediate terms (first to a long double machine +// register, and then to a double result) cause the rounding error computed +// by the algorithm to be off by up to 1ulp. However this occurs rarely, and +// in any case the result is still much better than a naive summation. +// +template <class Functor> +inline typename Functor::result_type kahan_sum_series(Functor& func, int bits) +{ + BOOST_MATH_STD_USING + + typedef typename Functor::result_type result_type; + + result_type factor = pow(result_type(2), bits); + result_type result = func(); + result_type next_term, y, t; + result_type carry = 0; + do{ + next_term = func(); + y = next_term - carry; + t = result + y; + carry = t - result; + carry -= y; + result = t; + } + while(fabs(result) < fabs(factor * next_term)); + return result; +} + +template <class Functor> +inline typename Functor::result_type kahan_sum_series(Functor& func, int bits, boost::uintmax_t& max_terms) +{ + BOOST_MATH_STD_USING + + typedef typename Functor::result_type result_type; + + boost::uintmax_t counter = max_terms; + + result_type factor = ldexp(result_type(1), bits); + result_type result = func(); + result_type next_term, y, t; + result_type carry = 0; + do{ + next_term = func(); + y = next_term - carry; + t = result + y; + carry = t - result; + carry -= y; + result = t; + } + while((fabs(result) < fabs(factor * next_term)) && --counter); + + // set max_terms to the actual number of terms of the series evaluated: + max_terms = max_terms - counter; + + return result; +} + +} // namespace tools +} // namespace math +} // namespace boost + +#endif // BOOST_MATH_TOOLS_SERIES_INCLUDED + diff --git a/Utilities/BGL/boost/math/tools/solve.hpp b/Utilities/BGL/boost/math/tools/solve.hpp new file mode 100644 index 0000000000000000000000000000000000000000..928427cf13abdc5938cf7ba819f6c69e87d422b9 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/solve.hpp @@ -0,0 +1,79 @@ +// (C) Copyright John Maddock 2006. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_TOOLS_SOLVE_HPP +#define BOOST_MATH_TOOLS_SOLVE_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/config.hpp> +#include <boost/assert.hpp> + +#ifdef BOOST_MSVC +#pragma warning(push) +#pragma warning(disable:4996 4267 4244) +#endif + +#include <boost/numeric/ublas/lu.hpp> +#include <boost/numeric/ublas/matrix.hpp> +#include <boost/numeric/ublas/vector.hpp> + +#ifdef BOOST_MSVC +#pragma warning(pop) +#endif + +namespace boost{ namespace math{ namespace tools{ + +// +// Find x such that Ax = b +// +// Caution: this uses undocumented, and untested ublas code, +// however short of writing our own LU-decompostion code +// it's the only game in town. +// +template <class T> +boost::numeric::ublas::vector<T> solve( + const boost::numeric::ublas::matrix<T>& A_, + const boost::numeric::ublas::vector<T>& b_) +{ + //BOOST_ASSERT(A_.size() == b_.size()); + + boost::numeric::ublas::matrix<T> A(A_); + boost::numeric::ublas::vector<T> b(b_); + boost::numeric::ublas::permutation_matrix<> piv(b.size()); + lu_factorize(A, piv); + lu_substitute(A, piv, b); + // + // iterate to reduce error: + // + boost::numeric::ublas::vector<T> delta(b.size()); + for(unsigned i = 0; i < 1; ++i) + { + noalias(delta) = prod(A_, b); + delta -= b_; + lu_substitute(A, piv, delta); + b -= delta; + + T max_error = 0; + + for(unsigned i = 0; i < delta.size(); ++i) + { + T err = fabs(delta[i] / b[i]); + if(err > max_error) + max_error = err; + } + //std::cout << "Max change in LU error correction: " << max_error << std::endl; + } + + return b; +} + +}}} // namespaces + +#endif // BOOST_MATH_TOOLS_SOLVE_HPP + + diff --git a/Utilities/BGL/boost/math/tools/stats.hpp b/Utilities/BGL/boost/math/tools/stats.hpp new file mode 100644 index 0000000000000000000000000000000000000000..3935991d7b1815443c8e32c87f14c92baf21ac0a --- /dev/null +++ b/Utilities/BGL/boost/math/tools/stats.hpp @@ -0,0 +1,88 @@ +// (C) Copyright John Maddock 2005-2006. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_TOOLS_STATS_INCLUDED +#define BOOST_MATH_TOOLS_STATS_INCLUDED + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/config/no_tr1/cmath.hpp> +#include <boost/cstdint.hpp> +#include <boost/math/tools/precision.hpp> + +namespace boost{ namespace math{ namespace tools{ + +template <class T> +class stats +{ +public: + stats() + : m_min(tools::max_value<T>()), + m_max(-tools::max_value<T>()), + m_total(0), + m_squared_total(0), + m_count(0) + {} + void add(const T& val) + { + if(val < m_min) + m_min = val; + if(val > m_max) + m_max = val; + m_total += val; + ++m_count; + m_squared_total += val*val; + } + T min BOOST_PREVENT_MACRO_SUBSTITUTION()const{ return m_min; } + T max BOOST_PREVENT_MACRO_SUBSTITUTION()const{ return m_max; } + T total()const{ return m_total; } + T mean()const{ return m_total / static_cast<T>(m_count); } + boost::uintmax_t count()const{ return m_count; } + T variance()const + { + BOOST_MATH_STD_USING + + T t = m_squared_total - m_total * m_total / m_count; + t /= m_count; + return t; + } + T variance1()const + { + BOOST_MATH_STD_USING + + T t = m_squared_total - m_total * m_total / m_count; + t /= (m_count-1); + return t; + } + T rms()const + { + BOOST_MATH_STD_USING + + return sqrt(m_squared_total / static_cast<T>(m_count)); + } + stats& operator+=(const stats& s) + { + if(s.m_min < m_min) + m_min = s.m_min; + if(s.m_max > m_max) + m_max = s.m_max; + m_total += s.m_total; + m_squared_total += s.m_squared_total; + m_count += s.m_count; + return *this; + } +private: + T m_min, m_max, m_total, m_squared_total; + boost::uintmax_t m_count; +}; + +} // namespace tools +} // namespace math +} // namespace boost + +#endif + diff --git a/Utilities/BGL/boost/math/tools/test.hpp b/Utilities/BGL/boost/math/tools/test.hpp new file mode 100644 index 0000000000000000000000000000000000000000..f74f3aabee22bfa908817854f21be65b742dc284 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/test.hpp @@ -0,0 +1,257 @@ +// (C) Copyright John Maddock 2006. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_TOOLS_TEST_HPP +#define BOOST_MATH_TOOLS_TEST_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/math/tools/config.hpp> +#include <boost/math/tools/stats.hpp> +#include <boost/math/special_functions/fpclassify.hpp> +#include <boost/test/test_tools.hpp> +#include <stdexcept> + +namespace boost{ namespace math{ namespace tools{ + +template <class T> +struct test_result +{ +private: + boost::math::tools::stats<T> stat; // Statistics for the test. + unsigned worst_case; // Index of the worst case test. +public: + test_result() { worst_case = 0; } + void set_worst(int i){ worst_case = i; } + void add(const T& point){ stat.add(point); } + // accessors: + unsigned worst()const{ return worst_case; } + T min BOOST_PREVENT_MACRO_SUBSTITUTION()const{ return (stat.min)(); } + T max BOOST_PREVENT_MACRO_SUBSTITUTION()const{ return (stat.max)(); } + T total()const{ return stat.total(); } + T mean()const{ return stat.mean(); } + boost::uintmax_t count()const{ return stat.count(); } + T variance()const{ return stat.variance(); } + T variance1()const{ return stat.variance1(); } + T rms()const{ return stat.rms(); } + + test_result& operator+=(const test_result& t) + { + if((t.stat.max)() > (stat.max)()) + worst_case = t.worst_case; + stat += t.stat; + return *this; + } +}; + +template <class T> +struct calculate_result_type +{ + typedef typename T::value_type row_type; + typedef typename row_type::value_type value_type; +}; + +template <class T> +T relative_error(T a, T b) +{ + BOOST_MATH_STD_USING +#ifdef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS + // + // If math.h has no long double support we can't rely + // on the math functions generating exponents outside + // the range of a double: + // + T min_val = (std::max)( + tools::min_value<T>(), + static_cast<T>((std::numeric_limits<double>::min)())); + T max_val = (std::min)( + tools::max_value<T>(), + static_cast<T>((std::numeric_limits<double>::max)())); +#else + T min_val = tools::min_value<T>(); + T max_val = tools::max_value<T>(); +#endif + + if((a != 0) && (b != 0)) + { + // TODO: use isfinite: + if(fabs(b) >= max_val) + { + if(fabs(a) >= max_val) + return 0; // one infinity is as good as another! + } + // If the result is denormalised, treat all denorms as equivalent: + if((a < min_val) && (a > 0)) + a = min_val; + else if((a > -min_val) && (a < 0)) + a = -min_val; + if((b < min_val) && (b > 0)) + b = min_val; + else if((b > -min_val) && (b < 0)) + b = -min_val; + return (std::max)(fabs((a-b)/a), fabs((a-b)/b)); + } + + // Handle special case where one or both are zero: + if(min_val == 0) + return fabs(a-b); + if(fabs(a) < min_val) + a = min_val; + if(fabs(b) < min_val) + b = min_val; + return (std::max)(fabs((a-b)/a), fabs((a-b)/b)); +} + +#if defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__) +template <> +inline double relative_error<double>(double a, double b) +{ + BOOST_MATH_STD_USING + // + // On Mac OS X we evaluate "double" functions at "long double" precision, + // but "long double" actually has a very slightly narrower range than "double"! + // Therefore use the range of "long double" as our limits since results outside + // that range may have been truncated to 0 or INF: + // + double min_val = (std::max)((double)tools::min_value<long double>(), tools::min_value<double>()); + double max_val = (std::min)((double)tools::max_value<long double>(), tools::max_value<double>()); + + if((a != 0) && (b != 0)) + { + // TODO: use isfinite: + if(b > max_val) + { + if(a > max_val) + return 0; // one infinity is as good as another! + } + // If the result is denormalised, treat all denorms as equivalent: + if((a < min_val) && (a > 0)) + a = min_val; + else if((a > -min_val) && (a < 0)) + a = -min_val; + if((b < min_val) && (b > 0)) + b = min_val; + else if((b > -min_val) && (b < 0)) + b = -min_val; + return (std::max)(fabs((a-b)/a), fabs((a-b)/b)); + } + + // Handle special case where one or both are zero: + if(min_val == 0) + return fabs(a-b); + if(fabs(a) < min_val) + a = min_val; + if(fabs(b) < min_val) + b = min_val; + return (std::max)(fabs((a-b)/a), fabs((a-b)/b)); +} +#endif + +template <class T> +void set_output_precision(T) +{ + if(std::numeric_limits<T>::digits10) + { + std::cout << std::setprecision(std::numeric_limits<T>::digits10 + 2); + } +} + +template <class Seq> +void print_row(const Seq& row) +{ + set_output_precision(row[0]); + for(unsigned i = 0; i < row.size(); ++i) + { + if(i) + std::cout << ", "; + std::cout << row[i]; + } + std::cout << std::endl; +} + +// +// Function test accepts an matrix of input values (probably a 2D boost::array) +// and calls two functors for each row in the array - one calculates a value +// to test, and one extracts the expected value from the array (or possibly +// calculates it at high precision). The two functors are usually simple lambda +// expressions. +// +template <class A, class F1, class F2> +test_result<typename calculate_result_type<A>::value_type> test(const A& a, F1 test_func, F2 expect_func) +{ + typedef typename A::value_type row_type; + typedef typename row_type::value_type value_type; + + test_result<value_type> result; + + for(unsigned i = 0; i < a.size(); ++i) + { + const row_type& row = a[i]; + value_type point; + try + { + point = test_func(row); + } + catch(const std::underflow_error&) + { + point = 0; + } + catch(const std::overflow_error&) + { + point = std::numeric_limits<value_type>::has_infinity ? + std::numeric_limits<value_type>::infinity() + : tools::max_value<value_type>(); + } + catch(const std::exception& e) + { + std::cerr << e.what() << std::endl; + print_row(row); + BOOST_ERROR("Unexpected exception."); + // so we don't get further errors: + point = expect_func(row); + } + value_type expected = expect_func(row); + value_type err = relative_error(point, expected); +#ifdef BOOST_INSTRUMENT + if(err != 0) + { + std::cout << row[0] << " " << err; + if(std::numeric_limits<value_type>::is_specialized) + { + std::cout << " (" << err / std::numeric_limits<value_type>::epsilon() << "eps)"; + } + std::cout << std::endl; + } +#endif + if(!(boost::math::isfinite)(point) && (boost::math::isfinite)(expected)) + { + std::cout << "CAUTION: Found non-finite result, when a finite value was expected at entry " << i << "\n"; + std::cout << "Found: " << point << " Expected " << expected << " Error: " << err << std::endl; + print_row(row); + BOOST_ERROR("Unexpected non-finite result"); + } + if(err > 0.5) + { + std::cout << "CAUTION: Gross error found at entry " << i << ".\n"; + std::cout << "Found: " << point << " Expected " << expected << " Error: " << err << std::endl; + print_row(row); + BOOST_ERROR("Gross error"); + } + result.add(err); + if((result.max)() == err) + result.set_worst(i); + } + return result; +} + +} // namespace tools +} // namespace math +} // namespace boost + +#endif + + diff --git a/Utilities/BGL/boost/math/tools/test_data.hpp b/Utilities/BGL/boost/math/tools/test_data.hpp new file mode 100644 index 0000000000000000000000000000000000000000..9d1dd4106bd43d409a0403f31898f5813e95dcc5 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/test_data.hpp @@ -0,0 +1,767 @@ +// (C) Copyright John Maddock 2006. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_TOOLS_TEST_DATA_HPP +#define BOOST_MATH_TOOLS_TEST_DATA_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/math/tools/config.hpp> +#include <boost/assert.hpp> +#ifdef BOOST_MSVC +# pragma warning(push) +# pragma warning(disable: 4127 4701 4512) +# pragma warning(disable: 4130) // '==' : logical operation on address of string constant. +#endif +#include <boost/algorithm/string/trim.hpp> +#include <boost/lexical_cast.hpp> +#ifdef BOOST_MSVC +#pragma warning(pop) +#endif +#include <boost/type_traits/is_floating_point.hpp> +#include <boost/type_traits/is_convertible.hpp> +#include <boost/type_traits/integral_constant.hpp> +#include <boost/tr1/random.hpp> +#include <boost/tr1/tuple.hpp> +#include <boost/math/tools/real_cast.hpp> + +#include <set> +#include <vector> +#include <iostream> + +#ifdef BOOST_MSVC +# pragma warning(push) +# pragma warning(disable: 4130) // '==' : logical operation on address of string constant. +// Used as a warning with BOOST_ASSERT +#endif + +namespace boost{ namespace math{ namespace tools{ + +enum parameter_type +{ + random_in_range = 0, + periodic_in_range = 1, + power_series = 2, + dummy_param = 0x80 +}; + +parameter_type operator | (parameter_type a, parameter_type b) +{ + return static_cast<parameter_type>((int)a|(int)b); +} +parameter_type& operator |= (parameter_type& a, parameter_type b) +{ + a = static_cast<parameter_type>(a|b); + return a; +} + +// +// If type == random_in_range then +// z1 and r2 are the endpoints of the half open range and n1 is the number of points. +// +// If type == periodic_in_range then +// z1 and r2 are the endpoints of the half open range and n1 is the number of points. +// +// If type == power_series then +// n1 and n2 are the endpoints of the exponents (closed range) and z1 is the basis. +// +// If type & dummy_param then this data is ignored and not stored in the output, it +// is passed to the generator function however which can do with it as it sees fit. +// +template <class T> +struct parameter_info +{ + parameter_type type; + T z1, z2; + int n1, n2; +}; + +template <class T> +inline parameter_info<T> make_random_param(T start_range, T end_range, int n_points) +{ + parameter_info<T> result = { random_in_range, start_range, end_range, n_points, 0 }; + return result; +} + +template <class T> +inline parameter_info<T> make_periodic_param(T start_range, T end_range, int n_points) +{ + parameter_info<T> result = { periodic_in_range, start_range, end_range, n_points, 0 }; + return result; +} + +template <class T> +inline parameter_info<T> make_power_param(T basis, int start_exponent, int end_exponent) +{ + parameter_info<T> result = { power_series, basis, 0, start_exponent, end_exponent }; + return result; +} + +namespace detail{ + +template <class Seq, class Item, int N> +inline void unpack_and_append_tuple(Seq& s, + const Item& data, + const boost::integral_constant<int, N>&, + const boost::false_type&) +{ + // termimation condition nothing to do here +} + +template <class Seq, class Item, int N> +inline void unpack_and_append_tuple(Seq& s, + const Item& data, + const boost::integral_constant<int, N>&, + const boost::true_type&) +{ + // extract the N'th element, append, and recurse: + typedef typename Seq::value_type value_type; + value_type val = std::tr1::get<N>(data); + s.push_back(val); + + typedef boost::integral_constant<int, N+1> next_value; + typedef boost::integral_constant<bool, (std::tr1::tuple_size<Item>::value > N+1)> terminate; + + unpack_and_append_tuple(s, data, next_value(), terminate()); +} + +template <class Seq, class Item> +inline void unpack_and_append(Seq& s, const Item& data, const boost::true_type&) +{ + s.push_back(data); +} + +template <class Seq, class Item> +inline void unpack_and_append(Seq& s, const Item& data, const boost::false_type&) +{ + // Item had better be a tuple-like type or we've had it!!!! + typedef boost::integral_constant<int, 0> next_value; + typedef boost::integral_constant<bool, (std::tr1::tuple_size<Item>::value > 0)> terminate; + + unpack_and_append_tuple(s, data, next_value(), terminate()); +} + +template <class Seq, class Item> +inline void unpack_and_append(Seq& s, const Item& data) +{ + typedef typename Seq::value_type value_type; + unpack_and_append(s, data, ::boost::is_convertible<Item, value_type>()); +} + +} // detail + +template <class T> +class test_data +{ +public: + typedef std::vector<T> row_type; + typedef row_type value_type; +private: + typedef std::set<row_type> container_type; +public: + typedef typename container_type::reference reference; + typedef typename container_type::const_reference const_reference; + typedef typename container_type::iterator iterator; + typedef typename container_type::const_iterator const_iterator; + typedef typename container_type::difference_type difference_type; + typedef typename container_type::size_type size_type; + + // creation: + test_data(){} + template <class F> + test_data(F func, const parameter_info<T>& arg1) + { + insert(func, arg1); + } + + // insertion: + template <class F> + test_data& insert(F func, const parameter_info<T>& arg1) + { + // generate data for single argument functor F + + typedef typename std::set<T>::const_iterator it_type; + + std::set<T> points; + create_test_points(points, arg1); + it_type a = points.begin(); + it_type b = points.end(); + row_type row; + while(a != b) + { + if((arg1.type & dummy_param) == 0) + row.push_back(*a); + try{ + // domain_error exceptions from func are swallowed + // and this data point is ignored: + boost::math::tools::detail::unpack_and_append(row, func(*a)); + m_data.insert(row); + } + catch(const std::domain_error&){} + row.clear(); + ++a; + } + return *this; + } + + template <class F> + test_data& insert(F func, const parameter_info<T>& arg1, const parameter_info<T>& arg2) + { + // generate data for 2-argument functor F + + typedef typename std::set<T>::const_iterator it_type; + + std::set<T> points1, points2; + create_test_points(points1, arg1); + create_test_points(points2, arg2); + it_type a = points1.begin(); + it_type b = points1.end(); + row_type row; + while(a != b) + { + it_type c = points2.begin(); + it_type d = points2.end(); + while(c != d) + { + if((arg1.type & dummy_param) == 0) + row.push_back(*a); + if((arg2.type & dummy_param) == 0) + row.push_back(*c); + try{ + // domain_error exceptions from func are swallowed + // and this data point is ignored: + detail::unpack_and_append(row, func(*a, *c)); + m_data.insert(row); + } + catch(const std::domain_error&){} + row.clear(); + ++c; + } + ++a; + } + return *this; + } + + template <class F> + test_data& insert(F func, const parameter_info<T>& arg1, const parameter_info<T>& arg2, const parameter_info<T>& arg3) + { + // generate data for 3-argument functor F + + typedef typename std::set<T>::const_iterator it_type; + + std::set<T> points1, points2, points3; + create_test_points(points1, arg1); + create_test_points(points2, arg2); + create_test_points(points3, arg3); + it_type a = points1.begin(); + it_type b = points1.end(); + row_type row; + while(a != b) + { + it_type c = points2.begin(); + it_type d = points2.end(); + while(c != d) + { + it_type e = points3.begin(); + it_type f = points3.end(); + while(e != f) + { + if((arg1.type & dummy_param) == 0) + row.push_back(*a); + if((arg2.type & dummy_param) == 0) + row.push_back(*c); + if((arg3.type & dummy_param) == 0) + row.push_back(*e); + try{ + // domain_error exceptions from func are swallowed + // and this data point is ignored: + detail::unpack_and_append(row, func(*a, *c, *e)); + m_data.insert(row); + } + catch(const std::domain_error&){} + row.clear(); + ++e; + } + ++c; + } + ++a; + } + return *this; + } + + void clear(){ m_data.clear(); } + + // access: + iterator begin() { return m_data.begin(); } + iterator end() { return m_data.end(); } + const_iterator begin()const { return m_data.begin(); } + const_iterator end()const { return m_data.end(); } + bool operator==(const test_data& d)const{ return m_data == d.m_data; } + bool operator!=(const test_data& d)const{ return m_data != d.m_data; } + void swap(test_data& other){ m_data.swap(other.m_data); } + size_type size()const{ return m_data.size(); } + size_type max_size()const{ return m_data.max_size(); } + bool empty()const{ return m_data.empty(); } + + bool operator < (const test_data& dat)const{ return m_data < dat.m_data; } + bool operator <= (const test_data& dat)const{ return m_data <= dat.m_data; } + bool operator > (const test_data& dat)const{ return m_data > dat.m_data; } + bool operator >= (const test_data& dat)const{ return m_data >= dat.m_data; } + +private: + void create_test_points(std::set<T>& points, const parameter_info<T>& arg1); + std::set<row_type> m_data; + + static float extern_val; + static float truncate_to_float(float const * pf); + static float truncate_to_float(float c){ return truncate_to_float(&c); } +}; + +// +// This code exists to bemuse the compiler's optimizer and force a +// truncation to float-precision only: +// +template <class T> +inline float test_data<T>::truncate_to_float(float const * pf) +{ + BOOST_MATH_STD_USING + int expon; + float f = floor(ldexp(frexp(*pf, &expon), 22)); + f = ldexp(f, expon - 22); + return f; + + //extern_val = *pf; + //return *pf; +} + +template <class T> +float test_data<T>::extern_val = 0; + +template <class T> +void test_data<T>::create_test_points(std::set<T>& points, const parameter_info<T>& arg1) +{ + BOOST_MATH_STD_USING + // + // Generate a set of test points as requested, try and generate points + // at only float precision: otherwise when testing float versions of functions + // there will be a rounding error in our input values which throws off the results + // (Garbage in garbage out etc). + // + switch(arg1.type & 0x7F) + { + case random_in_range: + { + BOOST_ASSERT(arg1.z1 < arg1.z2); + BOOST_ASSERT(arg1.n1 > 0); + typedef float random_type; + + std::tr1::mt19937 rnd; + std::tr1::uniform_real<random_type> ur_a(real_cast<random_type>(arg1.z1), real_cast<random_type>(arg1.z2)); + std::tr1::variate_generator<std::tr1::mt19937, std::tr1::uniform_real<random_type> > gen(rnd, ur_a); + + for(int i = 0; i < arg1.n1; ++i) + { + random_type r = gen(); + points.insert(truncate_to_float(r)); + } + } + break; + case periodic_in_range: + { + BOOST_ASSERT(arg1.z1 < arg1.z2); + BOOST_ASSERT(arg1.n1 > 0); + float interval = real_cast<float>((arg1.z2 - arg1.z1) / arg1.n1); + T val = arg1.z1; + while(val < arg1.z2) + { + points.insert(truncate_to_float(real_cast<float>(val))); + val += interval; + } + } + break; + case power_series: + { + BOOST_ASSERT(arg1.n1 < arg1.n2); + + typedef float random_type; + typedef typename boost::mpl::if_< + ::boost::is_floating_point<T>, + T, long double>::type power_type; + + std::tr1::mt19937 rnd; + std::tr1::uniform_real<random_type> ur_a(1.0, 2.0); + std::tr1::variate_generator<std::tr1::mt19937, std::tr1::uniform_real<random_type> > gen(rnd, ur_a); + + for(int power = arg1.n1; power <= arg1.n2; ++power) + { + random_type r = gen(); + power_type p = ldexp(static_cast<power_type>(r), power); + points.insert(truncate_to_float(real_cast<float>(arg1.z1 + p))); + } + } + break; + default: + BOOST_ASSERT(0 == "Invalid parameter_info object"); + // Assert will fail if get here. + // Triggers warning 4130) // '==' : logical operation on address of string constant. + } +} + +// +// Prompt a user for information on a parameter range: +// +template <class T> +bool get_user_parameter_info(parameter_info<T>& info, const char* param_name) +{ +#ifdef BOOST_MSVC +# pragma warning(push) +# pragma warning(disable: 4127) +#endif + std::string line; + do{ + std::cout << "What kind of distribution do you require for parameter " << param_name << "?\n" + "Choices are:\n" + " r Random values in a half open range\n" + " p Evenly spaced periodic values in a half open range\n" + " e Exponential power series at a particular point: a + 2^b for some range of b\n" + "[Default=r]"; + + std::getline(std::cin, line); + boost::algorithm::trim(line); + + if(line == "r") + { + info.type = random_in_range; + break; + } + else if(line == "p") + { + info.type = periodic_in_range; + break; + } + else if(line == "e") + { + info.type = power_series; + break; + } + else if(line == "") + { + info.type = random_in_range; + break; + } + // + // Ooops, not a valid input.... + // + std::cout << "Sorry don't recognise \"" << line << "\" as a valid input\n" + "do you want to try again [y/n]?"; + std::getline(std::cin, line); + boost::algorithm::trim(line); + if(line == "n") + return false; + else if(line == "y") + continue; + std::cout << "Sorry don't recognise that either, giving up...\n\n"; + return false; + }while(true); + + switch(info.type & ~dummy_param) + { + case random_in_range: + case periodic_in_range: + // get start and end points of range: + do{ + std::cout << "Data will be in the half open range a <= x < b,\n" + "enter value for the start point fo the range [default=0]:"; + std::getline(std::cin, line); + boost::algorithm::trim(line); + if(line == "") + { + info.z1 = 0; + break; + } + try{ + info.z1 = boost::lexical_cast<T>(line); + break; + } + catch(const boost::bad_lexical_cast&) + { + std::cout << "Sorry, that was not valid input, try again [y/n]?"; + std::getline(std::cin, line); + boost::algorithm::trim(line); + if(line == "y") + continue; + if(line == "n") + return false; + std::cout << "Sorry don't recognise that either, giving up...\n\n"; + return false; + } + }while(true); + do{ + std::cout << "Enter value for the end point fo the range [default=1]:"; + std::getline(std::cin, line); + boost::algorithm::trim(line); + if(line == "") + { + info.z2 = 1; + } + else + { + try + { + info.z2 = boost::lexical_cast<T>(line); + } + catch(const boost::bad_lexical_cast&) + { + std::cout << "Sorry, that was not valid input, try again [y/n]?"; + std::getline(std::cin, line); + boost::algorithm::trim(line); + if(line == "y") + continue; + if(line == "n") + return false; + std::cout << "Sorry don't recognise that either, giving up...\n\n"; + return false; + } + } + if(info.z1 >= info.z2) + { + std::cout << "The end point of the range was <= the start point\n" + "try a different value for the endpoint [y/n]?"; + std::getline(std::cin, line); + boost::algorithm::trim(line); + if(line == "y") + continue; + if(line == "n") + return false; + std::cout << "Sorry don't recognise that either, giving up...\n\n"; + return false; + } + break; + }while(true); + do{ + // get the number of points: + std::cout << "How many data points do you want?"; + std::getline(std::cin, line); + boost::algorithm::trim(line); + try{ + info.n1 = boost::lexical_cast<int>(line); + info.n2 = 0; + if(info.n1 <= 0) + { + std::cout << "The number of points should be > 0\n" + "try again [y/n]?"; + std::getline(std::cin, line); + boost::algorithm::trim(line); + if(line == "y") + continue; + if(line == "n") + return false; + std::cout << "Sorry don't recognise that either, giving up...\n\n"; + return false; + } + break; + } + catch(const boost::bad_lexical_cast&) + { + std::cout << "Sorry, that was not valid input, try again [y/n]?"; + std::getline(std::cin, line); + boost::algorithm::trim(line); + if(line == "y") + continue; + if(line == "n") + return false; + std::cout << "Sorry don't recognise that either, giving up...\n\n"; + return false; + } + }while(true); + break; + case power_series: + // get start and end points of range: + info.z2 = 0; + do{ + std::cout << "Data will be in the form a + r*2^b\n" + "for random value r,\n" + "enter value for the point a [default=0]:"; + std::getline(std::cin, line); + boost::algorithm::trim(line); + if(line == "") + { + info.z1 = 0; + break; + } + try{ + info.z1 = boost::lexical_cast<T>(line); + break; + } + catch(const boost::bad_lexical_cast&) + { + std::cout << "Sorry, that was not valid input, try again [y/n]?"; + std::getline(std::cin, line); + boost::algorithm::trim(line); + if(line == "y") + continue; + if(line == "n") + return false; + std::cout << "Sorry don't recognise that either, giving up...\n\n"; + return false; + } + }while(true); + + do{ + std::cout << "Data will be in the form a + r*2^b\n" + "for random value r,\n" + "enter value for the starting exponent b:"; + std::getline(std::cin, line); + boost::algorithm::trim(line); + try{ + info.n1 = boost::lexical_cast<int>(line); + break; + } + catch(const boost::bad_lexical_cast&) + { + std::cout << "Sorry, that was not valid input, try again [y/n]?"; + std::getline(std::cin, line); + boost::algorithm::trim(line); + if(line == "y") + continue; + if(line == "n") + return false; + std::cout << "Sorry don't recognise that either, giving up...\n\n"; + return false; + } + }while(true); + + do{ + std::cout << "Data will be in the form a + r*2^b\n" + "for random value r,\n" + "enter value for the ending exponent b:"; + std::getline(std::cin, line); + boost::algorithm::trim(line); + try{ + info.n2 = boost::lexical_cast<int>(line); + break; + } + catch(const boost::bad_lexical_cast&) + { + std::cout << "Sorry, that was not valid input, try again [y/n]?"; + std::getline(std::cin, line); + boost::algorithm::trim(line); + if(line == "y") + continue; + if(line == "n") + return false; + std::cout << "Sorry don't recognise that either, giving up...\n\n"; + return false; + } + }while(true); + + break; + default: + BOOST_ASSERT(0); // should never get here!! + } + + return true; +#ifdef BOOST_MSVC +# pragma warning(pop) +#endif +} + +template <class charT, class traits, class T> +inline std::basic_ostream<charT, traits>& write_csv(std::basic_ostream<charT, traits>& os, + const test_data<T>& data) +{ + const charT defarg[] = { ',', ' ', '\0' }; + return write_csv(os, data, defarg); +} + +template <class charT, class traits, class T> +std::basic_ostream<charT, traits>& write_csv(std::basic_ostream<charT, traits>& os, + const test_data<T>& data, + const charT* separator) +{ + typedef typename test_data<T>::const_iterator it_type; + typedef typename test_data<T>::value_type value_type; + typedef typename value_type::const_iterator value_type_iterator; + it_type a, b; + a = data.begin(); + b = data.end(); + while(a != b) + { + value_type_iterator x, y; + bool sep = false; + x = a->begin(); + y = a->end(); + while(x != y) + { + if(sep) + os << separator; + os << *x; + sep = true; + ++x; + } + os << std::endl; + ++a; + } + return os; +} + +template <class T> +std::ostream& write_code(std::ostream& os, + const test_data<T>& data, + const char* name) +{ + typedef typename test_data<T>::const_iterator it_type; + typedef typename test_data<T>::value_type value_type; + typedef typename value_type::const_iterator value_type_iterator; + + BOOST_ASSERT(os.good()); + + it_type a, b; + a = data.begin(); + b = data.end(); + if(a == b) + return os; + + os << "#define SC_(x) static_cast<T>(BOOST_JOIN(x, L))\n" + " static const boost::array<boost::array<T, " + << a->size() << ">, " << data.size() << "> " << name << " = {{\n"; + + while(a != b) + { + if(a != data.begin()) + os << ", \n"; + + value_type_iterator x, y; + x = a->begin(); + y = a->end(); + os << " { "; + while(x != y) + { + if(x != a->begin()) + os << ", "; + os << "SC_(" << *x << ")"; + ++x; + } + os << " }"; + ++a; + } + os << "\n }};\n#undef SC_\n\n"; + return os; +} + +} // namespace tools +} // namespace math +} // namespace boost + +#ifdef BOOST_MSVC +#pragma warning(pop) +#endif + + +#endif // BOOST_MATH_TOOLS_TEST_DATA_HPP + + diff --git a/Utilities/BGL/boost/math/tools/toms748_solve.hpp b/Utilities/BGL/boost/math/tools/toms748_solve.hpp new file mode 100644 index 0000000000000000000000000000000000000000..8459ef66a7f7ec70bbd60a1727939e6b4e37e32b --- /dev/null +++ b/Utilities/BGL/boost/math/tools/toms748_solve.hpp @@ -0,0 +1,584 @@ +// (C) Copyright John Maddock 2006. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_TOOLS_SOLVE_ROOT_HPP +#define BOOST_MATH_TOOLS_SOLVE_ROOT_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/math/tools/precision.hpp> +#include <boost/math/policies/error_handling.hpp> +#include <boost/math/tools/config.hpp> +#include <boost/math/special_functions/sign.hpp> +#include <boost/cstdint.hpp> +#include <limits> + +namespace boost{ namespace math{ namespace tools{ + +template <class T> +class eps_tolerance +{ +public: + eps_tolerance(unsigned bits) + { + BOOST_MATH_STD_USING + eps = (std::max)(T(ldexp(1.0F, 1-bits)), T(2 * tools::epsilon<T>())); + } + bool operator()(const T& a, const T& b) + { + BOOST_MATH_STD_USING + return (fabs(a - b) / (std::min)(fabs(a), fabs(b))) <= eps; + } +private: + T eps; +}; + +struct equal_floor +{ + equal_floor(){} + template <class T> + bool operator()(const T& a, const T& b) + { + BOOST_MATH_STD_USING + return floor(a) == floor(b); + } +}; + +struct equal_ceil +{ + equal_ceil(){} + template <class T> + bool operator()(const T& a, const T& b) + { + BOOST_MATH_STD_USING + return ceil(a) == ceil(b); + } +}; + +struct equal_nearest_integer +{ + equal_nearest_integer(){} + template <class T> + bool operator()(const T& a, const T& b) + { + BOOST_MATH_STD_USING + return floor(a + 0.5f) == floor(b + 0.5f); + } +}; + +namespace detail{ + +template <class F, class T> +void bracket(F f, T& a, T& b, T c, T& fa, T& fb, T& d, T& fd) +{ + // + // Given a point c inside the existing enclosing interval + // [a, b] sets a = c if f(c) == 0, otherwise finds the new + // enclosing interval: either [a, c] or [c, b] and sets + // d and fd to the point that has just been removed from + // the interval. In other words d is the third best guess + // to the root. + // + BOOST_MATH_STD_USING // For ADL of std math functions + T tol = tools::epsilon<T>() * 2; + // + // If the interval [a,b] is very small, or if c is too close + // to one end of the interval then we need to adjust the + // location of c accordingly: + // + if((b - a) < 2 * tol * a) + { + c = a + (b - a) / 2; + } + else if(c <= a + fabs(a) * tol) + { + c = a + fabs(a) * tol; + } + else if(c >= b - fabs(b) * tol) + { + c = b - fabs(a) * tol; + } + // + // OK, lets invoke f(c): + // + T fc = f(c); + // + // if we have a zero then we have an exact solution to the root: + // + if(fc == 0) + { + a = c; + fa = 0; + d = 0; + fd = 0; + return; + } + // + // Non-zero fc, update the interval: + // + if(boost::math::sign(fa) * boost::math::sign(fc) < 0) + { + d = b; + fd = fb; + b = c; + fb = fc; + } + else + { + d = a; + fd = fa; + a = c; + fa= fc; + } +} + +template <class T> +inline T safe_div(T num, T denom, T r) +{ + // + // return num / denom without overflow, + // return r if overflow would occur. + // + BOOST_MATH_STD_USING // For ADL of std math functions + + if(fabs(denom) < 1) + { + if(fabs(denom * tools::max_value<T>()) <= fabs(num)) + return r; + } + return num / denom; +} + +template <class T> +inline T secant_interpolate(const T& a, const T& b, const T& fa, const T& fb) +{ + // + // Performs standard secant interpolation of [a,b] given + // function evaluations f(a) and f(b). Performs a bisection + // if secant interpolation would leave us very close to either + // a or b. Rationale: we only call this function when at least + // one other form of interpolation has already failed, so we know + // that the function is unlikely to be smooth with a root very + // close to a or b. + // + BOOST_MATH_STD_USING // For ADL of std math functions + + T tol = tools::epsilon<T>() * 5; + T c = a - (fa / (fb - fa)) * (b - a); + if((c <= a + fabs(a) * tol) || (c >= b - fabs(b) * tol)) + return (a + b) / 2; + return c; +} + +template <class T> +T quadratic_interpolate(const T& a, const T& b, T const& d, + const T& fa, const T& fb, T const& fd, + unsigned count) +{ + // + // Performs quadratic interpolation to determine the next point, + // takes count Newton steps to find the location of the + // quadratic polynomial. + // + // Point d must lie outside of the interval [a,b], it is the third + // best approximation to the root, after a and b. + // + // Note: this does not guarentee to find a root + // inside [a, b], so we fall back to a secant step should + // the result be out of range. + // + // Start by obtaining the coefficients of the quadratic polynomial: + // + T B = safe_div(T(fb - fa), T(b - a), tools::max_value<T>()); + T A = safe_div(T(fd - fb), T(d - b), tools::max_value<T>()); + A = safe_div(T(A - B), T(d - a), T(0)); + + if(a == 0) + { + // failure to determine coefficients, try a secant step: + return secant_interpolate(a, b, fa, fb); + } + // + // Determine the starting point of the Newton steps: + // + T c; + if(boost::math::sign(A) * boost::math::sign(fa) > 0) + { + c = a; + } + else + { + c = b; + } + // + // Take the Newton steps: + // + for(unsigned i = 1; i <= count; ++i) + { + //c -= safe_div(B * c, (B + A * (2 * c - a - b)), 1 + c - a); + c -= safe_div(T(fa+(B+A*(c-b))*(c-a)), T(B + A * (2 * c - a - b)), T(1 + c - a)); + } + if((c <= a) || (c >= b)) + { + // Oops, failure, try a secant step: + c = secant_interpolate(a, b, fa, fb); + } + return c; +} + +template <class T> +T cubic_interpolate(const T& a, const T& b, const T& d, + const T& e, const T& fa, const T& fb, + const T& fd, const T& fe) +{ + // + // Uses inverse cubic interpolation of f(x) at points + // [a,b,d,e] to obtain an approximate root of f(x). + // Points d and e lie outside the interval [a,b] + // and are the third and forth best approximations + // to the root that we have found so far. + // + // Note: this does not guarentee to find a root + // inside [a, b], so we fall back to quadratic + // interpolation in case of an erroneous result. + // + BOOST_MATH_INSTRUMENT_CODE(" a = " << a << " b = " << b + << " d = " << d << " e = " << e << " fa = " << fa << " fb = " << fb + << " fd = " << fd << " fe = " << fe); + T q11 = (d - e) * fd / (fe - fd); + T q21 = (b - d) * fb / (fd - fb); + T q31 = (a - b) * fa / (fb - fa); + T d21 = (b - d) * fd / (fd - fb); + T d31 = (a - b) * fb / (fb - fa); + BOOST_MATH_INSTRUMENT_CODE( + "q11 = " << q11 << " q21 = " << q21 << " q31 = " << q31 + << " d21 = " << d21 << " d31 = " << d31); + T q22 = (d21 - q11) * fb / (fe - fb); + T q32 = (d31 - q21) * fa / (fd - fa); + T d32 = (d31 - q21) * fd / (fd - fa); + T q33 = (d32 - q22) * fa / (fe - fa); + T c = q31 + q32 + q33 + a; + BOOST_MATH_INSTRUMENT_CODE( + "q22 = " << q22 << " q32 = " << q32 << " d32 = " << d32 + << " q33 = " << q33 << " c = " << c); + + if((c <= a) || (c >= b)) + { + // Out of bounds step, fall back to quadratic interpolation: + c = quadratic_interpolate(a, b, d, fa, fb, fd, 3); + BOOST_MATH_INSTRUMENT_CODE( + "Out of bounds interpolation, falling back to quadratic interpolation. c = " << c); + } + + return c; +} + +} // namespace detail + +template <class F, class T, class Tol, class Policy> +std::pair<T, T> toms748_solve(F f, const T& ax, const T& bx, const T& fax, const T& fbx, Tol tol, boost::uintmax_t& max_iter, const Policy& pol) +{ + // + // Main entry point and logic for Toms Algorithm 748 + // root finder. + // + BOOST_MATH_STD_USING // For ADL of std math functions + + static const char* function = "boost::math::tools::toms748_solve<%1%>"; + + boost::uintmax_t count = max_iter; + T a, b, fa, fb, c, u, fu, a0, b0, d, fd, e, fe; + static const T mu = 0.5f; + + // initialise a, b and fa, fb: + a = ax; + b = bx; + if(a >= b) + policies::raise_domain_error( + function, + "Parameters a and b out of order: a=%1%", a, pol); + fa = fax; + fb = fbx; + + if(tol(a, b) || (fa == 0) || (fb == 0)) + { + max_iter = 0; + if(fa == 0) + b = a; + else if(fb == 0) + a = b; + return std::make_pair(a, b); + } + + if(boost::math::sign(fa) * boost::math::sign(fb) > 0) + policies::raise_domain_error( + function, + "Parameters a and b do not bracket the root: a=%1%", a, pol); + // dummy value for fd, e and fe: + fe = e = fd = 1e5F; + + if(fa != 0) + { + // + // On the first step we take a secant step: + // + c = detail::secant_interpolate(a, b, fa, fb); + detail::bracket(f, a, b, c, fa, fb, d, fd); + --count; + BOOST_MATH_INSTRUMENT_CODE(" a = " << a << " b = " << b); + + if(count && (fa != 0) && !tol(a, b)) + { + // + // On the second step we take a quadratic interpolation: + // + c = detail::quadratic_interpolate(a, b, d, fa, fb, fd, 2); + e = d; + fe = fd; + detail::bracket(f, a, b, c, fa, fb, d, fd); + --count; + BOOST_MATH_INSTRUMENT_CODE(" a = " << a << " b = " << b); + } + } + + while(count && (fa != 0) && !tol(a, b)) + { + // save our brackets: + a0 = a; + b0 = b; + // + // Starting with the third step taken + // we can use either quadratic or cubic interpolation. + // Cubic interpolation requires that all four function values + // fa, fb, fd, and fe are distinct, should that not be the case + // then variable prof will get set to true, and we'll end up + // taking a quadratic step instead. + // + T min_diff = tools::min_value<T>() * 32; + bool prof = (fabs(fa - fb) < min_diff) || (fabs(fa - fd) < min_diff) || (fabs(fa - fe) < min_diff) || (fabs(fb - fd) < min_diff) || (fabs(fb - fe) < min_diff) || (fabs(fd - fe) < min_diff); + if(prof) + { + c = detail::quadratic_interpolate(a, b, d, fa, fb, fd, 2); + BOOST_MATH_INSTRUMENT_CODE("Can't take cubic step!!!!"); + } + else + { + c = detail::cubic_interpolate(a, b, d, e, fa, fb, fd, fe); + } + // + // re-bracket, and check for termination: + // + e = d; + fe = fd; + detail::bracket(f, a, b, c, fa, fb, d, fd); + if((0 == --count) || (fa == 0) || tol(a, b)) + break; + BOOST_MATH_INSTRUMENT_CODE(" a = " << a << " b = " << b); + // + // Now another interpolated step: + // + prof = (fabs(fa - fb) < min_diff) || (fabs(fa - fd) < min_diff) || (fabs(fa - fe) < min_diff) || (fabs(fb - fd) < min_diff) || (fabs(fb - fe) < min_diff) || (fabs(fd - fe) < min_diff); + if(prof) + { + c = detail::quadratic_interpolate(a, b, d, fa, fb, fd, 3); + BOOST_MATH_INSTRUMENT_CODE("Can't take cubic step!!!!"); + } + else + { + c = detail::cubic_interpolate(a, b, d, e, fa, fb, fd, fe); + } + // + // Bracket again, and check termination condition, update e: + // + detail::bracket(f, a, b, c, fa, fb, d, fd); + if((0 == --count) || (fa == 0) || tol(a, b)) + break; + BOOST_MATH_INSTRUMENT_CODE(" a = " << a << " b = " << b); + // + // Now we take a double-length secant step: + // + if(fabs(fa) < fabs(fb)) + { + u = a; + fu = fa; + } + else + { + u = b; + fu = fb; + } + c = u - 2 * (fu / (fb - fa)) * (b - a); + if(fabs(c - u) > (b - a) / 2) + { + c = a + (b - a) / 2; + } + // + // Bracket again, and check termination condition: + // + e = d; + fe = fd; + detail::bracket(f, a, b, c, fa, fb, d, fd); + if((0 == --count) || (fa == 0) || tol(a, b)) + break; + BOOST_MATH_INSTRUMENT_CODE(" a = " << a << " b = " << b); + // + // And finally... check to see if an additional bisection step is + // to be taken, we do this if we're not converging fast enough: + // + if((b - a) < mu * (b0 - a0)) + continue; + // + // bracket again on a bisection: + // + e = d; + fe = fd; + detail::bracket(f, a, b, T(a + (b - a) / 2), fa, fb, d, fd); + --count; + BOOST_MATH_INSTRUMENT_CODE("Not converging: Taking a bisection!!!!"); + BOOST_MATH_INSTRUMENT_CODE(" a = " << a << " b = " << b); + } // while loop + + max_iter -= count; + if(fa == 0) + { + b = a; + } + else if(fb == 0) + { + a = b; + } + return std::make_pair(a, b); +} + +template <class F, class T, class Tol> +inline std::pair<T, T> toms748_solve(F f, const T& ax, const T& bx, const T& fax, const T& fbx, Tol tol, boost::uintmax_t& max_iter) +{ + return toms748_solve(f, ax, bx, fax, fbx, tol, max_iter, policies::policy<>()); +} + +template <class F, class T, class Tol, class Policy> +inline std::pair<T, T> toms748_solve(F f, const T& ax, const T& bx, Tol tol, boost::uintmax_t& max_iter, const Policy& pol) +{ + max_iter -= 2; + std::pair<T, T> r = toms748_solve(f, ax, bx, f(ax), f(bx), tol, max_iter, pol); + max_iter += 2; + return r; +} + +template <class F, class T, class Tol> +inline std::pair<T, T> toms748_solve(F f, const T& ax, const T& bx, Tol tol, boost::uintmax_t& max_iter) +{ + return toms748_solve(f, ax, bx, tol, max_iter, policies::policy<>()); +} + +template <class F, class T, class Tol, class Policy> +std::pair<T, T> bracket_and_solve_root(F f, const T& guess, T factor, bool rising, Tol tol, boost::uintmax_t& max_iter, const Policy& pol) +{ + BOOST_MATH_STD_USING + static const char* function = "boost::math::tools::bracket_and_solve_root<%1%>"; + // + // Set up inital brackets: + // + T a = guess; + T b = a; + T fa = f(a); + T fb = fa; + // + // Set up invocation count: + // + boost::uintmax_t count = max_iter - 1; + + if((fa < 0) == (guess < 0 ? !rising : rising)) + { + // + // Zero is to the right of b, so walk upwards + // until we find it: + // + while((boost::math::sign)(fb) == (boost::math::sign)(fa)) + { + if(count == 0) + policies::raise_evaluation_error(function, "Unable to bracket root, last nearest value was %1%", b, pol); + // + // Heuristic: every 20 iterations we double the growth factor in case the + // initial guess was *really* bad ! + // + if((max_iter - count) % 20 == 0) + factor *= 2; + // + // Now go ahead and move our guess by "factor": + // + a = b; + fa = fb; + b *= factor; + fb = f(b); + --count; + BOOST_MATH_INSTRUMENT_CODE("a = " << a << " b = " << b << " fa = " << fa << " fb = " << fb << " count = " << count); + } + } + else + { + // + // Zero is to the left of a, so walk downwards + // until we find it: + // + while((boost::math::sign)(fb) == (boost::math::sign)(fa)) + { + if(fabs(a) < tools::min_value<T>()) + { + // Escape route just in case the answer is zero! + max_iter -= count; + max_iter += 1; + return a > 0 ? std::make_pair(T(0), T(a)) : std::make_pair(T(a), T(0)); + } + if(count == 0) + policies::raise_evaluation_error(function, "Unable to bracket root, last nearest value was %1%", a, pol); + // + // Heuristic: every 20 iterations we double the growth factor in case the + // initial guess was *really* bad ! + // + if((max_iter - count) % 20 == 0) + factor *= 2; + // + // Now go ahead and move are guess by "factor": + // + b = a; + fb = fa; + a /= factor; + fa = f(a); + --count; + BOOST_MATH_INSTRUMENT_CODE("a = " << a << " b = " << b << " fa = " << fa << " fb = " << fb << " count = " << count); + } + } + max_iter -= count; + max_iter += 1; + std::pair<T, T> r = toms748_solve( + f, + (a < 0 ? b : a), + (a < 0 ? a : b), + (a < 0 ? fb : fa), + (a < 0 ? fa : fb), + tol, + count, + pol); + max_iter += count; + BOOST_MATH_INSTRUMENT_CODE("max_iter = " << max_iter << " count = " << count); + return r; +} + +template <class F, class T, class Tol> +inline std::pair<T, T> bracket_and_solve_root(F f, const T& guess, const T& factor, bool rising, Tol tol, boost::uintmax_t& max_iter) +{ + return bracket_and_solve_root(f, guess, factor, rising, tol, max_iter, policies::policy<>()); +} + +} // namespace tools +} // namespace math +} // namespace boost + + +#endif // BOOST_MATH_TOOLS_SOLVE_ROOT_HPP + diff --git a/Utilities/BGL/boost/math/tools/traits.hpp b/Utilities/BGL/boost/math/tools/traits.hpp new file mode 100644 index 0000000000000000000000000000000000000000..2a7e5a755a3cbcefb34d14da60229e922f2f6001 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/traits.hpp @@ -0,0 +1,111 @@ +// Copyright John Maddock 2007. + +// Use, modification and distribution are subject to 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) + +/* +This header defines two traits classes, both in namespace boost::math::tools. + +is_distribution<D>::value is true iff D has overloaded "cdf" and +"quantile" functions, plus member typedefs value_type and policy_type. +It's not much of a definitive test frankly, +but if it looks like a distribution and quacks like a distribution +then it must be a distribution. + +is_scaled_distribution<D>::value is true iff D is a distribution +as defined above, and has member functions "scale" and "location". + +*/ + +#ifndef BOOST_STATS_IS_DISTRIBUTION_HPP +#define BOOST_STATS_IS_DISTRIBUTION_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/mpl/has_xxx.hpp> +// should be the last #include +#include <boost/type_traits/detail/bool_trait_def.hpp> + +namespace boost{ namespace math{ namespace tools{ + +namespace detail{ + +BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(has_value_type, value_type, true) +BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(has_policy_type, policy_type, true) + +template<class D> +char cdf(const D& ...); +template<class D> +char quantile(const D& ...); + +template <class D> +struct has_cdf +{ + static D d; + BOOST_STATIC_CONSTANT(bool, value = sizeof(cdf(d, 0.0f)) != 1); +}; + +template <class D> +struct has_quantile +{ + static D d; + BOOST_STATIC_CONSTANT(bool, value = sizeof(quantile(d, 0.0f)) != 1); +}; + +template <class D> +struct is_distribution_imp +{ + BOOST_STATIC_CONSTANT(bool, value = + has_quantile<D>::value + && has_cdf<D>::value + && has_value_type<D>::value + && has_policy_type<D>::value); +}; + +template <class sig, sig val> +struct result_tag{}; + +template <class D> +double test_has_location(const volatile result_tag<typename D::value_type (D::*)()const, &D::location>*); +template <class D> +char test_has_location(...); + +template <class D> +double test_has_scale(const volatile result_tag<typename D::value_type (D::*)()const, &D::scale>*); +template <class D> +char test_has_scale(...); + +template <class D, bool b> +struct is_scaled_distribution_helper +{ + BOOST_STATIC_CONSTANT(bool, value = false); +}; + +template <class D> +struct is_scaled_distribution_helper<D, true> +{ + BOOST_STATIC_CONSTANT(bool, value = + (sizeof(test_has_location<D>(0)) != 1) + && + (sizeof(test_has_scale<D>(0)) != 1)); +}; + +template <class D> +struct is_scaled_distribution_imp +{ + BOOST_STATIC_CONSTANT(bool, value = (::boost::math::tools::detail::is_scaled_distribution_helper<D, ::boost::math::tools::detail::is_distribution_imp<D>::value>::value)); +}; + +} // namespace detail + +BOOST_TT_AUX_BOOL_TRAIT_DEF1(is_distribution,T,::boost::math::tools::detail::is_distribution_imp<T>::value) +BOOST_TT_AUX_BOOL_TRAIT_DEF1(is_scaled_distribution,T,::boost::math::tools::detail::is_scaled_distribution_imp<T>::value) + +}}} + +#endif + + diff --git a/Utilities/BGL/boost/math/tools/user.hpp b/Utilities/BGL/boost/math/tools/user.hpp new file mode 100644 index 0000000000000000000000000000000000000000..8f1a9a93404063ee4ef69e314223f99a6d89e2c6 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/user.hpp @@ -0,0 +1,97 @@ +// Copyright John Maddock 2007. +// Copyright Paul A. Bristow 2007. + +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_TOOLS_USER_HPP +#define BOOST_MATH_TOOLS_USER_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +// This file can be modified by the user to change the default policies. +// See "Changing the Policy Defaults" in documentation. + +// define this if the platform has no long double functions, +// or if the long double versions have only double precision: +// +// #define BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS +// +// Performance tuning options: +// +// #define BOOST_MATH_POLY_METHOD 3 +// #define BOOST_MATH_RATIONAL_METHOD 3 +// +// The maximum order of polynomial that will be evaluated +// via an unrolled specialisation: +// +// #define BOOST_MATH_MAX_POLY_ORDER 17 +// +// decide whether to store constants as integers or reals: +// +// #define BOOST_MATH_INT_TABLE_TYPE(RT, IT) IT + +// +// Default policies follow: +// +// Domain errors: +// +// #define BOOST_MATH_DOMAIN_ERROR_POLICY throw_on_error +// +// Pole errors: +// +// #define BOOST_MATH_POLE_ERROR_POLICY throw_on_error +// +// Overflow Errors: +// +// #define BOOST_MATH_OVERFLOW_ERROR_POLICY throw_on_error +// +// Internal Evaluation Errors: +// +// #define BOOST_MATH_EVALUATION_ERROR_POLICY throw_on_error +// +// Underfow: +// +// #define BOOST_MATH_UNDERFLOW_ERROR_POLICY ignore_error +// +// Denorms: +// +// #define BOOST_MATH_DENORM_ERROR_POLICY ignore_error +// +// Max digits to use for internal calculations: +// +// #define BOOST_MATH_DIGITS10_POLICY 0 +// +// Promote floats to doubles internally? +// +// #define BOOST_MATH_PROMOTE_FLOAT_POLICY true +// +// Promote doubles to long double internally: +// +// #define BOOST_MATH_PROMOTE_DOUBLE_POLICY true +// +// What do discrete quantiles return? +// +// #define BOOST_MATH_DISCRETE_QUANTILE_POLICY integer_round_outwards +// +// If a function is mathematically undefined +// (for example the Cauchy distribution has no mean), +// then do we stop the code from compiling? +// +// #define BOOST_MATH_ASSERT_UNDEFINED_POLICY true +// +// Maximum series iterstions permitted: +// +// #define BOOST_MATH_MAX_SERIES_ITERATION_POLICY 1000000 +// +// Maximum root finding steps permitted: +// +// define BOOST_MATH_MAX_ROOT_ITERATION_POLICY 200 + +#endif // BOOST_MATH_TOOLS_USER_HPP + + diff --git a/Utilities/BGL/boost/math/tools/workaround.hpp b/Utilities/BGL/boost/math/tools/workaround.hpp new file mode 100644 index 0000000000000000000000000000000000000000..d4eb6e2f4b39bb9217e4a9b0e4656f2a1bc36612 --- /dev/null +++ b/Utilities/BGL/boost/math/tools/workaround.hpp @@ -0,0 +1,38 @@ +// Copyright (c) 2006-7 John Maddock +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_TOOLS_WORHAROUND_HPP +#define BOOST_MATH_TOOLS_WORHAROUND_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/math/tools/config.hpp> + +namespace boost{ namespace math{ namespace tools{ +// +// We call this short forwarding function so that we can work around a bug +// on Darwin that causes std::fmod to return a NaN. The test case is: +// std::fmod(1185.0L, 1.5L); +// +template <class T> +inline T fmod_workaround(T a, T b) +{ + BOOST_MATH_STD_USING + return fmod(a, b); +} +#if (defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__)) && ((LDBL_MANT_DIG == 106) || (__LDBL_MANT_DIG__ == 106)) +template <> +inline long double fmod_workaround(long double a, long double b) +{ + return ::fmodl(a, b); +} +#endif + +}}} // namespaces + +#endif // BOOST_MATH_TOOLS_WORHAROUND_HPP + diff --git a/Utilities/BGL/boost/math/tr1.hpp b/Utilities/BGL/boost/math/tr1.hpp new file mode 100644 index 0000000000000000000000000000000000000000..d58556d76cbbd2034daa6f341b0faaaefd3a2300 --- /dev/null +++ b/Utilities/BGL/boost/math/tr1.hpp @@ -0,0 +1,859 @@ +// Copyright John Maddock 2008. +// Use, modification and distribution are subject to 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) + +#ifndef BOOST_MATH_TR1_HPP +#define BOOST_MATH_TR1_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#ifdef __cplusplus + +#include <boost/config.hpp> +#include <boost/static_assert.hpp> + +namespace boost{ namespace math{ namespace tr1{ extern "C"{ + +#endif // __cplusplus + +#ifdef BOOST_HAS_DECLSPEC // defined in config system +// we need to import/export our code only if the user has specifically +// asked for it by defining either BOOST_ALL_DYN_LINK if they want all boost +// libraries to be dynamically linked, or BOOST_MATH_TR1_DYN_LINK +// if they want just this one to be dynamically liked: +#if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_MATH_TR1_DYN_LINK) +// export if this is our own source, otherwise import: +#ifdef BOOST_MATH_TR1_SOURCE +# define BOOST_MATH_TR1_DECL __declspec(dllexport) +#else +# define BOOST_MATH_TR1_DECL __declspec(dllimport) +#endif // BOOST_MATH_TR1_SOURCE +#endif // DYN_LINK +#endif // BOOST_HAS_DECLSPEC +// +// if BOOST_MATH_TR1_DECL isn't defined yet define it now: +#ifndef BOOST_MATH_TR1_DECL +#define BOOST_MATH_TR1_DECL +#endif + +// +// Now set up the libraries to link against: +// +#if !defined(BOOST_MATH_TR1_NO_LIB) && !defined(BOOST_MATH_TR1_SOURCE) \ + && !defined(BOOST_ALL_NO_LIB) && defined(__cplusplus) +# define BOOST_LIB_NAME boost_math_c99 +# if defined(BOOST_MATH_TR1_DYN_LINK) || defined(BOOST_ALL_DYN_LINK) +# define BOOST_DYN_LINK +# endif +# include <boost/config/auto_link.hpp> +#endif +#if !defined(BOOST_MATH_TR1_NO_LIB) && !defined(BOOST_MATH_TR1_SOURCE) \ + && !defined(BOOST_ALL_NO_LIB) && defined(__cplusplus) +# define BOOST_LIB_NAME boost_math_c99f +# if defined(BOOST_MATH_TR1_DYN_LINK) || defined(BOOST_ALL_DYN_LINK) +# define BOOST_DYN_LINK +# endif +# include <boost/config/auto_link.hpp> +#endif +#if !defined(BOOST_MATH_TR1_NO_LIB) && !defined(BOOST_MATH_TR1_SOURCE) \ + && !defined(BOOST_ALL_NO_LIB) && defined(__cplusplus) \ + && !defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS) +# define BOOST_LIB_NAME boost_math_c99l +# if defined(BOOST_MATH_TR1_DYN_LINK) || defined(BOOST_ALL_DYN_LINK) +# define BOOST_DYN_LINK +# endif +# include <boost/config/auto_link.hpp> +#endif +#if !defined(BOOST_MATH_TR1_NO_LIB) && !defined(BOOST_MATH_TR1_SOURCE) \ + && !defined(BOOST_ALL_NO_LIB) && defined(__cplusplus) +# define BOOST_LIB_NAME boost_math_tr1 +# if defined(BOOST_MATH_TR1_DYN_LINK) || defined(BOOST_ALL_DYN_LINK) +# define BOOST_DYN_LINK +# endif +# include <boost/config/auto_link.hpp> +#endif +#if !defined(BOOST_MATH_TR1_NO_LIB) && !defined(BOOST_MATH_TR1_SOURCE) \ + && !defined(BOOST_ALL_NO_LIB) && defined(__cplusplus) +# define BOOST_LIB_NAME boost_math_tr1f +# if defined(BOOST_MATH_TR1_DYN_LINK) || defined(BOOST_ALL_DYN_LINK) +# define BOOST_DYN_LINK +# endif +# include <boost/config/auto_link.hpp> +#endif +#if !defined(BOOST_MATH_TR1_NO_LIB) && !defined(BOOST_MATH_TR1_SOURCE) \ + && !defined(BOOST_ALL_NO_LIB) && defined(__cplusplus) \ + && !defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS) +# define BOOST_LIB_NAME boost_math_tr1l +# if defined(BOOST_MATH_TR1_DYN_LINK) || defined(BOOST_ALL_DYN_LINK) +# define BOOST_DYN_LINK +# endif +# include <boost/config/auto_link.hpp> +#endif + +#ifndef FLT_EVAL_METHOD +typedef float float_t; +typedef double double_t; +#elif FLT_EVAL_METHOD == 0 +typedef float float_t; +typedef double double_t; +#elif FLT_EVAL_METHOD == 1 +typedef double float_t; +typedef double double_t; +#else +typedef long double float_t; +typedef long double double_t; +#endif + +// C99 Functions: +double BOOST_MATH_TR1_DECL acosh BOOST_PREVENT_MACRO_SUBSTITUTION(double x); +float BOOST_MATH_TR1_DECL acoshf BOOST_PREVENT_MACRO_SUBSTITUTION(float x); +long double BOOST_MATH_TR1_DECL acoshl BOOST_PREVENT_MACRO_SUBSTITUTION(long double x); + +double BOOST_MATH_TR1_DECL asinh BOOST_PREVENT_MACRO_SUBSTITUTION(double x); +float BOOST_MATH_TR1_DECL asinhf BOOST_PREVENT_MACRO_SUBSTITUTION(float x); +long double BOOST_MATH_TR1_DECL asinhl BOOST_PREVENT_MACRO_SUBSTITUTION(long double x); + +double BOOST_MATH_TR1_DECL atanh BOOST_PREVENT_MACRO_SUBSTITUTION(double x); +float BOOST_MATH_TR1_DECL atanhf BOOST_PREVENT_MACRO_SUBSTITUTION(float x); +long double BOOST_MATH_TR1_DECL atanhl BOOST_PREVENT_MACRO_SUBSTITUTION(long double x); + +double BOOST_MATH_TR1_DECL cbrt BOOST_PREVENT_MACRO_SUBSTITUTION(double x); +float BOOST_MATH_TR1_DECL cbrtf BOOST_PREVENT_MACRO_SUBSTITUTION(float x); +long double BOOST_MATH_TR1_DECL cbrtl BOOST_PREVENT_MACRO_SUBSTITUTION(long double x); + +double BOOST_MATH_TR1_DECL copysign BOOST_PREVENT_MACRO_SUBSTITUTION(double x, double y); +float BOOST_MATH_TR1_DECL copysignf BOOST_PREVENT_MACRO_SUBSTITUTION(float x, float y); +long double BOOST_MATH_TR1_DECL copysignl BOOST_PREVENT_MACRO_SUBSTITUTION(long double x, long double y); + +double BOOST_MATH_TR1_DECL erf BOOST_PREVENT_MACRO_SUBSTITUTION(double x); +float BOOST_MATH_TR1_DECL erff BOOST_PREVENT_MACRO_SUBSTITUTION(float x); +long double BOOST_MATH_TR1_DECL erfl BOOST_PREVENT_MACRO_SUBSTITUTION(long double x); + +double BOOST_MATH_TR1_DECL erfc BOOST_PREVENT_MACRO_SUBSTITUTION(double x); +float BOOST_MATH_TR1_DECL erfcf BOOST_PREVENT_MACRO_SUBSTITUTION(float x); +long double BOOST_MATH_TR1_DECL erfcl BOOST_PREVENT_MACRO_SUBSTITUTION(long double x); +#if 0 +double BOOST_MATH_TR1_DECL exp2 BOOST_PREVENT_MACRO_SUBSTITUTION(double x); +float BOOST_MATH_TR1_DECL exp2f BOOST_PREVENT_MACRO_SUBSTITUTION(float x); +long double BOOST_MATH_TR1_DECL exp2l BOOST_PREVENT_MACRO_SUBSTITUTION(long double x); +#endif +double BOOST_MATH_TR1_DECL boost_expm1 BOOST_PREVENT_MACRO_SUBSTITUTION(double x); +float BOOST_MATH_TR1_DECL boost_expm1f BOOST_PREVENT_MACRO_SUBSTITUTION(float x); +long double BOOST_MATH_TR1_DECL boost_expm1l BOOST_PREVENT_MACRO_SUBSTITUTION(long double x); +#if 0 +double BOOST_MATH_TR1_DECL fdim BOOST_PREVENT_MACRO_SUBSTITUTION(double x, double y); +float BOOST_MATH_TR1_DECL fdimf BOOST_PREVENT_MACRO_SUBSTITUTION(float x, float y); +long double BOOST_MATH_TR1_DECL fdiml BOOST_PREVENT_MACRO_SUBSTITUTION(long double x, long double y); +double BOOST_MATH_TR1_DECL fma BOOST_PREVENT_MACRO_SUBSTITUTION(double x, double y, double z); +float BOOST_MATH_TR1_DECL fmaf BOOST_PREVENT_MACRO_SUBSTITUTION(float x, float y, float z); +long double BOOST_MATH_TR1_DECL fmal BOOST_PREVENT_MACRO_SUBSTITUTION(long double x, long double y, long double z); +#endif +double BOOST_MATH_TR1_DECL fmax BOOST_PREVENT_MACRO_SUBSTITUTION(double x, double y); +float BOOST_MATH_TR1_DECL fmaxf BOOST_PREVENT_MACRO_SUBSTITUTION(float x, float y); +long double BOOST_MATH_TR1_DECL fmaxl BOOST_PREVENT_MACRO_SUBSTITUTION(long double x, long double y); + +double BOOST_MATH_TR1_DECL fmin BOOST_PREVENT_MACRO_SUBSTITUTION(double x, double y); +float BOOST_MATH_TR1_DECL fminf BOOST_PREVENT_MACRO_SUBSTITUTION(float x, float y); +long double BOOST_MATH_TR1_DECL fminl BOOST_PREVENT_MACRO_SUBSTITUTION(long double x, long double y); + +double BOOST_MATH_TR1_DECL hypot BOOST_PREVENT_MACRO_SUBSTITUTION(double x, double y); +float BOOST_MATH_TR1_DECL hypotf BOOST_PREVENT_MACRO_SUBSTITUTION(float x, float y); +long double BOOST_MATH_TR1_DECL hypotl BOOST_PREVENT_MACRO_SUBSTITUTION(long double x, long double y); +#if 0 +int BOOST_MATH_TR1_DECL ilogb BOOST_PREVENT_MACRO_SUBSTITUTION(double x); +int BOOST_MATH_TR1_DECL ilogbf BOOST_PREVENT_MACRO_SUBSTITUTION(float x); +int BOOST_MATH_TR1_DECL ilogbl BOOST_PREVENT_MACRO_SUBSTITUTION(long double x); +#endif +double BOOST_MATH_TR1_DECL lgamma BOOST_PREVENT_MACRO_SUBSTITUTION(double x); +float BOOST_MATH_TR1_DECL lgammaf BOOST_PREVENT_MACRO_SUBSTITUTION(float x); +long double BOOST_MATH_TR1_DECL lgammal BOOST_PREVENT_MACRO_SUBSTITUTION(long double x); +#ifdef BOOST_HAS_LONG_LONG +#if 0 +::boost::long_long_type BOOST_MATH_TR1_DECL llrint BOOST_PREVENT_MACRO_SUBSTITUTION(double x); +::boost::long_long_type BOOST_MATH_TR1_DECL llrintf BOOST_PREVENT_MACRO_SUBSTITUTION(float x); +::boost::long_long_type BOOST_MATH_TR1_DECL llrintl BOOST_PREVENT_MACRO_SUBSTITUTION(long double x); +#endif +::boost::long_long_type BOOST_MATH_TR1_DECL llround BOOST_PREVENT_MACRO_SUBSTITUTION(double x); +::boost::long_long_type BOOST_MATH_TR1_DECL llroundf BOOST_PREVENT_MACRO_SUBSTITUTION(float x); +::boost::long_long_type BOOST_MATH_TR1_DECL llroundl BOOST_PREVENT_MACRO_SUBSTITUTION(long double x); +#endif +double BOOST_MATH_TR1_DECL boost_log1p BOOST_PREVENT_MACRO_SUBSTITUTION(double x); +float BOOST_MATH_TR1_DECL boost_log1pf BOOST_PREVENT_MACRO_SUBSTITUTION(float x); +long double BOOST_MATH_TR1_DECL boost_log1pl BOOST_PREVENT_MACRO_SUBSTITUTION(long double x); +#if 0 +double BOOST_MATH_TR1_DECL log2 BOOST_PREVENT_MACRO_SUBSTITUTION(double x); +float BOOST_MATH_TR1_DECL log2f BOOST_PREVENT_MACRO_SUBSTITUTION(float x); +long double BOOST_MATH_TR1_DECL log2l BOOST_PREVENT_MACRO_SUBSTITUTION(long double x); + +double BOOST_MATH_TR1_DECL logb BOOST_PREVENT_MACRO_SUBSTITUTION(double x); +float BOOST_MATH_TR1_DECL logbf BOOST_PREVENT_MACRO_SUBSTITUTION(float x); +long double BOOST_MATH_TR1_DECL logbl BOOST_PREVENT_MACRO_SUBSTITUTION(long double x); +long BOOST_MATH_TR1_DECL lrint BOOST_PREVENT_MACRO_SUBSTITUTION(double x); +long BOOST_MATH_TR1_DECL lrintf BOOST_PREVENT_MACRO_SUBSTITUTION(float x); +long BOOST_MATH_TR1_DECL lrintl BOOST_PREVENT_MACRO_SUBSTITUTION(long double x); +#endif +long BOOST_MATH_TR1_DECL lround BOOST_PREVENT_MACRO_SUBSTITUTION(double x); +long BOOST_MATH_TR1_DECL lroundf BOOST_PREVENT_MACRO_SUBSTITUTION(float x); +long BOOST_MATH_TR1_DECL lroundl BOOST_PREVENT_MACRO_SUBSTITUTION(long double x); +#if 0 +double BOOST_MATH_TR1_DECL nan BOOST_PREVENT_MACRO_SUBSTITUTION(const char *str); +float BOOST_MATH_TR1_DECL nanf BOOST_PREVENT_MACRO_SUBSTITUTION(const char *str); +long double BOOST_MATH_TR1_DECL nanl BOOST_PREVENT_MACRO_SUBSTITUTION(const char *str); +double BOOST_MATH_TR1_DECL nearbyint BOOST_PREVENT_MACRO_SUBSTITUTION(double x); +float BOOST_MATH_TR1_DECL nearbyintf BOOST_PREVENT_MACRO_SUBSTITUTION(float x); +long double BOOST_MATH_TR1_DECL nearbyintl BOOST_PREVENT_MACRO_SUBSTITUTION(long double x); +#endif +double BOOST_MATH_TR1_DECL boost_nextafter BOOST_PREVENT_MACRO_SUBSTITUTION(double x, double y); +float BOOST_MATH_TR1_DECL boost_nextafterf BOOST_PREVENT_MACRO_SUBSTITUTION(float x, float y); +long double BOOST_MATH_TR1_DECL boost_nextafterl BOOST_PREVENT_MACRO_SUBSTITUTION(long double x, long double y); + +double BOOST_MATH_TR1_DECL nexttoward BOOST_PREVENT_MACRO_SUBSTITUTION(double x, long double y); +float BOOST_MATH_TR1_DECL nexttowardf BOOST_PREVENT_MACRO_SUBSTITUTION(float x, long double y); +long double BOOST_MATH_TR1_DECL nexttowardl BOOST_PREVENT_MACRO_SUBSTITUTION(long double x, long double y); +#if 0 +double BOOST_MATH_TR1_DECL remainder BOOST_PREVENT_MACRO_SUBSTITUTION(double x, double y); +float BOOST_MATH_TR1_DECL remainderf BOOST_PREVENT_MACRO_SUBSTITUTION(float x, float y); +long double BOOST_MATH_TR1_DECL remainderl BOOST_PREVENT_MACRO_SUBSTITUTION(long double x, long double y); +double BOOST_MATH_TR1_DECL remquo BOOST_PREVENT_MACRO_SUBSTITUTION(double x, double y, int *pquo); +float BOOST_MATH_TR1_DECL remquof BOOST_PREVENT_MACRO_SUBSTITUTION(float x, float y, int *pquo); +long double BOOST_MATH_TR1_DECL remquol BOOST_PREVENT_MACRO_SUBSTITUTION(long double x, long double y, int *pquo); +double BOOST_MATH_TR1_DECL rint BOOST_PREVENT_MACRO_SUBSTITUTION(double x); +float BOOST_MATH_TR1_DECL rintf BOOST_PREVENT_MACRO_SUBSTITUTION(float x); +long double BOOST_MATH_TR1_DECL rintl BOOST_PREVENT_MACRO_SUBSTITUTION(long double x); +#endif +double BOOST_MATH_TR1_DECL round BOOST_PREVENT_MACRO_SUBSTITUTION(double x); +float BOOST_MATH_TR1_DECL roundf BOOST_PREVENT_MACRO_SUBSTITUTION(float x); +long double BOOST_MATH_TR1_DECL roundl BOOST_PREVENT_MACRO_SUBSTITUTION(long double x); +#if 0 +double BOOST_MATH_TR1_DECL scalbln BOOST_PREVENT_MACRO_SUBSTITUTION(double x, long ex); +float BOOST_MATH_TR1_DECL scalblnf BOOST_PREVENT_MACRO_SUBSTITUTION(float x, long ex); +long double BOOST_MATH_TR1_DECL scalblnl BOOST_PREVENT_MACRO_SUBSTITUTION(long double x, long ex); +double BOOST_MATH_TR1_DECL scalbn BOOST_PREVENT_MACRO_SUBSTITUTION(double x, int ex); +float BOOST_MATH_TR1_DECL scalbnf BOOST_PREVENT_MACRO_SUBSTITUTION(float x, int ex); +long double BOOST_MATH_TR1_DECL scalbnl BOOST_PREVENT_MACRO_SUBSTITUTION(long double x, int ex); +#endif +double BOOST_MATH_TR1_DECL tgamma BOOST_PREVENT_MACRO_SUBSTITUTION(double x); +float BOOST_MATH_TR1_DECL tgammaf BOOST_PREVENT_MACRO_SUBSTITUTION(float x); +long double BOOST_MATH_TR1_DECL tgammal BOOST_PREVENT_MACRO_SUBSTITUTION(long double x); + +double BOOST_MATH_TR1_DECL trunc BOOST_PREVENT_MACRO_SUBSTITUTION(double x); +float BOOST_MATH_TR1_DECL truncf BOOST_PREVENT_MACRO_SUBSTITUTION(float x); +long double BOOST_MATH_TR1_DECL truncl BOOST_PREVENT_MACRO_SUBSTITUTION(long double x); + +// [5.2.1.1] associated Laguerre polynomials: +double BOOST_MATH_TR1_DECL assoc_laguerre BOOST_PREVENT_MACRO_SUBSTITUTION(unsigned n, unsigned m, double x); +float BOOST_MATH_TR1_DECL assoc_laguerref BOOST_PREVENT_MACRO_SUBSTITUTION(unsigned n, unsigned m, float x); +long double BOOST_MATH_TR1_DECL assoc_laguerrel BOOST_PREVENT_MACRO_SUBSTITUTION(unsigned n, unsigned m, long double x); + +// [5.2.1.2] associated Legendre functions: +double BOOST_MATH_TR1_DECL assoc_legendre BOOST_PREVENT_MACRO_SUBSTITUTION(unsigned l, unsigned m, double x); +float BOOST_MATH_TR1_DECL assoc_legendref BOOST_PREVENT_MACRO_SUBSTITUTION(unsigned l, unsigned m, float x); +long double BOOST_MATH_TR1_DECL assoc_legendrel BOOST_PREVENT_MACRO_SUBSTITUTION(unsigned l, unsigned m, long double x); + +// [5.2.1.3] beta function: +double BOOST_MATH_TR1_DECL beta BOOST_PREVENT_MACRO_SUBSTITUTION(double x, double y); +float BOOST_MATH_TR1_DECL betaf BOOST_PREVENT_MACRO_SUBSTITUTION(float x, float y); +long double BOOST_MATH_TR1_DECL betal BOOST_PREVENT_MACRO_SUBSTITUTION(long double x, long double y); + +// [5.2.1.4] (complete) elliptic integral of the first kind: +double BOOST_MATH_TR1_DECL comp_ellint_1 BOOST_PREVENT_MACRO_SUBSTITUTION(double k); +float BOOST_MATH_TR1_DECL comp_ellint_1f BOOST_PREVENT_MACRO_SUBSTITUTION(float k); +long double BOOST_MATH_TR1_DECL comp_ellint_1l BOOST_PREVENT_MACRO_SUBSTITUTION(long double k); + +// [5.2.1.5] (complete) elliptic integral of the second kind: +double BOOST_MATH_TR1_DECL comp_ellint_2 BOOST_PREVENT_MACRO_SUBSTITUTION(double k); +float BOOST_MATH_TR1_DECL comp_ellint_2f BOOST_PREVENT_MACRO_SUBSTITUTION(float k); +long double BOOST_MATH_TR1_DECL comp_ellint_2l BOOST_PREVENT_MACRO_SUBSTITUTION(long double k); + +// [5.2.1.6] (complete) elliptic integral of the third kind: +double BOOST_MATH_TR1_DECL comp_ellint_3 BOOST_PREVENT_MACRO_SUBSTITUTION(double k, double nu); +float BOOST_MATH_TR1_DECL comp_ellint_3f BOOST_PREVENT_MACRO_SUBSTITUTION(float k, float nu); +long double BOOST_MATH_TR1_DECL comp_ellint_3l BOOST_PREVENT_MACRO_SUBSTITUTION(long double k, long double nu); +#if 0 +// [5.2.1.7] confluent hypergeometric functions: +double BOOST_MATH_TR1_DECL conf_hyperg BOOST_PREVENT_MACRO_SUBSTITUTION(double a, double c, double x); +float BOOST_MATH_TR1_DECL conf_hypergf BOOST_PREVENT_MACRO_SUBSTITUTION(float a, float c, float x); +long double BOOST_MATH_TR1_DECL conf_hypergl BOOST_PREVENT_MACRO_SUBSTITUTION(long double a, long double c, long double x); +#endif +// [5.2.1.8] regular modified cylindrical Bessel functions: +double BOOST_MATH_TR1_DECL cyl_bessel_i BOOST_PREVENT_MACRO_SUBSTITUTION(double nu, double x); +float BOOST_MATH_TR1_DECL cyl_bessel_if BOOST_PREVENT_MACRO_SUBSTITUTION(float nu, float x); +long double BOOST_MATH_TR1_DECL cyl_bessel_il BOOST_PREVENT_MACRO_SUBSTITUTION(long double nu, long double x); + +// [5.2.1.9] cylindrical Bessel functions (of the first kind): +double BOOST_MATH_TR1_DECL cyl_bessel_j BOOST_PREVENT_MACRO_SUBSTITUTION(double nu, double x); +float BOOST_MATH_TR1_DECL cyl_bessel_jf BOOST_PREVENT_MACRO_SUBSTITUTION(float nu, float x); +long double BOOST_MATH_TR1_DECL cyl_bessel_jl BOOST_PREVENT_MACRO_SUBSTITUTION(long double nu, long double x); + +// [5.2.1.10] irregular modified cylindrical Bessel functions: +double BOOST_MATH_TR1_DECL cyl_bessel_k BOOST_PREVENT_MACRO_SUBSTITUTION(double nu, double x); +float BOOST_MATH_TR1_DECL cyl_bessel_kf BOOST_PREVENT_MACRO_SUBSTITUTION(float nu, float x); +long double BOOST_MATH_TR1_DECL cyl_bessel_kl BOOST_PREVENT_MACRO_SUBSTITUTION(long double nu, long double x); + +// [5.2.1.11] cylindrical Neumann functions; +// cylindrical Bessel functions (of the second kind): +double BOOST_MATH_TR1_DECL cyl_neumann BOOST_PREVENT_MACRO_SUBSTITUTION(double nu, double x); +float BOOST_MATH_TR1_DECL cyl_neumannf BOOST_PREVENT_MACRO_SUBSTITUTION(float nu, float x); +long double BOOST_MATH_TR1_DECL cyl_neumannl BOOST_PREVENT_MACRO_SUBSTITUTION(long double nu, long double x); + +// [5.2.1.12] (incomplete) elliptic integral of the first kind: +double BOOST_MATH_TR1_DECL ellint_1 BOOST_PREVENT_MACRO_SUBSTITUTION(double k, double phi); +float BOOST_MATH_TR1_DECL ellint_1f BOOST_PREVENT_MACRO_SUBSTITUTION(float k, float phi); +long double BOOST_MATH_TR1_DECL ellint_1l BOOST_PREVENT_MACRO_SUBSTITUTION(long double k, long double phi); + +// [5.2.1.13] (incomplete) elliptic integral of the second kind: +double BOOST_MATH_TR1_DECL ellint_2 BOOST_PREVENT_MACRO_SUBSTITUTION(double k, double phi); +float BOOST_MATH_TR1_DECL ellint_2f BOOST_PREVENT_MACRO_SUBSTITUTION(float k, float phi); +long double BOOST_MATH_TR1_DECL ellint_2l BOOST_PREVENT_MACRO_SUBSTITUTION(long double k, long double phi); + +// [5.2.1.14] (incomplete) elliptic integral of the third kind: +double BOOST_MATH_TR1_DECL ellint_3 BOOST_PREVENT_MACRO_SUBSTITUTION(double k, double nu, double phi); +float BOOST_MATH_TR1_DECL ellint_3f BOOST_PREVENT_MACRO_SUBSTITUTION(float k, float nu, float phi); +long double BOOST_MATH_TR1_DECL ellint_3l BOOST_PREVENT_MACRO_SUBSTITUTION(long double k, long double nu, long double phi); + +// [5.2.1.15] exponential integral: +double BOOST_MATH_TR1_DECL expint BOOST_PREVENT_MACRO_SUBSTITUTION(double x); +float BOOST_MATH_TR1_DECL expintf BOOST_PREVENT_MACRO_SUBSTITUTION(float x); +long double BOOST_MATH_TR1_DECL expintl BOOST_PREVENT_MACRO_SUBSTITUTION(long double x); + +// [5.2.1.16] Hermite polynomials: +double BOOST_MATH_TR1_DECL hermite BOOST_PREVENT_MACRO_SUBSTITUTION(unsigned n, double x); +float BOOST_MATH_TR1_DECL hermitef BOOST_PREVENT_MACRO_SUBSTITUTION(unsigned n, float x); +long double BOOST_MATH_TR1_DECL hermitel BOOST_PREVENT_MACRO_SUBSTITUTION(unsigned n, long double x); + +#if 0 +// [5.2.1.17] hypergeometric functions: +double BOOST_MATH_TR1_DECL hyperg BOOST_PREVENT_MACRO_SUBSTITUTION(double a, double b, double c, double x); +float BOOST_MATH_TR1_DECL hypergf BOOST_PREVENT_MACRO_SUBSTITUTION(float a, float b, float c, float x); +long double BOOST_MATH_TR1_DECL hypergl BOOST_PREVENT_MACRO_SUBSTITUTION(long double a, long double b, long double c, +long double x); +#endif + +// [5.2.1.18] Laguerre polynomials: +double BOOST_MATH_TR1_DECL laguerre BOOST_PREVENT_MACRO_SUBSTITUTION(unsigned n, double x); +float BOOST_MATH_TR1_DECL laguerref BOOST_PREVENT_MACRO_SUBSTITUTION(unsigned n, float x); +long double BOOST_MATH_TR1_DECL laguerrel BOOST_PREVENT_MACRO_SUBSTITUTION(unsigned n, long double x); + +// [5.2.1.19] Legendre polynomials: +double BOOST_MATH_TR1_DECL legendre BOOST_PREVENT_MACRO_SUBSTITUTION(unsigned l, double x); +float BOOST_MATH_TR1_DECL legendref BOOST_PREVENT_MACRO_SUBSTITUTION(unsigned l, float x); +long double BOOST_MATH_TR1_DECL legendrel BOOST_PREVENT_MACRO_SUBSTITUTION(unsigned l, long double x); + +// [5.2.1.20] Riemann zeta function: +double BOOST_MATH_TR1_DECL riemann_zeta BOOST_PREVENT_MACRO_SUBSTITUTION(double); +float BOOST_MATH_TR1_DECL riemann_zetaf BOOST_PREVENT_MACRO_SUBSTITUTION(float); +long double BOOST_MATH_TR1_DECL riemann_zetal BOOST_PREVENT_MACRO_SUBSTITUTION(long double); + +// [5.2.1.21] spherical Bessel functions (of the first kind): +double BOOST_MATH_TR1_DECL sph_bessel BOOST_PREVENT_MACRO_SUBSTITUTION(unsigned n, double x); +float BOOST_MATH_TR1_DECL sph_besself BOOST_PREVENT_MACRO_SUBSTITUTION(unsigned n, float x); +long double BOOST_MATH_TR1_DECL sph_bessell BOOST_PREVENT_MACRO_SUBSTITUTION(unsigned n, long double x); + +// [5.2.1.22] spherical associated Legendre functions: +double BOOST_MATH_TR1_DECL sph_legendre BOOST_PREVENT_MACRO_SUBSTITUTION(unsigned l, unsigned m, double theta); +float BOOST_MATH_TR1_DECL sph_legendref BOOST_PREVENT_MACRO_SUBSTITUTION(unsigned l, unsigned m, float theta); +long double BOOST_MATH_TR1_DECL sph_legendrel BOOST_PREVENT_MACRO_SUBSTITUTION(unsigned l, unsigned m, long double theta); + +// [5.2.1.23] spherical Neumann functions; +// spherical Bessel functions (of the second kind): +double BOOST_MATH_TR1_DECL sph_neumann BOOST_PREVENT_MACRO_SUBSTITUTION(unsigned n, double x); +float BOOST_MATH_TR1_DECL sph_neumannf BOOST_PREVENT_MACRO_SUBSTITUTION(unsigned n, float x); +long double BOOST_MATH_TR1_DECL sph_neumannl BOOST_PREVENT_MACRO_SUBSTITUTION(unsigned n, long double x); + +#ifdef __cplusplus + +}}}} // namespaces + +#include <boost/math/tools/promotion.hpp> + +namespace boost{ namespace math{ namespace tr1{ +// +// Declare overload of the functions which forward to the +// C interfaces: +// +// C99 Functions: +inline float acosh BOOST_PREVENT_MACRO_SUBSTITUTION(float x) +{ return boost::math::tr1::acoshf BOOST_PREVENT_MACRO_SUBSTITUTION(x); } +inline long double acosh BOOST_PREVENT_MACRO_SUBSTITUTION(long double x) +{ return boost::math::tr1::acoshl BOOST_PREVENT_MACRO_SUBSTITUTION(x); } +template <class T> +inline typename tools::promote_args<T>::type acosh BOOST_PREVENT_MACRO_SUBSTITUTION(T x) +{ return boost::math::tr1::acosh BOOST_PREVENT_MACRO_SUBSTITUTION(static_cast<typename tools::promote_args<T>::type>(x)); } + +inline float asinh BOOST_PREVENT_MACRO_SUBSTITUTION(float x){ return boost::math::tr1::asinhf BOOST_PREVENT_MACRO_SUBSTITUTION(x); } +inline long double asinh BOOST_PREVENT_MACRO_SUBSTITUTION(long double x){ return boost::math::tr1::asinhl BOOST_PREVENT_MACRO_SUBSTITUTION(x); } +template <class T> +inline typename tools::promote_args<T>::type asinh BOOST_PREVENT_MACRO_SUBSTITUTION(T x) +{ return boost::math::tr1::asinh BOOST_PREVENT_MACRO_SUBSTITUTION(static_cast<typename tools::promote_args<T>::type>(x)); } + +inline float atanh BOOST_PREVENT_MACRO_SUBSTITUTION(float x){ return boost::math::tr1::atanhf BOOST_PREVENT_MACRO_SUBSTITUTION(x); } +inline long double atanh BOOST_PREVENT_MACRO_SUBSTITUTION(long double x){ return boost::math::tr1::atanhl(x); } +template <class T> +inline typename tools::promote_args<T>::type atanh BOOST_PREVENT_MACRO_SUBSTITUTION(T x) +{ return boost::math::tr1::atanh BOOST_PREVENT_MACRO_SUBSTITUTION(static_cast<typename tools::promote_args<T>::type>(x)); } + +inline float cbrt BOOST_PREVENT_MACRO_SUBSTITUTION(float x) +{ return boost::math::tr1::cbrtf BOOST_PREVENT_MACRO_SUBSTITUTION(x); } +inline long double cbrt BOOST_PREVENT_MACRO_SUBSTITUTION(long double x) +{ return boost::math::tr1::cbrtl BOOST_PREVENT_MACRO_SUBSTITUTION(x); } +template <class T> +inline typename tools::promote_args<T>::type cbrt BOOST_PREVENT_MACRO_SUBSTITUTION(T x) +{ return boost::math::tr1::cbrt BOOST_PREVENT_MACRO_SUBSTITUTION(static_cast<typename tools::promote_args<T>::type>(x)); } + +inline float copysign BOOST_PREVENT_MACRO_SUBSTITUTION(float x, float y) +{ return boost::math::tr1::copysignf BOOST_PREVENT_MACRO_SUBSTITUTION(x, y); } +inline long double copysign BOOST_PREVENT_MACRO_SUBSTITUTION(long double x, long double y) +{ return boost::math::tr1::copysignl BOOST_PREVENT_MACRO_SUBSTITUTION(x, y); } +template <class T1, class T2> +inline typename tools::promote_args<T1, T2>::type copysign BOOST_PREVENT_MACRO_SUBSTITUTION(T1 x, T2 y) +{ return boost::math::tr1::copysign BOOST_PREVENT_MACRO_SUBSTITUTION(static_cast<typename tools::promote_args<T1, T2>::type>(x), static_cast<typename tools::promote_args<T1, T2>::type>(y)); } + +inline float erf BOOST_PREVENT_MACRO_SUBSTITUTION(float x) +{ return boost::math::tr1::erff BOOST_PREVENT_MACRO_SUBSTITUTION(x); } +inline long double erf BOOST_PREVENT_MACRO_SUBSTITUTION(long double x) +{ return boost::math::tr1::erfl BOOST_PREVENT_MACRO_SUBSTITUTION(x); } +template <class T> +inline typename tools::promote_args<T>::type erf BOOST_PREVENT_MACRO_SUBSTITUTION(T x) +{ return boost::math::tr1::erf BOOST_PREVENT_MACRO_SUBSTITUTION(static_cast<typename tools::promote_args<T>::type>(x)); } + +inline float erfc BOOST_PREVENT_MACRO_SUBSTITUTION(float x) +{ return boost::math::tr1::erfcf BOOST_PREVENT_MACRO_SUBSTITUTION(x); } +inline long double erfc BOOST_PREVENT_MACRO_SUBSTITUTION(long double x) +{ return boost::math::tr1::erfcl BOOST_PREVENT_MACRO_SUBSTITUTION(x); } +template <class T> +inline typename tools::promote_args<T>::type erfc BOOST_PREVENT_MACRO_SUBSTITUTION(T x) +{ return boost::math::tr1::erfc BOOST_PREVENT_MACRO_SUBSTITUTION(static_cast<typename tools::promote_args<T>::type>(x)); } +#if 0 +double exp2 BOOST_PREVENT_MACRO_SUBSTITUTION(double x); +float exp2f BOOST_PREVENT_MACRO_SUBSTITUTION(float x); +long double exp2l BOOST_PREVENT_MACRO_SUBSTITUTION(long double x); +#endif +inline float expm1f BOOST_PREVENT_MACRO_SUBSTITUTION(float x) +{ return boost::math::tr1::boost_expm1f BOOST_PREVENT_MACRO_SUBSTITUTION(x); } +inline double expm1 BOOST_PREVENT_MACRO_SUBSTITUTION(double x) +{ return boost::math::tr1::boost_expm1 BOOST_PREVENT_MACRO_SUBSTITUTION(x); } +inline long double expm1l BOOST_PREVENT_MACRO_SUBSTITUTION(long double x) +{ return boost::math::tr1::boost_expm1l BOOST_PREVENT_MACRO_SUBSTITUTION(x); } +inline float expm1 BOOST_PREVENT_MACRO_SUBSTITUTION(float x) +{ return boost::math::tr1::expm1f BOOST_PREVENT_MACRO_SUBSTITUTION(x); } +inline long double expm1 BOOST_PREVENT_MACRO_SUBSTITUTION(long double x) +{ return boost::math::tr1::expm1l BOOST_PREVENT_MACRO_SUBSTITUTION(x); } +template <class T> +inline typename tools::promote_args<T>::type expm1 BOOST_PREVENT_MACRO_SUBSTITUTION(T x) +{ return boost::math::tr1::expm1 BOOST_PREVENT_MACRO_SUBSTITUTION(static_cast<typename tools::promote_args<T>::type>(x)); } +#if 0 +double fdim BOOST_PREVENT_MACRO_SUBSTITUTION(double x, double y); +float fdimf BOOST_PREVENT_MACRO_SUBSTITUTION(float x, float y); +long double fdiml BOOST_PREVENT_MACRO_SUBSTITUTION(long double x, long double y); +double fma BOOST_PREVENT_MACRO_SUBSTITUTION(double x, double y, double z); +float fmaf BOOST_PREVENT_MACRO_SUBSTITUTION(float x, float y, float z); +long double fmal BOOST_PREVENT_MACRO_SUBSTITUTION(long double x, long double y, long double z); +#endif +inline float fmax BOOST_PREVENT_MACRO_SUBSTITUTION(float x, float y) +{ return boost::math::tr1::fmaxf BOOST_PREVENT_MACRO_SUBSTITUTION(x, y); } +inline long double fmax BOOST_PREVENT_MACRO_SUBSTITUTION(long double x, long double y) +{ return boost::math::tr1::fmaxl BOOST_PREVENT_MACRO_SUBSTITUTION(x, y); } +template <class T1, class T2> +inline typename tools::promote_args<T1, T2>::type fmax BOOST_PREVENT_MACRO_SUBSTITUTION(T1 x, T2 y) +{ return boost::math::tr1::fmax BOOST_PREVENT_MACRO_SUBSTITUTION(static_cast<typename tools::promote_args<T1, T2>::type>(x), static_cast<typename tools::promote_args<T1, T2>::type>(y)); } + +inline float fmin BOOST_PREVENT_MACRO_SUBSTITUTION(float x, float y) +{ return boost::math::tr1::fminf BOOST_PREVENT_MACRO_SUBSTITUTION(x, y); } +inline long double fmin BOOST_PREVENT_MACRO_SUBSTITUTION(long double x, long double y) +{ return boost::math::tr1::fminl BOOST_PREVENT_MACRO_SUBSTITUTION(x, y); } +template <class T1, class T2> +inline typename tools::promote_args<T1, T2>::type fmin BOOST_PREVENT_MACRO_SUBSTITUTION(T1 x, T2 y) +{ return boost::math::tr1::fmin BOOST_PREVENT_MACRO_SUBSTITUTION(static_cast<typename tools::promote_args<T1, T2>::type>(x), static_cast<typename tools::promote_args<T1, T2>::type>(y)); } + +inline float hypot BOOST_PREVENT_MACRO_SUBSTITUTION(float x, float y) +{ return boost::math::tr1::hypotf BOOST_PREVENT_MACRO_SUBSTITUTION(x, y); } +inline long double hypot BOOST_PREVENT_MACRO_SUBSTITUTION(long double x, long double y) +{ return boost::math::tr1::hypotl BOOST_PREVENT_MACRO_SUBSTITUTION(x, y); } +template <class T1, class T2> +inline typename tools::promote_args<T1, T2>::type hypot BOOST_PREVENT_MACRO_SUBSTITUTION(T1 x, T2 y) +{ return boost::math::tr1::hypot BOOST_PREVENT_MACRO_SUBSTITUTION(static_cast<typename tools::promote_args<T1, T2>::type>(x), static_cast<typename tools::promote_args<T1, T2>::type>(y)); } +#if 0 +int ilogb BOOST_PREVENT_MACRO_SUBSTITUTION(double x); +int ilogbf BOOST_PREVENT_MACRO_SUBSTITUTION(float x); +int ilogbl BOOST_PREVENT_MACRO_SUBSTITUTION(long double x); +#endif +inline float lgamma BOOST_PREVENT_MACRO_SUBSTITUTION(float x) +{ return boost::math::tr1::lgammaf BOOST_PREVENT_MACRO_SUBSTITUTION(x); } +inline long double lgamma BOOST_PREVENT_MACRO_SUBSTITUTION(long double x) +{ return boost::math::tr1::lgammal BOOST_PREVENT_MACRO_SUBSTITUTION(x); } +template <class T> +inline typename tools::promote_args<T>::type lgamma BOOST_PREVENT_MACRO_SUBSTITUTION(T x) +{ return boost::math::tr1::lgamma BOOST_PREVENT_MACRO_SUBSTITUTION(static_cast<typename tools::promote_args<T>::type>(x)); } +#ifdef BOOST_HAS_LONG_LONG +#if 0 +::boost::long_long_type llrint BOOST_PREVENT_MACRO_SUBSTITUTION(double x); +::boost::long_long_type llrintf BOOST_PREVENT_MACRO_SUBSTITUTION(float x); +::boost::long_long_type llrintl BOOST_PREVENT_MACRO_SUBSTITUTION(long double x); +#endif +inline ::boost::long_long_type llround BOOST_PREVENT_MACRO_SUBSTITUTION(float x) +{ return boost::math::tr1::llroundf BOOST_PREVENT_MACRO_SUBSTITUTION(x); } +inline ::boost::long_long_type llround BOOST_PREVENT_MACRO_SUBSTITUTION(long double x) +{ return boost::math::tr1::llroundl BOOST_PREVENT_MACRO_SUBSTITUTION(x); } +template <class T> +inline ::boost::long_long_type llround BOOST_PREVENT_MACRO_SUBSTITUTION(T x) +{ return llround BOOST_PREVENT_MACRO_SUBSTITUTION(static_cast<double>(x)); } +#endif +inline float log1pf BOOST_PREVENT_MACRO_SUBSTITUTION(float x) +{ return boost::math::tr1::boost_log1pf BOOST_PREVENT_MACRO_SUBSTITUTION(x); } +inline double log1p BOOST_PREVENT_MACRO_SUBSTITUTION(double x) +{ return boost::math::tr1::boost_log1p BOOST_PREVENT_MACRO_SUBSTITUTION(x); } +inline long double log1pl BOOST_PREVENT_MACRO_SUBSTITUTION(long double x) +{ return boost::math::tr1::boost_log1pl BOOST_PREVENT_MACRO_SUBSTITUTION(x); } +inline float log1p BOOST_PREVENT_MACRO_SUBSTITUTION(float x) +{ return boost::math::tr1::log1pf BOOST_PREVENT_MACRO_SUBSTITUTION(x); } +inline long double log1p BOOST_PREVENT_MACRO_SUBSTITUTION(long double x) +{ return boost::math::tr1::log1pl BOOST_PREVENT_MACRO_SUBSTITUTION(x); } +template <class T> +inline typename tools::promote_args<T>::type log1p BOOST_PREVENT_MACRO_SUBSTITUTION(T x) +{ return boost::math::tr1::log1p BOOST_PREVENT_MACRO_SUBSTITUTION(static_cast<typename tools::promote_args<T>::type>(x)); } +#if 0 +double log2 BOOST_PREVENT_MACRO_SUBSTITUTION(double x); +float log2f BOOST_PREVENT_MACRO_SUBSTITUTION(float x); +long double log2l BOOST_PREVENT_MACRO_SUBSTITUTION(long double x); + +double logb BOOST_PREVENT_MACRO_SUBSTITUTION(double x); +float logbf BOOST_PREVENT_MACRO_SUBSTITUTION(float x); +long double logbl BOOST_PREVENT_MACRO_SUBSTITUTION(long double x); +long lrint BOOST_PREVENT_MACRO_SUBSTITUTION(double x); +long lrintf BOOST_PREVENT_MACRO_SUBSTITUTION(float x); +long lrintl BOOST_PREVENT_MACRO_SUBSTITUTION(long double x); +#endif +inline long lround BOOST_PREVENT_MACRO_SUBSTITUTION(float x) +{ return boost::math::tr1::lroundf BOOST_PREVENT_MACRO_SUBSTITUTION(x); } +inline long lround BOOST_PREVENT_MACRO_SUBSTITUTION(long double x) +{ return boost::math::tr1::lroundl BOOST_PREVENT_MACRO_SUBSTITUTION(x); } +template <class T> +long lround BOOST_PREVENT_MACRO_SUBSTITUTION(T x) +{ return boost::math::tr1::lround BOOST_PREVENT_MACRO_SUBSTITUTION(static_cast<double>(x)); } +#if 0 +double nan BOOST_PREVENT_MACRO_SUBSTITUTION(const char *str); +float nanf BOOST_PREVENT_MACRO_SUBSTITUTION(const char *str); +long double nanl BOOST_PREVENT_MACRO_SUBSTITUTION(const char *str); +double nearbyint BOOST_PREVENT_MACRO_SUBSTITUTION(double x); +float nearbyintf BOOST_PREVENT_MACRO_SUBSTITUTION(float x); +long double nearbyintl BOOST_PREVENT_MACRO_SUBSTITUTION(long double x); +#endif +inline float nextafterf BOOST_PREVENT_MACRO_SUBSTITUTION(float x, float y) +{ return boost::math::tr1::boost_nextafterf BOOST_PREVENT_MACRO_SUBSTITUTION(x, y); } +inline double nextafter BOOST_PREVENT_MACRO_SUBSTITUTION(double x, double y) +{ return boost::math::tr1::boost_nextafter BOOST_PREVENT_MACRO_SUBSTITUTION(x, y); } +inline long double nextafterl BOOST_PREVENT_MACRO_SUBSTITUTION(long double x, long double y) +{ return boost::math::tr1::boost_nextafterl BOOST_PREVENT_MACRO_SUBSTITUTION(x, y); } +inline float nextafter BOOST_PREVENT_MACRO_SUBSTITUTION(float x, float y) +{ return boost::math::tr1::nextafterf BOOST_PREVENT_MACRO_SUBSTITUTION(x, y); } +inline long double nextafter BOOST_PREVENT_MACRO_SUBSTITUTION(long double x, long double y) +{ return boost::math::tr1::nextafterl BOOST_PREVENT_MACRO_SUBSTITUTION(x, y); } +template <class T1, class T2> +inline typename tools::promote_args<T1, T2>::type nextafter BOOST_PREVENT_MACRO_SUBSTITUTION(T1 x, T2 y) +{ return boost::math::tr1::nextafter BOOST_PREVENT_MACRO_SUBSTITUTION(static_cast<typename tools::promote_args<T1, T2>::type>(x), static_cast<typename tools::promote_args<T1, T2>::type>(y)); } + +inline float nexttoward BOOST_PREVENT_MACRO_SUBSTITUTION(float x, long double y) +{ return boost::math::tr1::nexttowardf BOOST_PREVENT_MACRO_SUBSTITUTION(x, y); } +inline long double nexttoward BOOST_PREVENT_MACRO_SUBSTITUTION(long double x, long double y) +{ return boost::math::tr1::nexttowardl BOOST_PREVENT_MACRO_SUBSTITUTION(x, y); } +template <class T1, class T2> +inline typename tools::promote_args<T1, T2>::type nexttoward BOOST_PREVENT_MACRO_SUBSTITUTION(T1 x, T2 y) +{ return boost::math::tr1::nexttoward BOOST_PREVENT_MACRO_SUBSTITUTION(static_cast<typename tools::promote_args<T1, T2>::type>(x), static_cast<long double>(y)); } +#if 0 +double remainder BOOST_PREVENT_MACRO_SUBSTITUTION(double x, double y); +float remainderf BOOST_PREVENT_MACRO_SUBSTITUTION(float x, float y); +long double remainderl BOOST_PREVENT_MACRO_SUBSTITUTION(long double x, long double y); +double remquo BOOST_PREVENT_MACRO_SUBSTITUTION(double x, double y, int *pquo); +float remquof BOOST_PREVENT_MACRO_SUBSTITUTION(float x, float y, int *pquo); +long double remquol BOOST_PREVENT_MACRO_SUBSTITUTION(long double x, long double y, int *pquo); +double rint BOOST_PREVENT_MACRO_SUBSTITUTION(double x); +float rintf BOOST_PREVENT_MACRO_SUBSTITUTION(float x); +long double rintl BOOST_PREVENT_MACRO_SUBSTITUTION(long double x); +#endif +inline float round BOOST_PREVENT_MACRO_SUBSTITUTION(float x) +{ return boost::math::tr1::roundf BOOST_PREVENT_MACRO_SUBSTITUTION(x); } +inline long double round BOOST_PREVENT_MACRO_SUBSTITUTION(long double x) +{ return boost::math::tr1::roundl BOOST_PREVENT_MACRO_SUBSTITUTION(x); } +template <class T> +inline typename tools::promote_args<T>::type round BOOST_PREVENT_MACRO_SUBSTITUTION(T x) +{ return boost::math::tr1::round BOOST_PREVENT_MACRO_SUBSTITUTION(static_cast<typename tools::promote_args<T>::type>(x)); } +#if 0 +double scalbln BOOST_PREVENT_MACRO_SUBSTITUTION(double x, long ex); +float scalblnf BOOST_PREVENT_MACRO_SUBSTITUTION(float x, long ex); +long double scalblnl BOOST_PREVENT_MACRO_SUBSTITUTION(long double x, long ex); +double scalbn BOOST_PREVENT_MACRO_SUBSTITUTION(double x, int ex); +float scalbnf BOOST_PREVENT_MACRO_SUBSTITUTION(float x, int ex); +long double scalbnl BOOST_PREVENT_MACRO_SUBSTITUTION(long double x, int ex); +#endif +inline float tgamma BOOST_PREVENT_MACRO_SUBSTITUTION(float x) +{ return boost::math::tr1::tgammaf BOOST_PREVENT_MACRO_SUBSTITUTION(x); } +inline long double tgamma BOOST_PREVENT_MACRO_SUBSTITUTION(long double x) +{ return boost::math::tr1::tgammal BOOST_PREVENT_MACRO_SUBSTITUTION(x); } +template <class T> +inline typename tools::promote_args<T>::type tgamma BOOST_PREVENT_MACRO_SUBSTITUTION(T x) +{ return boost::math::tr1::tgamma BOOST_PREVENT_MACRO_SUBSTITUTION(static_cast<typename tools::promote_args<T>::type>(x)); } + +inline float trunc BOOST_PREVENT_MACRO_SUBSTITUTION(float x) +{ return boost::math::tr1::truncf BOOST_PREVENT_MACRO_SUBSTITUTION(x); } +inline long double trunc BOOST_PREVENT_MACRO_SUBSTITUTION(long double x) +{ return boost::math::tr1::truncl BOOST_PREVENT_MACRO_SUBSTITUTION(x); } +template <class T> +inline typename tools::promote_args<T>::type trunc BOOST_PREVENT_MACRO_SUBSTITUTION(T x) +{ return boost::math::tr1::trunc BOOST_PREVENT_MACRO_SUBSTITUTION(static_cast<typename tools::promote_args<T>::type>(x)); } + +# define NO_MACRO_EXPAND /**/ +// C99 macros defined as C++ templates +template<class T> bool signbit NO_MACRO_EXPAND(T x) +{ BOOST_STATIC_ASSERT(sizeof(T) == 0); return false; } // must not be instantiated +template<> bool BOOST_MATH_TR1_DECL signbit<float> NO_MACRO_EXPAND(float x); +template<> bool BOOST_MATH_TR1_DECL signbit<double> NO_MACRO_EXPAND(double x); +template<> bool BOOST_MATH_TR1_DECL signbit<long double> NO_MACRO_EXPAND(long double x); + +template<class T> int fpclassify NO_MACRO_EXPAND(T x) +{ BOOST_STATIC_ASSERT(sizeof(T) == 0); return false; } // must not be instantiated +template<> int BOOST_MATH_TR1_DECL fpclassify<float> NO_MACRO_EXPAND(float x); +template<> int BOOST_MATH_TR1_DECL fpclassify<double> NO_MACRO_EXPAND(double x); +template<> int BOOST_MATH_TR1_DECL fpclassify<long double> NO_MACRO_EXPAND(long double x); + +template<class T> bool isfinite NO_MACRO_EXPAND(T x) +{ BOOST_STATIC_ASSERT(sizeof(T) == 0); return false; } // must not be instantiated +template<> bool BOOST_MATH_TR1_DECL isfinite<float> NO_MACRO_EXPAND(float x); +template<> bool BOOST_MATH_TR1_DECL isfinite<double> NO_MACRO_EXPAND(double x); +template<> bool BOOST_MATH_TR1_DECL isfinite<long double> NO_MACRO_EXPAND(long double x); + +template<class T> bool isinf NO_MACRO_EXPAND(T x) +{ BOOST_STATIC_ASSERT(sizeof(T) == 0); return false; } // must not be instantiated +template<> bool BOOST_MATH_TR1_DECL isinf<float> NO_MACRO_EXPAND(float x); +template<> bool BOOST_MATH_TR1_DECL isinf<double> NO_MACRO_EXPAND(double x); +template<> bool BOOST_MATH_TR1_DECL isinf<long double> NO_MACRO_EXPAND(long double x); + +template<class T> bool isnan NO_MACRO_EXPAND(T x) +{ BOOST_STATIC_ASSERT(sizeof(T) == 0); return false; } // must not be instantiated +template<> bool BOOST_MATH_TR1_DECL isnan<float> NO_MACRO_EXPAND(float x); +template<> bool BOOST_MATH_TR1_DECL isnan<double> NO_MACRO_EXPAND(double x); +template<> bool BOOST_MATH_TR1_DECL isnan<long double> NO_MACRO_EXPAND(long double x); + +template<class T> bool isnormal NO_MACRO_EXPAND(T x) +{ BOOST_STATIC_ASSERT(sizeof(T) == 0); return false; } // must not be instantiated +template<> bool BOOST_MATH_TR1_DECL isnormal<float> NO_MACRO_EXPAND(float x); +template<> bool BOOST_MATH_TR1_DECL isnormal<double> NO_MACRO_EXPAND(double x); +template<> bool BOOST_MATH_TR1_DECL isnormal<long double> NO_MACRO_EXPAND(long double x); + +#undef NO_MACRO_EXPAND + +// [5.2.1.1] associated Laguerre polynomials: +inline float assoc_laguerre BOOST_PREVENT_MACRO_SUBSTITUTION(unsigned n, unsigned m, float x) +{ return boost::math::tr1::assoc_laguerref BOOST_PREVENT_MACRO_SUBSTITUTION(n, m, x); } +inline long double assoc_laguerre BOOST_PREVENT_MACRO_SUBSTITUTION(unsigned n, unsigned m, long double x) +{ return boost::math::tr1::assoc_laguerrel BOOST_PREVENT_MACRO_SUBSTITUTION(n, m, x); } +template <class T> +inline typename tools::promote_args<T>::type assoc_laguerre BOOST_PREVENT_MACRO_SUBSTITUTION(unsigned n, unsigned m, T x) +{ return boost::math::tr1::assoc_laguerre BOOST_PREVENT_MACRO_SUBSTITUTION(n, m, static_cast<typename tools::promote_args<T>::type>(x)); } + +// [5.2.1.2] associated Legendre functions: +inline float assoc_legendre BOOST_PREVENT_MACRO_SUBSTITUTION(unsigned l, unsigned m, float x) +{ return boost::math::tr1::assoc_legendref BOOST_PREVENT_MACRO_SUBSTITUTION(l, m, x); } +inline long double assoc_legendre BOOST_PREVENT_MACRO_SUBSTITUTION(unsigned l, unsigned m, long double x) +{ return boost::math::tr1::assoc_legendrel BOOST_PREVENT_MACRO_SUBSTITUTION(l, m, x); } +template <class T> +inline typename tools::promote_args<T>::type assoc_legendre BOOST_PREVENT_MACRO_SUBSTITUTION(unsigned l, unsigned m, T x) +{ return boost::math::tr1::assoc_legendre BOOST_PREVENT_MACRO_SUBSTITUTION(l, m, static_cast<typename tools::promote_args<T>::type>(x)); } + +// [5.2.1.3] beta function: +inline float beta BOOST_PREVENT_MACRO_SUBSTITUTION(float x, float y) +{ return boost::math::tr1::betaf BOOST_PREVENT_MACRO_SUBSTITUTION(x, y); } +inline long double beta BOOST_PREVENT_MACRO_SUBSTITUTION(long double x, long double y) +{ return boost::math::tr1::betal BOOST_PREVENT_MACRO_SUBSTITUTION(x, y); } +template <class T1, class T2> +inline typename tools::promote_args<T1, T2>::type beta BOOST_PREVENT_MACRO_SUBSTITUTION(T2 x, T1 y) +{ return boost::math::tr1::beta BOOST_PREVENT_MACRO_SUBSTITUTION(static_cast<typename tools::promote_args<T1, T2>::type>(x), static_cast<typename tools::promote_args<T1, T2>::type>(y)); } + +// [5.2.1.4] (complete) elliptic integral of the first kind: +inline float comp_ellint_1 BOOST_PREVENT_MACRO_SUBSTITUTION(float k) +{ return boost::math::tr1::comp_ellint_1f BOOST_PREVENT_MACRO_SUBSTITUTION(k); } +inline long double comp_ellint_1 BOOST_PREVENT_MACRO_SUBSTITUTION(long double k) +{ return boost::math::tr1::comp_ellint_1l BOOST_PREVENT_MACRO_SUBSTITUTION(k); } +template <class T> +inline typename tools::promote_args<T>::type comp_ellint_1 BOOST_PREVENT_MACRO_SUBSTITUTION(T k) +{ return boost::math::tr1::comp_ellint_1 BOOST_PREVENT_MACRO_SUBSTITUTION(static_cast<typename tools::promote_args<T>::type>(k)); } + +// [5.2.1.5] BOOST_PREVENT_MACRO_SUBSTITUTION(complete) elliptic integral of the second kind: +inline float comp_ellint_2(float k) +{ return boost::math::tr1::comp_ellint_2f(k); } +inline long double comp_ellint_2(long double k) +{ return boost::math::tr1::comp_ellint_2l(k); } +template <class T> +inline typename tools::promote_args<T>::type comp_ellint_2(T k) +{ return boost::math::tr1::comp_ellint_2(static_cast<typename tools::promote_args<T>::type> BOOST_PREVENT_MACRO_SUBSTITUTION(k)); } + +// [5.2.1.6] BOOST_PREVENT_MACRO_SUBSTITUTION(complete) elliptic integral of the third kind: +inline float comp_ellint_3(float k, float nu) +{ return boost::math::tr1::comp_ellint_3f(k, nu); } +inline long double comp_ellint_3(long double k, long double nu) +{ return boost::math::tr1::comp_ellint_3l(k, nu); } +template <class T1, class T2> +inline typename tools::promote_args<T1, T2>::type comp_ellint_3(T1 k, T2 nu) +{ return boost::math::tr1::comp_ellint_3(static_cast<typename tools::promote_args<T1, T2>::type> BOOST_PREVENT_MACRO_SUBSTITUTION(k), static_cast<typename tools::promote_args<T1, T2>::type> BOOST_PREVENT_MACRO_SUBSTITUTION(nu)); } + +#if 0 +// [5.2.1.7] confluent hypergeometric functions: +double conf_hyperg BOOST_PREVENT_MACRO_SUBSTITUTION(double a, double c, double x); +float conf_hypergf BOOST_PREVENT_MACRO_SUBSTITUTION(float a, float c, float x); +long double conf_hypergl BOOST_PREVENT_MACRO_SUBSTITUTION(long double a, long double c, long double x); +#endif + +// [5.2.1.8] regular modified cylindrical Bessel functions: +inline float cyl_bessel_i BOOST_PREVENT_MACRO_SUBSTITUTION(float nu, float x) +{ return boost::math::tr1::cyl_bessel_if BOOST_PREVENT_MACRO_SUBSTITUTION(nu, x); } +inline long double cyl_bessel_i BOOST_PREVENT_MACRO_SUBSTITUTION(long double nu, long double x) +{ return boost::math::tr1::cyl_bessel_il BOOST_PREVENT_MACRO_SUBSTITUTION(nu, x); } +template <class T1, class T2> +inline typename tools::promote_args<T1, T2>::type cyl_bessel_i BOOST_PREVENT_MACRO_SUBSTITUTION(T1 nu, T2 x) +{ return boost::math::tr1::cyl_bessel_i BOOST_PREVENT_MACRO_SUBSTITUTION(static_cast<typename tools::promote_args<T1, T2>::type>(nu), static_cast<typename tools::promote_args<T1, T2>::type>(x)); } + +// [5.2.1.9] cylindrical Bessel functions (of the first kind): +inline float cyl_bessel_j BOOST_PREVENT_MACRO_SUBSTITUTION(float nu, float x) +{ return boost::math::tr1::cyl_bessel_jf BOOST_PREVENT_MACRO_SUBSTITUTION(nu, x); } +inline long double cyl_bessel_j BOOST_PREVENT_MACRO_SUBSTITUTION(long double nu, long double x) +{ return boost::math::tr1::cyl_bessel_jl BOOST_PREVENT_MACRO_SUBSTITUTION(nu, x); } +template <class T1, class T2> +inline typename tools::promote_args<T1, T2>::type cyl_bessel_j BOOST_PREVENT_MACRO_SUBSTITUTION(T1 nu, T2 x) +{ return boost::math::tr1::cyl_bessel_j BOOST_PREVENT_MACRO_SUBSTITUTION(static_cast<typename tools::promote_args<T1, T2>::type>(nu), static_cast<typename tools::promote_args<T1, T2>::type>(x)); } + +// [5.2.1.10] irregular modified cylindrical Bessel functions: +inline float cyl_bessel_k BOOST_PREVENT_MACRO_SUBSTITUTION(float nu, float x) +{ return boost::math::tr1::cyl_bessel_kf BOOST_PREVENT_MACRO_SUBSTITUTION(nu, x); } +inline long double cyl_bessel_k BOOST_PREVENT_MACRO_SUBSTITUTION(long double nu, long double x) +{ return boost::math::tr1::cyl_bessel_kl BOOST_PREVENT_MACRO_SUBSTITUTION(nu, x); } +template <class T1, class T2> +inline typename tools::promote_args<T1, T2>::type cyl_bessel_k BOOST_PREVENT_MACRO_SUBSTITUTION(T1 nu, T2 x) +{ return boost::math::tr1::cyl_bessel_k BOOST_PREVENT_MACRO_SUBSTITUTION(static_cast<typename tools::promote_args<T1, T2>::type> BOOST_PREVENT_MACRO_SUBSTITUTION(nu), static_cast<typename tools::promote_args<T1, T2>::type>(x)); } + +// [5.2.1.11] cylindrical Neumann functions; +// cylindrical Bessel functions (of the second kind): +inline float cyl_neumann BOOST_PREVENT_MACRO_SUBSTITUTION(float nu, float x) +{ return boost::math::tr1::cyl_neumannf BOOST_PREVENT_MACRO_SUBSTITUTION(nu, x); } +inline long double cyl_neumann BOOST_PREVENT_MACRO_SUBSTITUTION(long double nu, long double x) +{ return boost::math::tr1::cyl_neumannl BOOST_PREVENT_MACRO_SUBSTITUTION(nu, x); } +template <class T1, class T2> +inline typename tools::promote_args<T1, T2>::type cyl_neumann BOOST_PREVENT_MACRO_SUBSTITUTION(T1 nu, T2 x) +{ return boost::math::tr1::cyl_neumann BOOST_PREVENT_MACRO_SUBSTITUTION(static_cast<typename tools::promote_args<T1, T2>::type>(nu), static_cast<typename tools::promote_args<T1, T2>::type>(x)); } + +// [5.2.1.12] (incomplete) elliptic integral of the first kind: +inline float ellint_1 BOOST_PREVENT_MACRO_SUBSTITUTION(float k, float phi) +{ return boost::math::tr1::ellint_1f BOOST_PREVENT_MACRO_SUBSTITUTION(k, phi); } +inline long double ellint_1 BOOST_PREVENT_MACRO_SUBSTITUTION(long double k, long double phi) +{ return boost::math::tr1::ellint_1l BOOST_PREVENT_MACRO_SUBSTITUTION(k, phi); } +template <class T1, class T2> +inline typename tools::promote_args<T1, T2>::type ellint_1 BOOST_PREVENT_MACRO_SUBSTITUTION(T1 k, T2 phi) +{ return boost::math::tr1::ellint_1 BOOST_PREVENT_MACRO_SUBSTITUTION(static_cast<typename tools::promote_args<T1, T2>::type>(k), static_cast<typename tools::promote_args<T1, T2>::type>(phi)); } + +// [5.2.1.13] (incomplete) elliptic integral of the second kind: +inline float ellint_2 BOOST_PREVENT_MACRO_SUBSTITUTION(float k, float phi) +{ return boost::math::tr1::ellint_2f BOOST_PREVENT_MACRO_SUBSTITUTION(k, phi); } +inline long double ellint_2 BOOST_PREVENT_MACRO_SUBSTITUTION(long double k, long double phi) +{ return boost::math::tr1::ellint_2l BOOST_PREVENT_MACRO_SUBSTITUTION(k, phi); } +template <class T1, class T2> +inline typename tools::promote_args<T1, T2>::type ellint_2 BOOST_PREVENT_MACRO_SUBSTITUTION(T1 k, T2 phi) +{ return boost::math::tr1::ellint_2 BOOST_PREVENT_MACRO_SUBSTITUTION(static_cast<typename tools::promote_args<T1, T2>::type>(k), static_cast<typename tools::promote_args<T1, T2>::type>(phi)); } + +// [5.2.1.14] (incomplete) elliptic integral of the third kind: +inline float ellint_3 BOOST_PREVENT_MACRO_SUBSTITUTION(float k, float nu, float phi) +{ return boost::math::tr1::ellint_3f BOOST_PREVENT_MACRO_SUBSTITUTION(k, nu, phi); } +inline long double ellint_3 BOOST_PREVENT_MACRO_SUBSTITUTION(long double k, long double nu, long double phi) +{ return boost::math::tr1::ellint_3l BOOST_PREVENT_MACRO_SUBSTITUTION(k, nu, phi); } +template <class T1, class T2, class T3> +inline typename tools::promote_args<T1, T2, T3>::type ellint_3 BOOST_PREVENT_MACRO_SUBSTITUTION(T1 k, T2 nu, T3 phi) +{ return boost::math::tr1::ellint_3 BOOST_PREVENT_MACRO_SUBSTITUTION(static_cast<typename tools::promote_args<T1, T2, T3>::type>(k), static_cast<typename tools::promote_args<T1, T2, T3>::type>(nu), static_cast<typename tools::promote_args<T1, T2, T3>::type>(phi)); } + +// [5.2.1.15] exponential integral: +inline float expint BOOST_PREVENT_MACRO_SUBSTITUTION(float x) +{ return boost::math::tr1::expintf BOOST_PREVENT_MACRO_SUBSTITUTION(x); } +inline long double expint BOOST_PREVENT_MACRO_SUBSTITUTION(long double x) +{ return boost::math::tr1::expintl BOOST_PREVENT_MACRO_SUBSTITUTION(x); } +template <class T> +inline typename tools::promote_args<T>::type expint BOOST_PREVENT_MACRO_SUBSTITUTION(T x) +{ return boost::math::tr1::expint BOOST_PREVENT_MACRO_SUBSTITUTION(static_cast<typename tools::promote_args<T>::type>(x)); } + +// [5.2.1.16] Hermite polynomials: +inline float hermite BOOST_PREVENT_MACRO_SUBSTITUTION(unsigned n, float x) +{ return boost::math::tr1::hermitef BOOST_PREVENT_MACRO_SUBSTITUTION(n, x); } +inline long double hermite BOOST_PREVENT_MACRO_SUBSTITUTION(unsigned n, long double x) +{ return boost::math::tr1::hermitel BOOST_PREVENT_MACRO_SUBSTITUTION(n, x); } +template <class T> +inline typename tools::promote_args<T>::type hermite BOOST_PREVENT_MACRO_SUBSTITUTION(unsigned n, T x) +{ return boost::math::tr1::hermite BOOST_PREVENT_MACRO_SUBSTITUTION(n, static_cast<typename tools::promote_args<T>::type>(x)); } + +#if 0 +// [5.2.1.17] hypergeometric functions: +double hyperg BOOST_PREVENT_MACRO_SUBSTITUTION(double a, double b, double c, double x); +float hypergf BOOST_PREVENT_MACRO_SUBSTITUTION(float a, float b, float c, float x); +long double hypergl BOOST_PREVENT_MACRO_SUBSTITUTION(long double a, long double b, long double c, +long double x); +#endif + +// [5.2.1.18] Laguerre polynomials: +inline float laguerre BOOST_PREVENT_MACRO_SUBSTITUTION(unsigned n, float x) +{ return boost::math::tr1::laguerref BOOST_PREVENT_MACRO_SUBSTITUTION(n, x); } +inline long double laguerre BOOST_PREVENT_MACRO_SUBSTITUTION(unsigned n, long double x) +{ return boost::math::tr1::laguerrel BOOST_PREVENT_MACRO_SUBSTITUTION(n, x); } +template <class T> +inline typename tools::promote_args<T>::type laguerre BOOST_PREVENT_MACRO_SUBSTITUTION(unsigned n, T x) +{ return boost::math::tr1::laguerre BOOST_PREVENT_MACRO_SUBSTITUTION(n, static_cast<typename tools::promote_args<T>::type>(x)); } + +// [5.2.1.19] Legendre polynomials: +inline float legendre BOOST_PREVENT_MACRO_SUBSTITUTION(unsigned l, float x) +{ return boost::math::tr1::legendref BOOST_PREVENT_MACRO_SUBSTITUTION(l, x); } +inline long double legendre BOOST_PREVENT_MACRO_SUBSTITUTION(unsigned l, long double x) +{ return boost::math::tr1::legendrel BOOST_PREVENT_MACRO_SUBSTITUTION(l, x); } +template <class T> +inline typename tools::promote_args<T>::type legendre BOOST_PREVENT_MACRO_SUBSTITUTION(unsigned l, T x) +{ return boost::math::tr1::legendre BOOST_PREVENT_MACRO_SUBSTITUTION(l, static_cast<typename tools::promote_args<T>::type>(x)); } + +// [5.2.1.20] Riemann zeta function: +inline float riemann_zeta BOOST_PREVENT_MACRO_SUBSTITUTION(float z) +{ return boost::math::tr1::riemann_zetaf BOOST_PREVENT_MACRO_SUBSTITUTION(z); } +inline long double riemann_zeta BOOST_PREVENT_MACRO_SUBSTITUTION(long double z) +{ return boost::math::tr1::riemann_zetal BOOST_PREVENT_MACRO_SUBSTITUTION(z); } +template <class T> +inline typename tools::promote_args<T>::type riemann_zeta BOOST_PREVENT_MACRO_SUBSTITUTION(T z) +{ return boost::math::tr1::riemann_zeta BOOST_PREVENT_MACRO_SUBSTITUTION(static_cast<typename tools::promote_args<T>::type>(z)); } + +// [5.2.1.21] spherical Bessel functions (of the first kind): +inline float sph_bessel BOOST_PREVENT_MACRO_SUBSTITUTION(unsigned n, float x) +{ return boost::math::tr1::sph_besself BOOST_PREVENT_MACRO_SUBSTITUTION(n, x); } +inline long double sph_bessel BOOST_PREVENT_MACRO_SUBSTITUTION(unsigned n, long double x) +{ return boost::math::tr1::sph_bessell BOOST_PREVENT_MACRO_SUBSTITUTION(n, x); } +template <class T> +inline typename tools::promote_args<T>::type sph_bessel BOOST_PREVENT_MACRO_SUBSTITUTION(unsigned n, T x) +{ return boost::math::tr1::sph_bessel BOOST_PREVENT_MACRO_SUBSTITUTION(n, static_cast<typename tools::promote_args<T>::type>(x)); } + +// [5.2.1.22] spherical associated Legendre functions: +inline float sph_legendre BOOST_PREVENT_MACRO_SUBSTITUTION(unsigned l, unsigned m, float theta) +{ return boost::math::tr1::sph_legendref BOOST_PREVENT_MACRO_SUBSTITUTION(l, m, theta); } +inline long double sph_legendre BOOST_PREVENT_MACRO_SUBSTITUTION(unsigned l, unsigned m, long double theta) +{ return boost::math::tr1::sph_legendrel BOOST_PREVENT_MACRO_SUBSTITUTION(l, m, theta); } +template <class T> +inline typename tools::promote_args<T>::type sph_legendre BOOST_PREVENT_MACRO_SUBSTITUTION(unsigned l, unsigned m, T theta) +{ return boost::math::tr1::sph_legendre BOOST_PREVENT_MACRO_SUBSTITUTION(l, m, static_cast<typename tools::promote_args<T>::type>(theta)); } + +// [5.2.1.23] spherical Neumann functions; +// spherical Bessel functions (of the second kind): +inline float sph_neumann BOOST_PREVENT_MACRO_SUBSTITUTION(unsigned n, float x) +{ return boost::math::tr1::sph_neumannf BOOST_PREVENT_MACRO_SUBSTITUTION(n, x); } +inline long double sph_neumann BOOST_PREVENT_MACRO_SUBSTITUTION(unsigned n, long double x) +{ return boost::math::tr1::sph_neumannl BOOST_PREVENT_MACRO_SUBSTITUTION(n, x); } +template <class T> +inline typename tools::promote_args<T>::type sph_neumann BOOST_PREVENT_MACRO_SUBSTITUTION(unsigned n, T x) +{ return boost::math::tr1::sph_neumann BOOST_PREVENT_MACRO_SUBSTITUTION(n, static_cast<typename tools::promote_args<T>::type>(x)); } + +}}} // namespaces + +#endif // __cplusplus + +#endif // BOOST_MATH_TR1_HPP +