Skip to content

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

Open
@tc3t

Description

@tc3t

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

Activity

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[/+] on Jan 6, 2020
jwakely

jwakely commented on Jan 6, 2020

@jwakely
Member

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

jwakely commented on Jan 6, 2020

@jwakely
Member

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

jensmaurer

jensmaurer commented on Jan 6, 2020

@jensmaurer
Member

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

tc3t

tc3t commented on Jan 7, 2020

@tc3t
Author

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

jensmaurer commented on May 23, 2020

@jensmaurer
Member

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

jwakely

jwakely commented on May 23, 2020

@jwakely
Member
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[/+] on Feb 5, 2021
added
not-editorialIssue is not deemed editorial; the editorial issue is kept open for tracking.
on Feb 5, 2021
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

    lwgIssue must be reviewed by LWG.not-editorialIssue is not deemed editorial; the editorial issue is kept open for tracking.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @jwakely@tc3t@jensmaurer

        Issue actions

          [rand.dist.bern.negbin] negative_binomial_distribution has unclear specification for p == 1 LWG 3402 · Issue #3606 · cplusplus/draft