beta.qbk 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. [section:beta_function Beta]
  2. [h4 Synopsis]
  3. ``
  4. #include <boost/math/special_functions/beta.hpp>
  5. ``
  6. namespace boost{ namespace math{
  7. template <class T1, class T2>
  8. ``__sf_result`` beta(T1 a, T2 b);
  9. template <class T1, class T2, class ``__Policy``>
  10. ``__sf_result`` beta(T1 a, T2 b, const ``__Policy``&);
  11. }} // namespaces
  12. [h4 Description]
  13. The beta function is defined by:
  14. [equation beta1]
  15. [graph beta]
  16. [optional_policy]
  17. The return type of these functions is computed using the __arg_promotion_rules
  18. when T1 and T2 are different types.
  19. [h4 Accuracy]
  20. The following table shows peak errors for various domains of input arguments,
  21. along with comparisons to the __gsl and __cephes libraries. Note that
  22. only results for the widest floating point type on the system are given as
  23. narrower types have __zero_error.
  24. [table_beta]
  25. Note that the worst errors occur when a or b are large, and that
  26. when this is the case the result is very close to zero, so absolute
  27. errors will be very small.
  28. [h4 Testing]
  29. A mixture of spot tests of exact values, and randomly generated test data are
  30. used: the test data was computed using
  31. [@http://shoup.net/ntl/doc/RR.txt NTL::RR] at 1000-bit precision.
  32. [h4 Implementation]
  33. Traditional methods of evaluating the beta function either involve evaluating
  34. the gamma functions directly, or taking logarithms and then
  35. exponentiating the result. However, the former is prone to overflows
  36. for even very modest arguments, while the latter is prone to cancellation
  37. errors. As an alternative, if we regard the gamma function as a white-box
  38. containing the __lanczos, then we can combine the power terms:
  39. [equation beta2]
  40. which is almost the ideal solution, however almost all of the error occurs
  41. in evaluating the power terms when /a/ or /b/ are large. If we assume that /a > b/
  42. then the larger of the two power terms can be reduced by a factor of /b/, which
  43. immediately cuts the maximum error in half:
  44. [equation beta3]
  45. This may not be the final solution, but it is very competitive compared to
  46. other implementation methods.
  47. The generic implementation - where no __lanczos approximation is available - is
  48. implemented in a very similar way to the generic version of the gamma function
  49. by means of Sterling's approximation.
  50. Again in order to avoid numerical overflow the power terms that prefix the series
  51. are collected together
  52. There are a few special cases worth mentioning:
  53. When /a/ or /b/ are less than one, we can use the recurrence relations:
  54. [equation beta4]
  55. [equation beta5]
  56. to move to a more favorable region where they are both greater than 1.
  57. In addition:
  58. [equation beta7]
  59. [endsect] [/section:beta_function The Beta Function]
  60. [/
  61. Copyright 2006 John Maddock and Paul A. Bristow.
  62. Distributed under the Boost Software License, Version 1.0.
  63. (See accompanying file LICENSE_1_0.txt or copy at
  64. http://www.boost.org/LICENSE_1_0.txt).
  65. ]