Skip to content

beta_distribution quantile returning incorrect values when precision policy is used. #1587

Closed

Description

@OliverHallam

We've run into an issue where the beta quantile function returns incorrect results for particular inputs, when using a precision policy.

Here is a simple repro of one particular case we hit:

#include <iostream>
#include <boost/math/distributions/beta.hpp>

using namespace boost::math;
using namespace boost::math::policies;

int main()
{
    double alpha = 1.78672964680176;
    double beta = 2583.71522530538;
    double p = 0.0273644014531048;

    beta_distribution<double, policy<digits10<8>>> dist{alpha, beta};

    auto x = quantile(dist, p);

    std::cout << x << "\n";
}

The expected result is 7.33064e-05, but the result returned is 0.253938.

If you change the alpha/beta values slightly the correct value is returned. Removing the digits policy also seems to eliminate the error.

In my brief investigation it looks like the initial approximation is correct, but it then jumps to the wrong value in the first iteration of halley_iterate. My uneducated guess is that it looks like its using the same precision to evaluate the beta function when its rootfinding to find the inverse - intuitively I'm not sure that's valid, although this judgement is well beyond my current mathematical prowess.

FWIW we were observing this bug on boost 1.69 but is still reproducible in 1.91 so its not something that has changed recently. I have reproduced this in Clang, but we were originally seeing this on production code built with ICC so I don't think its a compiler issue.

Activity

  1. changed the title [-]beta_distribution quantile returning incorrect values when precision policy is used,.[/-] [+]beta_distribution quantile returning incorrect values when precision policy is used.[/+] on Apr 24, 2026
  2. OliverHallam commented on Apr 24, 2026

    @OliverHallam
    Author

    This should have been reported against boostorg/math - can someone move it for me?

  3. transferred this issue fromboostorg/booston Oct 28, 2026
  4. NAThompson commented on Oct 29, 2026

    @NAThompson
    Collaborator

    @OliverHallam : Fixed on develop:

    PYTHONPATH=~/.venvs/boost-math/build ~/.venvs/boost-math/bin/python
    >>> import boost.math as bm
    >>> alpha = 1.78672964680176;
    >>> beta = 2583.71522530538
    >>> p = 0.0273644014531048
    >>> dist = bm.beta_distribution(alpha, beta)
    >>> dist.quantile(p)
    7.330639836997918e-05
    

    Should be available in the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions