concepts.qbk 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. [section:high_precision Using Boost.Math with High-Precision Floating-Point Libraries]
  2. The special functions, distributions, constants and tools in this library
  3. can be used with a number of high-precision libraries, including:
  4. * __multiprecision
  5. * __e_float
  6. * __NTL
  7. * __GMP
  8. * __MPFR
  9. * __gcc_quad_type
  10. * Intel _Quad type
  11. The last four have some license restrictions;
  12. only __multiprecision when using the `cpp_float` backend
  13. can provide an unrestricted [@http://www.boost.org/LICENSE_1_0.txt Boost] license.
  14. At present, the price of a free license is slightly lower speed.
  15. Of course, the main cost of higher precision is very much decreased
  16. (usually at least hundred-fold) computation speed, and big increases in memory use.
  17. Some libraries offer true
  18. [@http://en.wikipedia.org/wiki/Arbitrary-precision_arithmetic arbitrary-precision arithmetic]
  19. where the precision is limited only by available memory and compute time, but most are used
  20. at some arbitrarily-fixed precision, say 100 decimal digits, like __multiprecision `cpp_dec_float_100`.
  21. __multiprecision can operate in both ways, but the most popular choice is likely to be about a hundred
  22. decimal digits, though examples of computing about a million digits have been demonstrated.
  23. [section:why_high_precision Why use a high-precision library rather than built-in floating-point types?]
  24. For nearly all applications, the built-in floating-point types, `double`
  25. (and `long double` if this offers higher precision than `double`)
  26. offer enough precision, typically a dozen decimal digits.
  27. Some reasons why one would want to use a higher precision:
  28. * A much more precise result (many more digits) is just a requirement.
  29. * The range of the computed value exceeds the range of the type: factorials are the textbook example.
  30. * Using `double` is (or may be) too inaccurate.
  31. * Using `long double` (or may be) is too inaccurate.
  32. * Using an extended-precision type implemented in software as
  33. [@http://en.wikipedia.org/wiki/Double-double_(arithmetic)#Double-double_arithmetic double-double]
  34. ([@http://en.wikipedia.org/wiki/Darwin_(operating_system) Darwin]) is sometimes unpredictably inaccurate.
  35. * Loss of precision or inaccuracy caused by extreme arguments or
  36. [@http://en.wikipedia.org/wiki/Loss_of_significance cancellation errors].
  37. * An accuracy as good as possible for a chosen built-in floating-point type is required.
  38. * As a reference value, for example, to determine the inaccuracy
  39. of a value computed with a built-in floating point type,
  40. (perhaps even using some quick'n'dirty algorithm).
  41. The accuracy of many functions and distributions in Boost.Math has been measured in this way
  42. from tables of very high precision (up to 1000 decimal digits).
  43. Many functions and distributions have differences from exact values
  44. that are only a few least significant bits - computation noise.
  45. Others, often those for which analytical solutions are not available,
  46. require approximations and iteration:
  47. these may lose several decimal digits of precision.
  48. Much larger loss of precision can occur for [@http://en.wikipedia.org/wiki/Boundary_case boundary]
  49. or [@http://en.wikipedia.org/wiki/Corner_case corner cases],
  50. often caused by [@http://en.wikipedia.org/wiki/Loss_of_significance cancellation errors].
  51. (Some of the worst and most common examples of
  52. [@http://en.wikipedia.org/wiki/Loss_of_significance cancellation error or loss of significance]
  53. can be avoided by using __complements: see __why_complements).
  54. If you require a value which is as accurate as can be represented in the floating-point type,
  55. and is thus the
  56. [@https://en.wikipedia.org/wiki/Floating-point_arithmetic#Representable_numbers,_conversion_and_rounding closest representable value]
  57. correctly rounded to nearest,
  58. and has an error less than 1/2 a
  59. [@http://en.wikipedia.org/wiki/Least_significant_bit least significant bit] or
  60. [@http://en.wikipedia.org/wiki/Unit_in_the_last_place ulp]
  61. it may be useful to use a higher-precision type,
  62. for example, `cpp_dec_float_50`, to generate this value.
  63. Conversion of this value to a built-in floating-point type ('float', `double` or `long double`)
  64. will not cause any further loss of precision.
  65. A decimal digit string will also be 'read' precisely by the compiler
  66. into a built-in floating-point type to the nearest representable value.
  67. [note In contrast, reading a value from an `std::istream` into a built-in floating-point type
  68. is [*not guaranteed by the C++ Standard] to give the nearest representable value.]
  69. William Kahan coined the term
  70. [@http://en.wikipedia.org/wiki/Rounding#The_table-maker.27s_dilemma Table-Maker's Dilemma]
  71. for the problem of correctly rounding functions.
  72. Using a much higher precision (50 or 100 decimal digits)
  73. is a practical way of generating (almost always) correctly rounded values.
  74. [endsect] [/section:why_high_precision Why use a high-precision library rather than built-in floating-point types?]
  75. [section:use_multiprecision Using Boost.Multiprecision]
  76. [*All new projects are recommended to use __multiprecision.]
  77. [import ../../example/big_seventh.cpp]
  78. [big_seventh_example_1]
  79. [big_seventh_example_2]
  80. The full source of this example is at [@../../example/big_seventh.cpp big_seventh.cpp]
  81. [import ../../example/fft_sines_table.cpp]
  82. [fft_sines_table_example_1]
  83. [fft_sines_table_example_2]
  84. [fft_sines_table_example_3
  85. ]
  86. The table output is:
  87. [fft_sines_table_example_output]
  88. [fft_sines_table_example_check]
  89. The full source of this example is at [@../../example/fft_sines_table.cpp fft_sines_table.cpp]
  90. [/TODO another example needed here]
  91. [/import ../../example/ibeta_mp_example.cpp]
  92. [/ibeta_mp_example_1]
  93. [/The program output is:]
  94. [/ibeta_mp_output_1]
  95. [endsect] [/section:use_multiprecision Using Boost.Multiprecision]
  96. [section:float128 Using with GCC's __float128 datatype]
  97. At present support for GCC's native `__float128` datatype is extremely limited: the numeric constants
  98. will all work with that type, and that's about it. If you want to use the distributions or special
  99. functions then you will need to provide your own wrapper header that:
  100. * Provides `std::numeric_limits<__float128>` support.
  101. * Provides overloads of the standard library math functions for type `__float128`
  102. and which forward to the libquadmath equivalents.
  103. Ultimately these facilities should be provided by GCC and `libstdc++`.
  104. [endsect] [/section:float128 Using with GCC's __float128 datatype]
  105. [section:use_mpfr Using With MPFR or GMP - High-Precision Floating-Point Library]
  106. The special functions and tools in this library can be used with
  107. [@http://www.mpfr.org MPFR] (an arbitrary precision number type based on the __GMP),
  108. either via the bindings in [@../../../../boost/math/bindings/mpfr.hpp boost/math/bindings/mpfr.hpp],
  109. or via [@../../../../boost/math/bindings/mpfr.hpp boost/math/bindings/mpreal.hpp].
  110. [*New projects are recommended to use __multiprecision with GMP/MPFR backend instead.]
  111. In order to use these bindings you will need to have installed [@http://www.mpfr.org MPFR]
  112. plus its dependency the [@http://gmplib.org GMP library]. You will also need one of the
  113. two supported C++ wrappers for MPFR:
  114. [@http://math.berkeley.edu/~wilken/code/gmpfrxx/ gmpfrxx (or mpfr_class)],
  115. or [@http://www.holoborodko.com/pavel/mpfr/ mpfr-C++ (mpreal)].
  116. Unfortunately neither `mpfr_class` nor `mpreal` quite satisfy our conceptual requirements,
  117. so there is a very thin set of additional interfaces and some helper traits defined in
  118. [@../../../../boost/math/bindings/mpfr.hpp boost/math/bindings/mpfr.hpp] and
  119. [@../../../../boost/math/bindings/mpreal.hpp boost/math/bindings/mpreal.hpp]
  120. that you should use in place of including 'gmpfrxx.h' or 'mpreal.h' directly.
  121. The classes `mpfr_class` or `mpreal` are
  122. then usable unchanged once this header is included, so for example `mpfr_class`'s
  123. performance-enhancing expression templates are preserved and fully supported by this library:
  124. #include <boost/math/bindings/mpfr.hpp>
  125. #include <boost/math/special_functions/gamma.hpp>
  126. int main()
  127. {
  128. mpfr_class::set_dprec(500); // 500 bit precision
  129. //
  130. // Note that the argument to tgamma is
  131. // an expression template - that's just fine here.
  132. //
  133. mpfr_class v = boost::math::tgamma(sqrt(mpfr_class(2)));
  134. std::cout << std::setprecision(50) << v << std::endl;
  135. }
  136. Alternatively use with `mpreal` would look like:
  137. #include <boost/math/bindings/mpreal.hpp>
  138. #include <boost/math/special_functions/gamma.hpp>
  139. int main()
  140. {
  141. mpfr::mpreal::set_precision(500); // 500 bit precision
  142. mpfr::mpreal v = boost::math::tgamma(sqrt(mpfr::mpreal(2)));
  143. std::cout << std::setprecision(50) << v << std::endl;
  144. }
  145. There is a concept checking test program for mpfr support
  146. [@../../../../libs/math/test/mpfr_concept_check.cpp here] and
  147. [@../../../../libs/math/test/mpreal_concept_check.cpp here].
  148. [endsect] [/section:use_mpfr Using With MPFR / GMP - a High-Precision Floating-Point Library]
  149. [section:e_float Using e_float Library]
  150. __multiprecision was a development from the __e_float library by Christopher Kormanyos.
  151. e_float can still be used with Boost.Math library via the header:
  152. <boost/math/bindings/e_float.hpp>
  153. And the type `boost::math::ef::e_float`:
  154. this type is a thin wrapper class around ::e_float which provides the necessary
  155. syntactic sugar to make everything "just work".
  156. There is also a concept checking test program for e_float support
  157. [@../../../../libs/math/test/e_float_concept_check.cpp here].
  158. [*New projects are recommended to use __multiprecision with `cpp_float` backend instead.]
  159. [endsect] [/section:e_float Using e_float Library]
  160. [section:use_ntl Using NTL Library]
  161. [@http://shoup.net/ntl/doc/RR.txt NTL::RR]
  162. (an arbitrarily-fixed precision floating-point number type),
  163. can be used via the bindings in
  164. [@../../../../boost/math/bindings/rr.hpp boost/math/bindings/rr.hpp].
  165. For details, see [@http://shoup.net/ntl/ NTL: A Library for doing Number Theory by
  166. Victor Shoup].
  167. [*New projects are recommended to use __multiprecision instead.]
  168. Unfortunately `NTL::RR` doesn't quite satisfy our conceptual requirements,
  169. so there is a very thin wrapper class `boost::math::ntl::RR` defined in
  170. [@../../../../boost/math/bindings/rr.hpp boost/math/bindings/rr.hpp] that you
  171. should use in place of `NTL::RR`. The class is intended to be a drop-in
  172. replacement for the "real" NTL::RR that adds some syntactic sugar to keep
  173. this library happy, plus some of the standard library functions not implemented
  174. in NTL.
  175. For those functions that are based upon the __lanczos, the bindings
  176. defines a series of approximations with up to 61 terms and accuracy
  177. up to approximately 3e-113. This therefore sets the upper limit for accuracy
  178. to the majority of functions defined this library when used with `NTL::RR`.
  179. There is a concept checking test program for NTL support
  180. [@../../../../libs/math/test/ntl_concept_check.cpp here].
  181. [endsect] [/section:use_ntl Using With NTL - a High-Precision Floating-Point Library]
  182. [section:using_test Using without expression templates for Boost.Test and others]
  183. As noted in the __multiprecision documentation, certain program constructs will not compile
  184. when using expression templates. One example that many users may encounter
  185. is Boost.Test (1.54 and earlier) when using macro BOOST_CHECK_CLOSE and BOOST_CHECK_CLOSE_FRACTION.
  186. If, for example, you wish to use any multiprecision type like `cpp_dec_float_50`
  187. in place of `double` to give more precision,
  188. you will need to override the default `boost::multiprecision::et_on` with
  189. `boost::multiprecision::et_off`.
  190. [import ../../example/test_cpp_float_close_fraction.cpp]
  191. [expression_template_1]
  192. A full example code is at [@../../example/test_cpp_float_close_fraction.cpp test_cpp_float_close_fraction.cpp]
  193. [endsect] [/section:using_test Using without expression templates for Boost.Test and others]
  194. [endsect] [/section:high_precision Using With High-Precision Floating-Point Libraries]
  195. [section:real_concepts Conceptual Requirements for Real Number Types]
  196. The functions and statistical distributions in this library can be used with
  197. any type ['RealType] that meets the conceptual requirements given below. All
  198. the built-in floating-point types like `double` will meet these requirements.
  199. (Built-in types are also called __fundamental_types).
  200. User-defined types that meet the conceptual requirements can also be used.
  201. For example, with [link math_toolkit.high_precision.use_ntl a thin wrapper class]
  202. one of the types provided with [@http://shoup.net/ntl/ NTL (RR)] can be used.
  203. But now that __multiprecision library is available,
  204. this has become the preferred real-number type,
  205. typically __cpp_dec_float or __cpp_bin_float.
  206. Submissions of binding to other extended precision types would also still be welcome.
  207. The guiding principal behind these requirements is that a ['RealType]
  208. behaves just like a built-in floating-point type.
  209. [h4 Basic Arithmetic Requirements]
  210. These requirements are common to all of the functions in this library.
  211. In the following table /r/ is an object of type `RealType`, /cr/ and
  212. /cr2/ are objects
  213. of type `const RealType`, and /ca/ is an object of type `const arithmetic-type`
  214. (arithmetic types include all the built in integers and floating point types).
  215. [table
  216. [[Expression][Result Type][Notes]]
  217. [[`RealType(cr)`][RealType]
  218. [RealType is copy constructible.]]
  219. [[`RealType(ca)`][RealType]
  220. [RealType is copy constructible from the arithmetic types.]]
  221. [[`r = cr`][RealType&][Assignment operator.]]
  222. [[`r = ca`][RealType&][Assignment operator from the arithmetic types.]]
  223. [[`r += cr`][RealType&][Adds cr to r.]]
  224. [[`r += ca`][RealType&][Adds ar to r.]]
  225. [[`r -= cr`][RealType&][Subtracts cr from r.]]
  226. [[`r -= ca`][RealType&][Subtracts ca from r.]]
  227. [[`r *= cr`][RealType&][Multiplies r by cr.]]
  228. [[`r *= ca`][RealType&][Multiplies r by ca.]]
  229. [[`r /= cr`][RealType&][Divides r by cr.]]
  230. [[`r /= ca`][RealType&][Divides r by ca.]]
  231. [[`-r`][RealType][Unary Negation.]]
  232. [[`+r`][RealType&][Identity Operation.]]
  233. [[`cr + cr2`][RealType][Binary Addition]]
  234. [[`cr + ca`][RealType][Binary Addition]]
  235. [[`ca + cr`][RealType][Binary Addition]]
  236. [[`cr - cr2`][RealType][Binary Subtraction]]
  237. [[`cr - ca`][RealType][Binary Subtraction]]
  238. [[`ca - cr`][RealType][Binary Subtraction]]
  239. [[`cr * cr2`][RealType][Binary Multiplication]]
  240. [[`cr * ca`][RealType][Binary Multiplication]]
  241. [[`ca * cr`][RealType][Binary Multiplication]]
  242. [[`cr / cr2`][RealType][Binary Subtraction]]
  243. [[`cr / ca`][RealType][Binary Subtraction]]
  244. [[`ca / cr`][RealType][Binary Subtraction]]
  245. [[`cr == cr2`][bool][Equality Comparison]]
  246. [[`cr == ca`][bool][Equality Comparison]]
  247. [[`ca == cr`][bool][Equality Comparison]]
  248. [[`cr != cr2`][bool][Inequality Comparison]]
  249. [[`cr != ca`][bool][Inequality Comparison]]
  250. [[`ca != cr`][bool][Inequality Comparison]]
  251. [[`cr <= cr2`][bool][Less than equal to.]]
  252. [[`cr <= ca`][bool][Less than equal to.]]
  253. [[`ca <= cr`][bool][Less than equal to.]]
  254. [[`cr >= cr2`][bool][Greater than equal to.]]
  255. [[`cr >= ca`][bool][Greater than equal to.]]
  256. [[`ca >= cr`][bool][Greater than equal to.]]
  257. [[`cr < cr2`][bool][Less than comparison.]]
  258. [[`cr < ca`][bool][Less than comparison.]]
  259. [[`ca < cr`][bool][Less than comparison.]]
  260. [[`cr > cr2`][bool][Greater than comparison.]]
  261. [[`cr > ca`][bool][Greater than comparison.]]
  262. [[`ca > cr`][bool][Greater than comparison.]]
  263. [[`boost::math::tools::digits<RealType>()`][int]
  264. [The number of digits in the significand of RealType.]]
  265. [[`boost::math::tools::max_value<RealType>()`][RealType]
  266. [The largest representable number by type RealType.]]
  267. [[`boost::math::tools::min_value<RealType>()`][RealType]
  268. [The smallest representable number by type RealType.]]
  269. [[`boost::math::tools::log_max_value<RealType>()`][RealType]
  270. [The natural logarithm of the largest representable number by type RealType.]]
  271. [[`boost::math::tools::log_min_value<RealType>()`][RealType]
  272. [The natural logarithm of the smallest representable number by type RealType.]]
  273. [[`boost::math::tools::epsilon<RealType>()`][RealType]
  274. [The machine epsilon of RealType.]]
  275. ]
  276. Note that:
  277. # The functions `log_max_value` and `log_min_value` can be
  278. synthesised from the others, and so no explicit specialisation is required.
  279. # The function `epsilon` can be synthesised from the others, so no
  280. explicit specialisation is required provided the precision
  281. of RealType does not vary at runtime (see the header
  282. [@../../../../boost/math/bindings/rr.hpp boost/math/bindings/rr.hpp]
  283. for an example where the precision does vary at runtime).
  284. # The functions `digits`, `max_value` and `min_value`, all get synthesised
  285. automatically from `std::numeric_limits`. However, if `numeric_limits`
  286. is not specialised for type RealType, then you will get a compiler error
  287. when code tries to use these functions, /unless/ you explicitly specialise them.
  288. For example if the precision of RealType varies at runtime, then
  289. `numeric_limits` support may not be appropriate, see
  290. [@../../../../boost/math/bindings/rr.hpp boost/math/bindings/rr.hpp] for examples.
  291. [warning
  292. If `std::numeric_limits<>` is *not specialized*
  293. for type /RealType/ then the default float precision of 6 decimal digits
  294. will be used by other Boost programs including:
  295. Boost.Test: giving misleading error messages like
  296. ['"difference between {9.79796} and {9.79796} exceeds 5.42101e-19%".]
  297. Boost.LexicalCast and Boost.Serialization when converting the number
  298. to a string, causing potentially serious loss of accuracy on output.
  299. Although it might seem obvious that RealType should require `std::numeric_limits`
  300. to be specialized, this is not sensible for
  301. `NTL::RR` and similar classes where the [*number of digits is a runtime parameter]
  302. (whereas for `numeric_limits` everything has to be fixed at compile time).
  303. ]
  304. [h4 Standard Library Support Requirements]
  305. Many (though not all) of the functions in this library make calls
  306. to standard library functions, the following table summarises the
  307. requirements. Note that most of the functions in this library
  308. will only call a small subset of the functions listed here, so if in
  309. doubt whether a user-defined type has enough standard library
  310. support to be useable the best advise is to try it and see!
  311. In the following table /r/ is an object of type `RealType`,
  312. /cr1/ and /cr2/ are objects of type `const RealType`, and
  313. /i/ is an object of type `int`.
  314. [table
  315. [[Expression][Result Type]]
  316. [[`fabs(cr1)`][RealType]]
  317. [[`abs(cr1)`][RealType]]
  318. [[`ceil(cr1)`][RealType]]
  319. [[`floor(cr1)`][RealType]]
  320. [[`exp(cr1)`][RealType]]
  321. [[`pow(cr1, cr2)`][RealType]]
  322. [[`sqrt(cr1)`][RealType]]
  323. [[`log(cr1)`][RealType]]
  324. [[`frexp(cr1, &i)`][RealType]]
  325. [[`ldexp(cr1, i)`][RealType]]
  326. [[`cos(cr1)`][RealType]]
  327. [[`sin(cr1)`][RealType]]
  328. [[`asin(cr1)`][RealType]]
  329. [[`tan(cr1)`][RealType]]
  330. [[`atan(cr1)`][RealType]]
  331. [[`fmod(cr1)`][RealType]]
  332. [[`round(cr1)`][RealType]]
  333. [[`iround(cr1)`][int]]
  334. [[`trunc(cr1)`][RealType]]
  335. [[`itrunc(cr1)`][int]]
  336. ]
  337. Note that the table above lists only those standard library functions known to
  338. be used (or likely to be used in the near future) by this library.
  339. The following functions: `acos`, `atan2`, `fmod`, `cosh`, `sinh`, `tanh`, `log10`,
  340. `lround`, `llround`, `ltrunc`, `lltrunc` and `modf`
  341. are not currently used, but may be if further special functions are added.
  342. Note that the `round`, `trunc` and `modf` functions are not part of the
  343. current C++ standard: they are part of the additions added to C99 which will
  344. likely be in the next C++ standard. There are Boost versions of these provided
  345. as a backup, and the functions are always called unqualified so that
  346. argument-dependent-lookup can take place.
  347. In addition, for efficient and accurate results, a __lanczos is highly desirable.
  348. You may be able to adapt an existing approximation from
  349. [@../../../../boost/math/special_functions/lanczos.hpp
  350. boost/math/special_functions/lanczos.hpp] or
  351. [@../../../../boost/math/bindings/detail/big_lanczos.hpp
  352. boost/math/bindings/detail/big_lanczos.hpp]:
  353. in the former case you will need change
  354. `static_cast`'s to `lexical_cast`'s, and the constants to /strings/
  355. (in order to ensure the coefficients aren't truncated to `long doubl`e)
  356. and then specialise `lanczos_traits` for type T. Otherwise you may have to hack
  357. [@../../tools/lanczos_generator.cpp
  358. libs/math/tools/lanczos_generator.cpp] to find a suitable
  359. approximation for your RealType. The code will still compile if you don't do
  360. this, but both accuracy and efficiency will be somewhat compromised in any
  361. function that makes use of the gamma\/beta\/erf family of functions.
  362. [endsect] [/section:real_concepts Conceptual Requirements for Real Number Types]
  363. [section:dist_concept Conceptual Requirements for Distribution Types]
  364. A ['DistributionType] is a type that implements the following conceptual
  365. requirements, and encapsulates a statistical distribution.
  366. Please note that this documentation should not be used as a substitute
  367. for the
  368. [link math_toolkit.dist_ref reference documentation], and
  369. [link math_toolkit.stat_tut tutorial] of the statistical
  370. distributions.
  371. In the following table, ['d] is an object of type `DistributionType`,
  372. ['cd] is an object of type `const DistributionType` and ['cr] is an
  373. object of a type convertible to `RealType`.
  374. [table
  375. [[Expression][Result Type][Notes]]
  376. [[DistributionType::value_type][RealType]
  377. [The real-number type /RealType/ upon which the distribution operates.]]
  378. [[DistributionType::policy_type][RealType]
  379. [The __Policy to use when evaluating functions that depend on this distribution.]]
  380. [[d = cd][Distribution&][Distribution types are assignable.]]
  381. [[Distribution(cd)][Distribution][Distribution types are copy constructible.]]
  382. [[pdf(cd, cr)][RealType][Returns the PDF of the distribution.]]
  383. [[cdf(cd, cr)][RealType][Returns the CDF of the distribution.]]
  384. [[cdf(complement(cd, cr))][RealType]
  385. [Returns the complement of the CDF of the distribution,
  386. the same as: `1-cdf(cd, cr)`]]
  387. [[quantile(cd, cr)][RealType][Returns the quantile (or percentile) of the distribution.]]
  388. [[quantile(complement(cd, cr))][RealType]
  389. [Returns the quantile (or percentile) of the distribution, starting from
  390. the complement of the probability, the same as: `quantile(cd, 1-cr)`]]
  391. [[chf(cd, cr)][RealType][Returns the cumulative hazard function of the distribution.]]
  392. [[hazard(cd, cr)][RealType][Returns the hazard function of the distribution.]]
  393. [[kurtosis(cd)][RealType][Returns the kurtosis of the distribution.]]
  394. [[kurtosis_excess(cd)][RealType][Returns the kurtosis excess of the distribution.]]
  395. [[mean(cd)][RealType][Returns the mean of the distribution.]]
  396. [[mode(cd)][RealType][Returns the mode of the distribution.]]
  397. [[skewness(cd)][RealType][Returns the skewness of the distribution.]]
  398. [[standard_deviation(cd)][RealType][Returns the standard deviation of the distribution.]]
  399. [[variance(cd)][RealType][Returns the variance of the distribution.]]
  400. ]
  401. [endsect] [/ section:dist_concept Conceptual Requirements for Distribution Types]
  402. [section:archetypes Conceptual Archetypes for Reals and Distributions]
  403. There are a few concept archetypes available:
  404. * Real concept for floating-point types.
  405. * Distribution concept for statistical distributions.
  406. [h5:real_concept Real concept]
  407. `std_real_concept` is an archetype for theReal types,
  408. including the built-in float, double, long double.
  409. ``#include <boost/concepts/std_real_concept.hpp>``
  410. namespace boost{
  411. namespace math{
  412. namespace concepts
  413. {
  414. class std_real_concept;
  415. }
  416. }} // namespaces
  417. The main purpose in providing this type is to verify
  418. that standard library functions are found via a using declaration -
  419. bringing those functions into the current scope -
  420. and not just because they happen to be in global scope.
  421. In order to ensure that a call to say `pow` can be found
  422. either via argument dependent lookup, or failing that then
  423. in the std namespace: all calls to standard library functions
  424. are unqualified, with the std:: versions found via a `using` declaration
  425. to make them visible in the current scope. Unfortunately it's all
  426. to easy to forget the `using` declaration, and call the double version of
  427. the function that happens to be in the global scope by mistake.
  428. For example if the code calls ::pow rather than std::pow,
  429. the code will cleanly compile, but truncation of long doubles to
  430. double will cause a significant loss of precision.
  431. In contrast a template instantiated with std_real_concept will *only*
  432. compile if the all the standard library functions used have
  433. been brought into the current scope with a using declaration.
  434. [h6 Testing the real concept]
  435. There is a test program
  436. [@../../test/std_real_concept_check.cpp libs/math/test/std_real_concept_check.cpp]
  437. that instantiates every template in this library with type
  438. `std_real_concept` to verify its usage of standard library functions.
  439. ``#include <boost/math/concepts/real_concept.hpp>``
  440. namespace boost{
  441. namespace math{
  442. namespace concepts{
  443. class real_concept;
  444. }}} // namespaces
  445. `real_concept` is an archetype for
  446. [link math_toolkit.real_concepts user defined real types],
  447. it declares its standard library functions in its own
  448. namespace: these will only be found if they are called unqualified
  449. allowing argument dependent lookup to locate them. In addition
  450. this type is useable at runtime:
  451. this allows code that would not otherwise be exercised by the built-in
  452. floating point types to be tested. There is no std::numeric_limits<>
  453. support for this type, since numeric_limits is not a conceptual requirement
  454. for [link math_toolkit.real_concepts RealType]s.
  455. NTL RR is an example of a type meeting the requirements that this type
  456. models, but note that use of a thin wrapper class is required: refer to
  457. [link math_toolkit.high_precision.use_ntl "Using With NTL - a High-Precision Floating-Point Library"].
  458. There is no specific test case for type `real_concept`, instead, since this
  459. type is usable at runtime, each individual test case as well as testing
  460. `float`, `double` and `long double`, also tests `real_concept`.
  461. [h6:distribution_concept Distribution Concept]
  462. Distribution Concept models statistical distributions.
  463. ``#include <boost/math/concepts/distribution.hpp>``
  464. namespace boost{
  465. namespace math{
  466. namespace concepts
  467. {
  468. template <class RealType>
  469. class distribution_archetype;
  470. template <class Distribution>
  471. struct DistributionConcept;
  472. }}} // namespaces
  473. The class template `distribution_archetype` is a model of the
  474. [link math_toolkit.dist_concept Distribution concept].
  475. The class template `DistributionConcept` is a
  476. [@../../../../libs/concept_check/index.html concept checking class]
  477. for distribution types.
  478. [h6 Testing the distribution concept]
  479. The test program
  480. [@../../test/compile_test/distribution_concept_check.cpp distribution_concept_check.cpp]
  481. is responsible for using `DistributionConcept` to verify that all the
  482. distributions in this library conform to the
  483. [link math_toolkit.dist_concept Distribution concept].
  484. The class template `DistributionConcept` verifies the existence
  485. (but not proper function) of the non-member accessors
  486. required by the [link math_toolkit.dist_concept Distribution concept].
  487. These are checked by calls like
  488. v = pdf(dist, x); // (Result v is ignored).
  489. And in addition, those that accept two arguments do the right thing when the
  490. arguments are of different types (the result type is always the same as the
  491. distribution's value_type). (This is implemented by some additional
  492. forwarding-functions in derived_accessors.hpp, so that there is no need for
  493. any code changes. Likewise boilerplate versions of the
  494. hazard\/chf\/coefficient_of_variation functions are implemented in
  495. there too.)
  496. [endsect] [/section:archetypes Conceptual Archetypes for Reals and Distributions]
  497. [/
  498. Copyright 2006, 2010, 2012 John Maddock and Paul A. Bristow.
  499. Distributed under the Boost Software License, Version 1.0.
  500. (See accompanying file LICENSE_1_0.txt or copy at
  501. http://www.boost.org/LICENSE_1_0.txt).
  502. ]