diff --git a/doc/distributions/hypergeometric.qbk b/doc/distributions/hypergeometric.qbk index 89b9ce46f..5780c788d 100644 --- a/doc/distributions/hypergeometric.qbk +++ b/doc/distributions/hypergeometric.qbk @@ -229,18 +229,24 @@ gives the required CDF. The median is simply the quantile at 0.5, and the remaining properties are calculated via: -[equation hypergeometric6] +[/ +Requires amsmath and mathtools: + +\DeclarePairedDelimiter{\floor}{\lfloor}{\rfloor} +\begin{equation*} +\begin{split} +mean & = \frac{rn}{N} \\ +mode & = \floor*{ \frac{(r+1)(n+1)}{N+2} }\\ +variance & = \frac{r(\frac{n}{N})(1-\frac{n}{N})(N-r)}{(N-1)}\\ +skewness & = \frac{(N-2n)\sqrt{(N-1)}(N-2r)}{\sqrt{rn(N-n)(N-r)}(N-2)}\\ +kertosis\:excess & = \frac{(N-1)N^2(N(N+1)-6r(N-r)-6n(N-n)+6nr(N-r)(N-n)(5N-6)}{nr(N-r)(N-n)(N-2)(N-3)} +\end{split} +\end{equation*} -[note The kurtosis formula above is not quite correct and kurtosis excess is now calculated -from -[@https://www.wolframalpha.com/input/?i=kurtosis+hypergeometric+distribution Wolfram Alpha hypergeometric distribution kurtosis]. -(The hypergeometric distribution kurtosis excess is mentioned in -[@https://mathworld.wolfram.com/HypergeometricDistribution.html Wolfram Hypergeometric distribution] -but coyly only described as ['\"the kurtosis excess is given by a complicated expression.\"]). -This has been found numerically equivalent to the -[@https://en.wikipedia.org/wiki/Hypergeometric_distribution Wikipedia hypergeometric kurtosis excess formula]. ] +[equation hypergeometric6] + [endsect] [/ hypergeometric.qbk diff --git a/doc/equations/hypergeometric6.svg b/doc/equations/hypergeometric6.svg index d53504b33..8be5ec9e6 100644 --- a/doc/equations/hypergeometric6.svg +++ b/doc/equations/hypergeometric6.svg @@ -1,2 +1,684 @@ - -mean=rnNmode=floor((r+1)(n+1)N+2)variance=r(nN)(1nN)(Nr)(N1)skewness=(N2n)(N1)(N2r)rn(Nn)(Nr)(N2)kurtosis excess=(N2(N1)r(N2)(N3)(Nr))(N(N+1)6N(Nr)n(Nn)+3r(Nr)(N+6)N26) \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/doc/html/index.html b/doc/html/index.html index 5f71a8555..c46436556 100644 --- a/doc/html/index.html +++ b/doc/html/index.html @@ -134,7 +134,7 @@ This manual is also available in -

Last revised: June 16, 2021 at 10:35:24 GMT

+

Last revised: June 27, 2021 at 18:26:02 GMT


diff --git a/doc/html/indexes/s01.html b/doc/html/indexes/s01.html index ed5fcc865..818036fcf 100644 --- a/doc/html/indexes/s01.html +++ b/doc/html/indexes/s01.html @@ -24,7 +24,7 @@

-Function Index

+Function Index

1 2 4 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

@@ -123,6 +123,10 @@
  • +

    addition

    +
    +
  • +
  • add_fn

  • @@ -277,7 +281,10 @@
  • at

    -
    +
  • atanh

    @@ -1320,6 +1327,10 @@
  • +

    fibonacci

    +
    +
  • +
  • find_alpha

  • @@ -2060,6 +2071,7 @@
  • -

    means

    -
    -
  • -
  • means_and_covariance

  • @@ -2720,6 +2728,7 @@
  • Automatic Differentiation

  • Bessel Functions of the First and Second Kinds

  • Empirical Cumulative Distribution Function

  • +
  • Fibonacci Numbers

  • Lanczos Smoothing Derivatives

  • Modified Bessel Functions of the First and Second Kinds

  • tanh_sinh

  • @@ -2765,6 +2774,7 @@
  • +

    set

    +
    +
  • +
  • set_zero

  • @@ -3631,6 +3649,10 @@
  • +

    unchecked_fibonacci

    +
    +
  • +
  • unreal

    -Class Index

    +Class Index

    A B C D E F G H I K L M N O P Q R S T U V W

    @@ -45,6 +45,10 @@
  • bernoulli_distribution

  • beta_distribution

  • +
  • +

    bilinear_uniform

    +
    +
  • binomial_distribution

  • @@ -182,6 +186,10 @@

    -Typedef Index

    +Typedef Index

    A B C D E F G H I K L N P R S T U V W

    diff --git a/doc/html/indexes/s04.html b/doc/html/indexes/s04.html index e93374726..e60c7717c 100644 --- a/doc/html/indexes/s04.html +++ b/doc/html/indexes/s04.html @@ -24,7 +24,7 @@

    -Macro Index

    +Macro Index

    B F

    @@ -308,6 +308,7 @@

    BOOST_MATH_STANDALONE

    diff --git a/doc/html/indexes/s05.html b/doc/html/indexes/s05.html index 6e8b4bbce..33bc41746 100644 --- a/doc/html/indexes/s05.html +++ b/doc/html/indexes/s05.html @@ -23,7 +23,7 @@

    -Index

    +Index

    1 2 4 5 7 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

    @@ -375,6 +375,10 @@
  • +

    addition

    + +
  • +
  • add_fn

  • @@ -612,7 +616,10 @@
  • at

    - +
  • atanh

    @@ -818,6 +825,22 @@
  • beta_distribution

  • +

    Bilinear Uniform Interpolation

    + +
  • +
  • +

    bilinear_uniform

    + +
  • +
  • binomial

  • @@ -1221,6 +1244,7 @@

    BOOST_MATH_STANDALONE

    @@ -2404,6 +2428,7 @@
  • Arithmetic-Geometric Mean

  • Automatic Differentiation

  • Barycentric Rational Interpolation

  • +
  • Bilinear Uniform Interpolation

  • Binomial Distribution

  • Binomial Quiz Example

  • Bivariate Statistics

  • @@ -2430,6 +2455,7 @@
  • Exponential Integral Ei

  • Extreme Value Distribution

  • Factorial

  • +
  • Fibonacci Numbers

  • Floating-Point Constant Macros

  • Gauss-Kronrod Quadrature

  • Gauss-Legendre quadrature

  • @@ -4142,6 +4168,7 @@
  • Elliptic Integral Overview

  • F Distribution

  • Factorial

  • +
  • Fibonacci Numbers

  • Find Scale (Standard Deviation) Example

  • Finding Zeros of Bessel Functions of the First and Second Kinds

  • Gamma (and Erlang) Distribution

  • @@ -4232,10 +4259,6 @@
  • -

    F Distribution Examples

    - -
  • -
  • Facets for Floating-Point Infinities and NaNs

  • +

    fibonacci

    + +
  • +
  • +

    Fibonacci Numbers

    + +
  • +
  • +

    fibonacci_generator

    + +
  • +
  • file

    diff --git a/doc/html/math_toolkit/bilinear_uniform.html b/doc/html/math_toolkit/bilinear_uniform.html new file mode 100644 index 000000000..346b4f428 --- /dev/null +++ b/doc/html/math_toolkit/bilinear_uniform.html @@ -0,0 +1,144 @@ + + + +Bilinear Uniform Interpolation + + + + + + + + + + + + + + + +
    Boost C++ LibrariesHomeLibrariesPeopleFAQMore
    +
    +
    +PrevUpHomeNext +
    +
    + +

    + + Synopsis +

    +
    #include <boost/math/interpolators/bilinear_uniform.hpp>
    +
    +namespace boost::math::interpolators {
    +
    +template <class RandomAccessContainer>
    +class bilinear_uniform
    +{
    +public:
    +    using Real = typename RandomAccessContainer::value_type;
    +
    +    bilinear_uniform(RandomAccessContainer && fieldData, decltype(fieldData.size()) rows, decltype(fieldData.size()) cols, Real dx = 1, Real dy = 1, Real x0 = 0, Real y0 = 0)
    +
    +    Real operator()(Real x, Real y) const;
    +};
    +
    +

    + + Bilinear + Uniform Interpolation +

    +

    + The bilinear uniform interpolator takes a grid of data points specified by + a linear index and interpolates between each segment using a bilinear function. + Note that "bilinear" does not mean linear-it is the product of two + linear functions. The interpolant is continuous and its evaluation is constant + time. An example usage is as follows: +

    +
    std::vector<double> v{0.1, 0.2, 0.3,
    +                      0.4, 0.5, 0.5};
    +using boost::math::interpolators::bilinear_uniform;
    +int rows = 2;
    +int cols = 3;
    +double dx = 1;
    +double dy = 1;
    +auto bu = bilinear_uniform(std::move(v), rows, cols, dx, dy);
    +// evaluate at a point:
    +double z = bu(0.0, 0.0);
    +
    +

    + Periodically, it is helpful to see what data the interpolator has. This can + be achieved via +

    +
    std::cout << ub << "\n";
    +
    +

    + Note that the interpolator is pimpl'd, so that copying the class is cheap, + and hence it can be shared between threads. (The call operator is threadsafe.) +

    +

    + Note that the layout of the field data follows the convention found in laying + out images: The first value is associated with (x0, y0), and the last value + is associate with (x0 + (cols - 1)dx, y0 + (rows - 1)dy). This matches with + how we think about laying out matrices in C order, but of course there is no + canonical choice and conventions must be made. For example, it is traditional + in image processing the associate the first field value with the center of + the pixel (which would be called a cell-centered field in VTK). This interpolator + is point-centered, in the sense that (x0,y0) is associated with value v[0], + and (x0+dx, y0) associated with v[1]. If you have cell-centered data at (0,0), + then just pass (x0,y0) = (0.5, 0.5) to this interpolator. +

    +

    + Note that this interpolator does not provide the option for a rotation. We + regarded that as too expensive to handle in this class. Rotating the arguments + must be performed by the user. +

    +

    + + Complexity + and Performance +

    +

    + The google/benchmark in reporting/performance/bilinear_uniform_performance.cpp demonstrates + the cost of the call operator for this interpolator: +

    +
    Run on (16 X 4300 MHz CPU s)
    +CPU Caches:
    +  L1 Data 32K (x8)
    +  L1 Instruction 32K (x8)
    +  L2 Unified 1024K (x8)
    +  L3 Unified 11264K (x1)
    +Load Average: 0.92, 0.64, 0.35
    +--------------------------------------
    +Benchmark                      Time
    +--------------------------------------
    +Bilinear<double>/64            13.6 ns
    +Bilinear<double>/128           13.3 ns
    +Bilinear<double>/256           13.9 ns
    +Bilinear<double>/512           13.7 ns
    +Bilinear<double>/1024          13.2 ns
    +Bilinear<double>/2048          13.1 ns
    +Bilinear<double>/4096          13.2 ns
    +Bilinear<double>/8192          13.2 ns
    +
    +
    + + + +
    +
    +
    +PrevUpHomeNext +
    + + diff --git a/doc/html/math_toolkit/conventions.html b/doc/html/math_toolkit/conventions.html index 5b815d0c0..f0d0f1943 100644 --- a/doc/html/math_toolkit/conventions.html +++ b/doc/html/math_toolkit/conventions.html @@ -27,7 +27,7 @@ Document Conventions

    - +

    This documentation aims to use of the following naming and formatting conventions. diff --git a/doc/html/math_toolkit/dist_ref/dists/hypergeometric_dist.html b/doc/html/math_toolkit/dist_ref/dists/hypergeometric_dist.html index 7b11aa984..f204bcf3b 100644 --- a/doc/html/math_toolkit/dist_ref/dists/hypergeometric_dist.html +++ b/doc/html/math_toolkit/dist_ref/dists/hypergeometric_dist.html @@ -342,22 +342,6 @@

    -
    - - - - - -
    [Note]Note

    - The kurtosis formula above is not quite correct and kurtosis excess is - now calculated from Wolfram - Alpha hypergeometric distribution kurtosis. (The hypergeometric - distribution kurtosis excess is mentioned in Wolfram - Hypergeometric distribution but coyly only described as "the - kurtosis excess is given by a complicated expression."). - This has been found numerically equivalent to the Wikipedia - hypergeometric kurtosis excess formula. -

    diff --git a/doc/html/math_toolkit/history1.html b/doc/html/math_toolkit/history1.html index 3d50c46e6..3ff59e77c 100644 --- a/doc/html/math_toolkit/history1.html +++ b/doc/html/math_toolkit/history1.html @@ -38,6 +38,42 @@

    + Math-3.1.0 + (Boost-1.77) +
    +
      +
    • + This library can now be used entirely standalone, without the rest of Boost: + either use a compiler which supports __has_include + or define BOOST_MATH_STANDALONE + to enable standalone mode. +
    • +
    • + Add Bilinear Uniform Interpolation. +
    • +
    • + Add Fibonacci + Numbers. +
    • +
    • + Fix Hypergeometric Distribution kertosis, see #639. +
    • +
    • + Fix closed Catmull-Rom curves to have the same start/end point. See #636. +
    • +
    • + Correct Bernoulli number caching in multi-threading multiprecision case. +
    • +
    • + Re-enabled the ability to build in environments with no std lib threading + support. See #621. +
    • +
    • + Correct Gini-coefficient parrellel calculation. +
    • +
    +
    + Math-3.0.0 (Boost-1.76)
    @@ -88,7 +124,7 @@
    - + Math-2.13.0 (Boost-1.75)
    @@ -139,7 +175,7 @@
    - + Math-2.12.0 (Boost-1.73)
    @@ -181,7 +217,7 @@
    - + Math-2.11.0 (Boost-1.72)
    @@ -243,7 +279,7 @@
    - + Math-2.10.0 (Boost-1.71)
    @@ -277,7 +313,7 @@
    - + Math-2.9.0 (Boost-1.70)
    @@ -331,7 +367,7 @@
    - + Math-2.8.0 (Boost-1.69)
    @@ -388,7 +424,7 @@
    - + Math-2.7.1 (Boost-1.68)
    @@ -402,7 +438,7 @@
    - + Math-2.7.0 (Boost-1.66)
    @@ -419,7 +455,7 @@
    - + Math-2.6.0 (Boost-1.65)
    @@ -456,7 +492,7 @@
    - + Math-2.5.2 (Boost-1.64)
    @@ -473,7 +509,7 @@
    - + Math-2.5.1 (Boost-1.63)
    @@ -489,7 +525,7 @@
    - + Math-2.5.0 (Boost-1.62)
    @@ -514,7 +550,7 @@
    - + Math-2.4.0 (Boost-1.61)
    @@ -525,7 +561,7 @@ Polynomial arithmetic added to tools.
    - + Math-2.3.0 (Boost-1.60)
    @@ -604,7 +640,7 @@
    - + Math-2.2.1

    @@ -623,7 +659,7 @@

    - + Math-2.2.0 (boost-1.58.0)
    @@ -667,7 +703,7 @@
    - + Math-2.1.0 (boost-1.57.0)
    @@ -693,7 +729,7 @@
    - + Math-2.0.0 (Boost-1.56.0)
    @@ -744,7 +780,7 @@
    - + Math-1.9.1
      @@ -759,7 +795,7 @@
    - + Math-1.9.0
      @@ -826,7 +862,7 @@
    - + Boost-1.55
      @@ -885,7 +921,7 @@ and Accurate Parallel Inversion of the Gamma Distribution, Thomas Luu

      - + Boost-1.54
      @@ -939,7 +975,7 @@
    - + Boost-1.53
      @@ -974,7 +1010,7 @@
    - + Boost-1.52
      @@ -1021,14 +1057,14 @@ by switching to use the Students t distribution (or Normal distribution
    - + Boost-1.51

    See Boost-1.52 - some items were added but not listed in time for the release.

    - + Boost-1.50
      @@ -1065,7 +1101,7 @@ by switching to use the Students t distribution (or Normal distribution
    - + Boost-1.49
      @@ -1109,7 +1145,7 @@ by switching to use the Students t distribution (or Normal distribution
    - + Boost-1.48
      @@ -1160,7 +1196,7 @@ by switching to use the Students t distribution (or Normal distribution
    - + Boost-1.47
      @@ -1177,7 +1213,7 @@ by switching to use the Students t distribution (or Normal distribution
    - + Boost-1.46.1
    • @@ -1185,7 +1221,7 @@ by switching to use the Students t distribution (or Normal distribution #5113.
    - + Boost-1.46.0
      @@ -1200,7 +1236,7 @@ by switching to use the Students t distribution (or Normal distribution
    - + Boost-1.45.0
      @@ -1217,7 +1253,7 @@ by switching to use the Students t distribution (or Normal distribution
    - + Boost-1.44.0
      @@ -1231,7 +1267,7 @@ by switching to use the Students t distribution (or Normal distribution
    - + Boost-1.41.0
    • @@ -1239,7 +1275,7 @@ by switching to use the Students t distribution (or Normal distribution its inverse.
    - + Boost-1.40.0
      @@ -1275,7 +1311,7 @@ by switching to use the Students t distribution (or Normal distribution
    - + Boost-1.38.0
      @@ -1287,14 +1323,14 @@ by switching to use the Students t distribution (or Normal distribution
    - + Boost-1.37.0
    • Improved accuracy and testing of the inverse hypergeometric functions.
    - + Boost-1.36.0
      @@ -1327,7 +1363,7 @@ by switching to use the Students t distribution (or Normal distribution
    - + Boost-1.35.0: Post Review First Official Release
    @@ -1359,7 +1395,7 @@ by switching to use the Students t distribution (or Normal distribution
    - + Milestone 4: Second Review Candidate (1st March 2007)
    @@ -1373,7 +1409,7 @@ by switching to use the Students t distribution (or Normal distribution
    - + Milestone 3: First Review Candidate (31st Dec 2006)
    @@ -1401,7 +1437,7 @@ by switching to use the Students t distribution (or Normal distribution
    - + Milestone 2: Released September 10th 2006
    @@ -1437,7 +1473,7 @@ by switching to use the Students t distribution (or Normal distribution
    - + Milestone 1: Released March 31st 2006
    diff --git a/doc/html/math_toolkit/history2.html b/doc/html/math_toolkit/history2.html index 28cb77aac..d62d16317 100644 --- a/doc/html/math_toolkit/history2.html +++ b/doc/html/math_toolkit/history2.html @@ -38,6 +38,42 @@

    + Math-3.1.0 + (Boost-1.77) +
    +
      +
    • + This library can now be used entirely standalone, without the rest of Boost: + either use a compiler which supports __has_include + or define BOOST_MATH_STANDALONE + to enable standalone mode. +
    • +
    • + Add Bilinear Uniform Interpolation. +
    • +
    • + Add Fibonacci + Numbers. +
    • +
    • + Fix Hypergeometric Distribution kertosis, see #639. +
    • +
    • + Fix closed Catmull-Rom curves to have the same start/end point. See #636. +
    • +
    • + Correct Bernoulli number caching in multi-threading multiprecision case. +
    • +
    • + Re-enabled the ability to build in environments with no std lib threading + support. See #621. +
    • +
    • + Correct Gini-coefficient parrellel calculation. +
    • +
    +
    + Math-3.0.0 (Boost-1.76)
    @@ -88,7 +124,7 @@
    - + Math-2.13.0 (Boost-1.75)
    @@ -139,7 +175,7 @@
    - + Math-2.12.0 (Boost-1.73)
    @@ -181,7 +217,7 @@
    - + Math-2.11.0 (Boost-1.72)
    @@ -243,7 +279,7 @@
    - + Math-2.10.0 (Boost-1.71)
    @@ -277,7 +313,7 @@
    - + Math-2.9.0 (Boost-1.70)
    @@ -331,7 +367,7 @@
    - + Math-2.8.0 (Boost-1.69)
    @@ -388,7 +424,7 @@
    - + Math-2.7.1 (Boost-1.68)
    @@ -402,7 +438,7 @@
    - + Math-2.7.0 (Boost-1.66)
    @@ -419,7 +455,7 @@
    - + Math-2.6.0 (Boost-1.65)
    @@ -456,7 +492,7 @@
    - + Math-2.5.2 (Boost-1.64)
    @@ -473,7 +509,7 @@
    - + Math-2.5.1 (Boost-1.63)
    @@ -489,7 +525,7 @@
    - + Math-2.5.0 (Boost-1.62)
    @@ -514,7 +550,7 @@
    - + Math-2.4.0 (Boost-1.61)
    @@ -525,7 +561,7 @@ Polynomial arithmetic added to tools.
    - + Math-2.3.0 (Boost-1.60)
    @@ -604,7 +640,7 @@
    - + Math-2.2.1

    @@ -623,7 +659,7 @@

    - + Math-2.2.0 (boost-1.58.0)
    @@ -667,7 +703,7 @@
    - + Math-2.1.0 (boost-1.57.0)
    @@ -693,7 +729,7 @@
    - + Math-2.0.0 (Boost-1.56.0)
    @@ -744,7 +780,7 @@
    - + Math-1.9.1
      @@ -759,7 +795,7 @@
    - + Math-1.9.0
      @@ -826,7 +862,7 @@
    - + Boost-1.55
      @@ -885,7 +921,7 @@ and Accurate Parallel Inversion of the Gamma Distribution, Thomas Luu

      - + Boost-1.54
      @@ -939,7 +975,7 @@
    - + Boost-1.53
      @@ -974,7 +1010,7 @@
    - + Boost-1.52
      @@ -1021,14 +1057,14 @@ by switching to use the Students t distribution (or Normal distribution
    - + Boost-1.51

    See Boost-1.52 - some items were added but not listed in time for the release.

    - + Boost-1.50
      @@ -1065,7 +1101,7 @@ by switching to use the Students t distribution (or Normal distribution
    - + Boost-1.49
      @@ -1109,7 +1145,7 @@ by switching to use the Students t distribution (or Normal distribution
    - + Boost-1.48
      @@ -1160,7 +1196,7 @@ by switching to use the Students t distribution (or Normal distribution
    - + Boost-1.47
      @@ -1177,7 +1213,7 @@ by switching to use the Students t distribution (or Normal distribution
    - + Boost-1.46.1
    • @@ -1185,7 +1221,7 @@ by switching to use the Students t distribution (or Normal distribution #5113.
    - + Boost-1.46.0
      @@ -1200,7 +1236,7 @@ by switching to use the Students t distribution (or Normal distribution
    - + Boost-1.45.0
      @@ -1217,7 +1253,7 @@ by switching to use the Students t distribution (or Normal distribution
    - + Boost-1.44.0
      @@ -1231,7 +1267,7 @@ by switching to use the Students t distribution (or Normal distribution
    - + Boost-1.41.0
    • @@ -1239,7 +1275,7 @@ by switching to use the Students t distribution (or Normal distribution its inverse.
    - + Boost-1.40.0
      @@ -1275,7 +1311,7 @@ by switching to use the Students t distribution (or Normal distribution
    - + Boost-1.38.0
      @@ -1287,14 +1323,14 @@ by switching to use the Students t distribution (or Normal distribution
    - + Boost-1.37.0
    • Improved accuracy and testing of the inverse hypergeometric functions.
    - + Boost-1.36.0
      @@ -1327,7 +1363,7 @@ by switching to use the Students t distribution (or Normal distribution
    - + Boost-1.35.0: Post Review First Official Release
    @@ -1359,7 +1395,7 @@ by switching to use the Students t distribution (or Normal distribution
    - + Milestone 4: Second Review Candidate (1st March 2007)
    @@ -1373,7 +1409,7 @@ by switching to use the Students t distribution (or Normal distribution
    - + Milestone 3: First Review Candidate (31st Dec 2006)
    @@ -1401,7 +1437,7 @@ by switching to use the Students t distribution (or Normal distribution
    - + Milestone 2: Released September 10th 2006
    @@ -1437,7 +1473,7 @@ by switching to use the Students t distribution (or Normal distribution
    - + Milestone 1: Released March 31st 2006
    diff --git a/doc/html/math_toolkit/navigation.html b/doc/html/math_toolkit/navigation.html index 7748e49df..4bd188e1b 100644 --- a/doc/html/math_toolkit/navigation.html +++ b/doc/html/math_toolkit/navigation.html @@ -27,7 +27,7 @@ Navigation

    - +

    Boost.Math documentation is provided in both HTML and PDF formats. diff --git a/doc/html/math_toolkit/number_series.html b/doc/html/math_toolkit/number_series.html index 2d7be9aaa..77142c368 100644 --- a/doc/html/math_toolkit/number_series.html +++ b/doc/html/math_toolkit/number_series.html @@ -31,6 +31,8 @@ Numbers

    Tangent Numbers
    Prime Numbers
    +
    Fibonacci + Numbers
    diff --git a/doc/html/math_toolkit/number_series/fibonacci_numbers.html b/doc/html/math_toolkit/number_series/fibonacci_numbers.html new file mode 100644 index 000000000..923a2a47d --- /dev/null +++ b/doc/html/math_toolkit/number_series/fibonacci_numbers.html @@ -0,0 +1,198 @@ + + + +Fibonacci Numbers + + + + + + + + +
    + + + + + + +
    Boost C++ LibrariesHomeLibrariesPeopleFAQMore
    +
    +
    +PrevUpHomeNext +
    +
    + +

    + Fibonacci numbers + (Fn) follows the linear recurrence Fn=Fn-1+Fn-2 starting with F0=0, F1=1. +

    +
    + + Synopsis +
    +
    #include <boost/math/special_functions/fibonacci.hpp>
    +
    +
    namespace boost { namespace math {
    +
    +template <class T, class Policy>
    +constexpr T fibonacci(unsigned long long n) // Checked version (default policy)
    +
    +template <class T, class Policy>
    +constexpr T fibonacci(unsigned long long n, const Policy &pol) // Checked version (policy for errors etc.)
    +
    +template <typename T>
    +constexpr T unchecked_fibonacci(unsigned long long n) noexcept(std::is_fundamental<T>::value); {  // Unchecked version (no policy).
    +
    +}} // namespaces
    +
    +

    + The functions return Fn for a given input n having type + T. +

    +
    + + Description +
    +

    + The checked versions checks for the overflow before starting the computation. + If n is so large that the result can not be represented + in type T, it then calls overflow_error. + The overflow check is susceptible to off-by-one errors around the overflow + limit. See Binet's Formula below for more details on the check. +

    +

    + These functions are all constexpr + from C++14 onwards, and in addition unchecked_fibonacci + is noexcept when T is a fundamental + type. +

    +

    + The final Policy argument is optional and can + be used to control the behaviour of the function: how it handles errors, + what level of precision to use etc. Refer to the policy + documentation for more details. +

    +

    + If in the checked version, the overflow check succeeds then the unchecked + version is called which computes the desired Fn. Checked version is slower + because of the overhead involved in overflow check. +

    +
    + + Generator +
    +
    #include <boost/math/special_functions/fibonacci.hpp>
    +
    +
    template <typename T>
    +class fibonacci_generator {
    +  // returns consecutive fibonacci number starting from 0, 1, 1, 2, ...
    +  T operator()();
    +  // reset the generator to start from nth fibonacci number
    +  void set(unsigned long long n);
    +}
    +
    +

    + The generator returns consecutive fibonacci numbers starting with 0, 1, 1, + 2... +

    +

    + The state of the generator can be modified using set() + which makes generator return consecutive fibonacci numbers starting from + n[sup th] fibonacci number. +

    +
    boost::math::fibonacci_generator<int> gen;
    +int x = gen(); // x is 0
    +int y = gen(); // y is 1
    +for(int i = 0; i < 5; ++i) // this loop is same as gen.set(7);
    +    gen();
    +int z = gen(); // z is 13 
    +
    +

    + Generator is non-throwing for all fundamental types and will not check for + overflows. +

    +
    + + Type + Requirements +
    +

    + The type must be an arithmetic type supporting +, -, * and can be initialized + from trivial integral types. +

    +
    + + Example +
    +

    + The file reciprocal_fibonacci_constant.cpp + uses fibonacci_generator + to calculate the reciprocal fibonacci constant to 1000 digit precision like + so: +

    +
    #include <boost/math/special_functions/fibonacci.hpp>
    +#include <boost/multiprecision/mpfr.hpp>
    +#include <iomanip>
    +#include <iostream>
    +
    +int main() {
    +    using Real = boost::multiprecision::mpfr_float_1000;
    +    boost::math::fibonacci_generator<Real> gen;
    +    gen.set(1); // start producing values from 1st fibonacci number
    +    Real ans = 0;
    +    const int ITR = 1000;
    +    for (int i = 0; i < ITR; ++i) {
    +        ans += 1.0 / gen();
    +    }
    +    std::cout << std::setprecision(1000) << "Reciprocal fibonacci constant after "
    +              << ITR << " iterations is: " << ans << std::endl;
    +}
    +
    +
    + + Implementation +
    +

    + The time complexity for computing fibonacci number is O(log n), without considering + the time complexities of multiplication and addition (where n + is the input parameter). The implementation is iterative version of Dijkstra's identities + and which simply walks down the bits of n. +

    +
    + + Binet's + Formula +
    +

    + There is a closed form expression for computing fibonacci numbers but since + it suffers from imprecision issues (using floating point computation), it + is not implemented. +

    +

    + However an approximate formula is used for the overflow checking in the checked + version. +

    +
    + + + +
    +
    +
    +PrevUpHomeNext +
    + + diff --git a/doc/html/math_toolkit/number_series/primes.html b/doc/html/math_toolkit/number_series/primes.html index 1c9afbf8b..695bf2128 100644 --- a/doc/html/math_toolkit/number_series/primes.html +++ b/doc/html/math_toolkit/number_series/primes.html @@ -7,7 +7,7 @@ - + @@ -20,7 +20,7 @@

    -PrevUpHomeNext +PrevUpHomeNext

    @@ -83,7 +83,7 @@
    -PrevUpHomeNext +PrevUpHomeNext
    diff --git a/doc/html/math_toolkit/quintic_hermite.html b/doc/html/math_toolkit/quintic_hermite.html index 2b726631c..1897cefe2 100644 --- a/doc/html/math_toolkit/quintic_hermite.html +++ b/doc/html/math_toolkit/quintic_hermite.html @@ -7,7 +7,7 @@ - + @@ -20,7 +20,7 @@

    -PrevUpHomeNext +PrevUpHomeNext

    @@ -236,7 +236,7 @@
    -PrevUpHomeNext +PrevUpHomeNext
    diff --git a/doc/html/math_toolkit/sf_gamma.html b/doc/html/math_toolkit/sf_gamma.html index dbc838805..b10a9e83f 100644 --- a/doc/html/math_toolkit/sf_gamma.html +++ b/doc/html/math_toolkit/sf_gamma.html @@ -6,7 +6,7 @@ - + @@ -20,7 +20,7 @@
    -PrevUpHomeNext +PrevUpHomeNext

    @@ -54,7 +54,7 @@
    -PrevUpHomeNext +PrevUpHomeNext
    diff --git a/doc/html/quadrature.html b/doc/html/quadrature.html index acbb599d6..f19a0a6d7 100644 --- a/doc/html/quadrature.html +++ b/doc/html/quadrature.html @@ -6,7 +6,7 @@ - + @@ -20,7 +20,7 @@
    -PrevUpHomeNext +PrevUpHomeNext

    @@ -70,7 +70,7 @@
    -PrevUpHomeNext +PrevUpHomeNext
    diff --git a/doc/html/special.html b/doc/html/special.html index 9243ac2cc..814be1732 100644 --- a/doc/html/special.html +++ b/doc/html/special.html @@ -34,6 +34,8 @@ Numbers
    Tangent Numbers
    Prime Numbers
    +
    Fibonacci + Numbers

  • Gamma Functions
    diff --git a/doc/html/standalone_HTML.manifest b/doc/html/standalone_HTML.manifest index 725bdf12b..94eff5ee8 100644 --- a/doc/html/standalone_HTML.manifest +++ b/doc/html/standalone_HTML.manifest @@ -168,6 +168,7 @@ math_toolkit/number_series.html math_toolkit/number_series/bernoulli_numbers.html math_toolkit/number_series/tangent_numbers.html math_toolkit/number_series/primes.html +math_toolkit/number_series/fibonacci_numbers.html math_toolkit/sf_gamma.html math_toolkit/sf_gamma/tgamma.html math_toolkit/sf_gamma/lgamma.html @@ -326,6 +327,7 @@ math_toolkit/cubic_hermite.html math_toolkit/makima.html math_toolkit/pchip.html math_toolkit/quintic_hermite.html +math_toolkit/bilinear_uniform.html quadrature.html math_toolkit/trapezoidal.html math_toolkit/gauss.html diff --git a/doc/overview/roadmap.qbk b/doc/overview/roadmap.qbk index cecb49540..ef3c2444b 100644 --- a/doc/overview/roadmap.qbk +++ b/doc/overview/roadmap.qbk @@ -8,6 +8,18 @@ All old bug reports including closed ones can be viewed on Trac Recent issues on GitHub [@https://github.com/boostorg/math/issues?utf8=%E2%9C%93&q=is%3Aissue here]. +[h4 Math-3.1.0 (Boost-1.77)] + +* This library can now be used entirely standalone, without the rest of Boost: either use a compiler +which supports `__has_include` or define `BOOST_MATH_STANDALONE` to enable standalone mode. +* Add [link math_toolkit.bilinear_uniform Bilinear Uniform Interpolation]. +* Add [link math_toolkit.number_series.fibonacci_numbers Fibonacci Numbers]. +* Fix Hypergeometric Distribution kertosis, see [@https://github.com/boostorg/math/issues/639 #639]. +* Fix closed Catmull-Rom curves to have the same start/end point. See [@https://github.com/boostorg/math/issues/636 #636]. +* Correct Bernoulli number caching in multi-threading multiprecision case. +* Re-enabled the ability to build in environments with no std lib threading support. See [@https://github.com/boostorg/math/issues/621 #621]. +* Correct Gini-coefficient parrellel calculation. + [h4 Math-3.0.0 (Boost-1.76)] * [*Breaking Change:] C++03 support is now removed, a C++11 or later conformant compiler is now required to use this library. diff --git a/doc/sf/number_series.qbk b/doc/sf/number_series.qbk index 2e0f0ef2c..c47cc877f 100644 --- a/doc/sf/number_series.qbk +++ b/doc/sf/number_series.qbk @@ -261,11 +261,100 @@ This function is `constexpr` only if the compiler supports C++14 constexpr funct [endsect] [/section:primes] +[section:fibonacci_numbers Fibonacci Numbers] + +[@https://en.wikipedia.org/wiki/Fibonacci_number Fibonacci numbers] (F[sub n]) follows the linear recurrence F[sub n]=F[sub n-1]+F[sub n-2] starting with F[sub 0]=0, F[sub 1]=1. + +[h4 Synopsis] + +`` +#include +`` + + namespace boost { namespace math { + + template + constexpr T fibonacci(unsigned long long n) // Checked version (default policy) + + template + constexpr T fibonacci(unsigned long long n, const Policy &pol) // Checked version (policy for errors etc.) + + template + constexpr T unchecked_fibonacci(unsigned long long n) noexcept(std::is_fundamental::value); { // Unchecked version (no policy). + + }} // namespaces + +The functions return F[sub n] for a given input [^n] having type [^T]. + +[h4 Description] +The checked versions checks for the overflow before starting the computation. If [^n] is so large that the result can not +be represented in type [^T], it then calls __overflow_error. The overflow check is susceptible to off-by-one errors around the overflow limit. See Binet's Formula below for more details on the check. + +These functions are all `constexpr` from C++14 onwards, and in addition `unchecked_fibonacci` is `noexcept` when T is a fundamental type. + +[optional_policy] + +If in the checked version, the overflow check succeeds then the unchecked version is called which computes the desired F[sub n]. Checked version is slower because of the overhead involved in overflow check. + +[h4 Generator] + +`` +#include +`` + + template + class fibonacci_generator { + // returns consecutive fibonacci number starting from 0, 1, 1, 2, ... + T operator()(); + // reset the generator to start from nth fibonacci number + void set(unsigned long long n); + } + +The generator returns consecutive fibonacci numbers starting with 0, 1, 1, 2... + +The state of the generator can be modified using [^set()] which makes generator return consecutive fibonacci numbers starting from [^n][sup th] fibonacci number. + + boost::math::fibonacci_generator gen; + int x = gen(); // x is 0 + int y = gen(); // y is 1 + for(int i = 0; i < 5; ++i) // this loop is same as gen.set(7); + gen(); + int z = gen(); // z is 13 + + +Generator is non-throwing for all fundamental types and will not check for overflows. + +[h4 Type Requirements] + +The type must be an arithmetic type supporting +, -, * and can be initialized from trivial integral types. + +[h4 Example] + +The file [@../../example/reciprocal_fibonacci_constant.cpp reciprocal_fibonacci_constant.cpp] uses `fibonacci_generator` to calculate the +reciprocal fibonacci constant to 1000 digit precision like so: + +[import ../../example/reciprocal_fibonacci_constant.cpp] + +[fibonacci_eg] + +[h4 Implementation] + +The time complexity for computing fibonacci number is O(log n), without considering the time complexities of multiplication and addition (where [^n] is the input parameter). +The implementation is iterative version of [@http://www.cs.utexas.edu/users/EWD/ewd06xx/EWD654.PDF Dijkstra's identities] and which simply walks down the bits of [^n]. + +[h4:binet Binet's Formula] + +There is a closed form expression for computing fibonacci numbers but since it suffers from imprecision issues (using floating point computation), it is not implemented. + +However an approximate formula is used for the overflow checking in the checked version. + +[endsect] [/Fibonacci Numbers] + [endsect] [/Number Series] [/ Copyright 2013, 2014 Nikhar Agrawal, Christopher Kormanyos, John Maddock, Paul A. Bristow. - Distributed under the Boost Software License, Version 1.0. + Copyright 2020 Madhur Chauhan. 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). ] diff --git a/example/Jamfile.v2 b/example/Jamfile.v2 index fb33e6cdf..72834b561 100644 --- a/example/Jamfile.v2 +++ b/example/Jamfile.v2 @@ -150,7 +150,7 @@ test-suite examples : [ run ooura_fourier_integrals_example.cpp : : : [ requires cxx11_hdr_mutex cxx11_lambdas cxx11_inline_namespaces cxx11_auto_declarations ] ] [ run ooura_fourier_integrals_cosine_example.cpp : : : [ requires cxx11_hdr_mutex cxx11_inline_namespaces cxx11_auto_declarations cxx17_std_apply ] ] [ run ooura_fourier_integrals_multiprecision_example.cpp : : : [ check-target-builds ../config//has_float128 "GCC libquadmath and __float128 support" : -lquadmath ] [ requires cxx11_hdr_mutex cxx11_inline_namespaces cxx11_auto_declarations cxx17_std_apply ] ] - + [ run reciprocal_fibonacci_constant.cpp : : : [ check-target-builds ../config//has_mpfr "MPFR Support" : "-lmpfr -lgmp" : no ] ] ; run root_elliptic_finding.cpp /boost/timer : : : release static [ requires cxx11_unified_initialization_syntax cxx11_defaulted_functions ] freebsd:"-lrt" linux:"-lrt -lpthread" ; diff --git a/example/reciprocal_fibonacci_constant.cpp b/example/reciprocal_fibonacci_constant.cpp index 349625fee..7c6405c52 100644 --- a/example/reciprocal_fibonacci_constant.cpp +++ b/example/reciprocal_fibonacci_constant.cpp @@ -8,6 +8,8 @@ // This is an example to calculate Reciprocal Fibonacci Constant (A079586 in the OEIS) // compile with flags: -std=c++11 -lmpfr +//[fibonacci_eg + #include #include #include @@ -25,3 +27,5 @@ int main() { std::cout << std::setprecision(1000) << "Reciprocal fibonacci constant after " << ITR << " iterations is: " << ans << std::endl; } + +//] diff --git a/include/boost/math/special_functions/fibonacci.hpp b/include/boost/math/special_functions/fibonacci.hpp index 09e86122c..7aaf6dd85 100644 --- a/include/boost/math/special_functions/fibonacci.hpp +++ b/include/boost/math/special_functions/fibonacci.hpp @@ -21,14 +21,12 @@ namespace boost { namespace math { namespace detail { -// this should be constexpr in future -const double log_2 = std::log(2.0), - fib_bits_phi = std::log(boost::math::constants::phi()) / log_2, - fib_bits_deno = std::log(5.0) / 2.0 / log_2; + constexpr double fib_bits_phi = 0.69424191363061730173879026; + constexpr double fib_bits_deno = 1.1609640474436811739351597; } // namespace detail template -inline constexpr T unchecked_fibonacci(unsigned long long n) noexcept { +inline BOOST_CXX14_CONSTEXPR T unchecked_fibonacci(unsigned long long n) noexcept(std::is_fundamental::value) { // This function is called by the rest and computes the actual nth fibonacci number // First few fibonacci numbers: 0 (0th), 1 (1st), 1 (2nd), 2 (3rd), ... if (n <= 2) return n == 0 ? 0 : 1; @@ -52,7 +50,7 @@ inline constexpr T unchecked_fibonacci(unsigned long long n) noexcept { } template -T inline fibonacci(unsigned long long n, const Policy &pol) { +T inline BOOST_CXX14_CONSTEXPR fibonacci(unsigned long long n, const Policy &pol) { // check for overflow using approximation to binet's formula: F_n ~ phi^n / sqrt(5) if (n > 20 && n * detail::fib_bits_phi - detail::fib_bits_deno > std::numeric_limits::digits) return policies::raise_overflow_error("boost::math::fibonacci<%1%>(unsigned long long)", "Possible overflow detected.", pol); @@ -60,7 +58,7 @@ T inline fibonacci(unsigned long long n, const Policy &pol) { } template -T inline fibonacci(unsigned long long n) { +T inline BOOST_CXX14_CONSTEXPR fibonacci(unsigned long long n) { return fibonacci(n, policies::policy<>()); } @@ -69,7 +67,7 @@ template class fibonacci_generator { public: // return next fibonacci number - T operator()() noexcept { + T operator()() noexcept(std::is_fundamental::value) { T ret = a; a = b, b = b + ret; // could've simply: swap(a, b), b += a; return ret; @@ -77,7 +75,7 @@ class fibonacci_generator { // after set(nth), subsequent calls to the generator returns consecutive // fibonacci numbers starting with the nth fibonacci number - void set(unsigned long long nth) noexcept { + void set(unsigned long long nth) noexcept(std::is_fundamental::value) { n = nth; a = unchecked_fibonacci(n); b = unchecked_fibonacci(n + 1); diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index f6d2c4aea..2b062bf15 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -495,7 +495,7 @@ test-suite special_fun : [ run test_trig.cpp test_instances//test_instances pch_light ../../test/build//boost_unit_test_framework ] [ run test_zeta.cpp ../../test/build//boost_unit_test_framework test_instances//test_instances pch_light ] [ run test_sinc.cpp ../../test/build//boost_unit_test_framework pch_light ] - [ run test_fibonacci.cpp ../../test/build//boost_unit_test_framework : : : [ requires cxx17_if_constexpr cxx17_std_apply ] ] + [ run test_fibonacci.cpp ../../test/build//boost_unit_test_framework ] ; test-suite distribution_tests : diff --git a/test/test_fibonacci.cpp b/test/test_fibonacci.cpp index 429819a73..fb030c209 100644 --- a/test/test_fibonacci.cpp +++ b/test/test_fibonacci.cpp @@ -94,13 +94,21 @@ BOOST_AUTO_TEST_CASE(generator_check) { } } +#ifndef BOOST_NO_CXX14_CONSTEXPR + BOOST_AUTO_TEST_CASE(constexpr_check) { constexpr int x = boost::math::unchecked_fibonacci(32); - BOOST_TEST(x == 2178309); + static_assert(x == 2178309); constexpr double y = boost::math::unchecked_fibonacci(40); - BOOST_TEST(y == 102334155.0); + static_assert(y == 102334155.0); + + constexpr int xx = boost::math::fibonacci(32); + static_assert(xx == 2178309); + + constexpr double yy = boost::math::fibonacci(40); + static_assert(yy == 102334155.0); - // checked fibonacci can't be constexpr because of non-constexpr - // dependency in detail::log_2, detail::fib_bits_phi, detail::fib_bits_deno } + +#endif