Description
Latter parameter of std::negative_binomial_distribution ([rand.dist.bern.negbin]) is required by the constructor to be less or equal to 1. However a note before says that the mathematical expression "is undefined when p == 1". This leaves it unclear what p == 1 should mean for the program.
- Many definitions elsewhere [1][2][3][4][5] for negative_binomial_distribution accept p == 1 as it would seem logical given the mathematical definition.
- Note saying that P(i|k,p) is undefined when p == 1 probably refers to 0^0, but it would seem inconsistent interpretation given that the same 0^0 effectively appears in binomial_distribution when p == 1 and t == i, where it must be interpreted as 1 (interpretations of 0^0 is analyzed e.g. in Wikipedia). Thus it's unclear what's the intended purpose of the note.
- It is not clear whether note of mathematical term being undefined implies that behaviour of the program is undefined (instead of e.g. evaluation resulting to NaN).
Why this is a problem?
Using the distribution with wrong parameters can result to UB (e.g. application termination), so it's essential to know what parameters can be used.
Questions to clarify:
- Should p == 1 result to undefined behaviour in operator()?
- If yes, why constructor accepts p == 1 and why a distribution can't be evaluated after being constructed with an argument that fulfills the 'Requires' statement and when it would be valid to evaluate given the mathematical definition? Or in other words, what requirement user violates to cause undefined behaviour if calling operator() after constructed with p == 1?
- If not, it would be worth clarifying: for example cppreference.com mentions that with p == 1 operator() results to undefined behaviour.
The note about P(i|k,p) being undefined has been added by LWG2406, but creating this issue as editorial as LWG2406 resulted only to change in non-normative text. It's also worth noting that both premises in LWG2406 seem untrue:
-
For p == 1, this is "* 1^k * 0^i", so every integer i >= 0 is produced with zero probability
-As mentioned above, 0^0 can be considered to be 1 in this context.
-
Wikipedia states that p must be within (0, 1), exclusive on both sides.
-p == 1 is and was accepted even in Wikipedia in 2014. [3]
References:
[1] https://reference.wolfram.com/language/ref/NegativeBinomialDistribution.html
[2] https://en.wikipedia.org/w/index.php?title=Negative_binomial_distribution&oldid=931222356 (2019-12-17)
[3] https://en.wikipedia.org/w/index.php?title=Negative_binomial_distribution&oldid=611204120 (2014-06-02)
[4] https://se.mathworks.com/help/stats/prob.negativebinomialdistribution.html
[5] http://search.r-project.org/R/library/stats/html/NegBinomial.html