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
Activity
[-]negative_binomial_distribution has unclear specification for p == 1[/-][+][rand.dist.bern.negbin] negative_binomial_distribution has unclear specification for p == 1[/+]jwakely commentedon Jan 6, 2020
This doesn't seem editorial. The LWG issue acknowledged there was a problem but explicitly decided against changing anything more than adding a note. Further changes should go through LWG again.
jwakely commentedon Jan 6, 2020
... and probably SG6 (the Numerics study group).
jensmaurer commentedon Jan 6, 2020
You seek normative clarification on p==1, which should be handled by an LWG issue.
tc3t commentedon Jan 7, 2020
Thanks for the responses. I'll consider making a LWG issue on this, although the comments in LWG2406 mention the need to have a paper reviewing the whole clause instead of having issues one distribution at a time, but perhaps this could be considered as an exception given that it got the note.
There seems to be no list for SG6 in isocpp forums, but I'll considered making a validation pass through Std-discussions.
jensmaurer commentedon May 23, 2020
@tc3t, did you already obtain a new LWG issue?
jwakely commentedon May 23, 2020
https://WG21.link/lwg3402
[-][rand.dist.bern.negbin] negative_binomial_distribution has unclear specification for p == 1[/-][+][rand.dist.bern.negbin] negative_binomial_distribution has unclear specification for p == 1 LWG 3402[/+]