Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rand.dist.bern.negbin] negative_binomial_distribution has unclear specification for p == 1 LWG 3402 #3606

Open
tc3t opened this issue Jan 6, 2020 · 6 comments
Labels
lwg Issue must be reviewed by LWG. not-editorial Issue is not deemed editorial; the editorial issue is kept open for tracking.

Comments

@tc3t
Copy link

tc3t commented Jan 6, 2020

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:

  1. 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.

  2. 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

@tc3t tc3t changed the title negative_binomial_distribution has unclear specification for p == 1 [rand.dist.bern.negbin] negative_binomial_distribution has unclear specification for p == 1 Jan 6, 2020
@jwakely
Copy link
Member

jwakely commented 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
Copy link
Member

jwakely commented Jan 6, 2020

... and probably SG6 (the Numerics study group).

@jensmaurer
Copy link
Member

You seek normative clarification on p==1, which should be handled by an LWG issue.

@jensmaurer jensmaurer added the lwg Issue must be reviewed by LWG. label Jan 6, 2020
@tc3t
Copy link
Author

tc3t commented 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
Copy link
Member

@tc3t, did you already obtain a new LWG issue?

@jwakely
Copy link
Member

jwakely commented May 23, 2020

https://WG21.link/lwg3402

@jensmaurer jensmaurer changed the title [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 Feb 5, 2021
@jensmaurer jensmaurer added the not-editorial Issue is not deemed editorial; the editorial issue is kept open for tracking. label Feb 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lwg Issue must be reviewed by LWG. not-editorial Issue is not deemed editorial; the editorial issue is kept open for tracking.
Projects
None yet
Development

No branches or pull requests

3 participants