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

feat: add math/base/special/bernoullif #3037

Open
wants to merge 16 commits into
base: develop
Choose a base branch
from

Conversation

gururaj1512
Copy link
Member

@gururaj1512 gururaj1512 commented Oct 26, 2024

Progresses #649

Description

What is the purpose of this pull request?

float stdlib_base_bernoullif( const int32_t n )

Related Issues

Does this pull request have any related issues?

This pull request:

Questions

Any questions for reviewers of this pull request?

No.

Other

Any other information relevant to this pull request? This may include screenshots, references, and/or implementation notes.

No.

Checklist

Please ensure the following tasks are completed before submitting this pull request.


@stdlib-js/reviewers

@stdlib-bot stdlib-bot added the Math Issue or pull request specific to math functionality. label Oct 26, 2024
@kgryte kgryte added Feature Issue or pull request for adding a new feature. Needs Changes Pull request which needs changes before being merged. labels Oct 26, 2024
@Planeshifter
Copy link
Member

@gunjjoshi This is not a problem exclusively with this PR, since it also applies to math/base/special/bernoulli, which you added in #1860, but I noticed that the implementation returns zero for all odd numbers. However, Wikipedia says that this is incorrect for input value 1: https://en.wikipedia.org/wiki/Bernoulli_number
Could you please take a look and confirm whether we need to handle this case separately?

@gunjjoshi
Copy link
Member

@Planeshifter Thanks for catching this. After digging for some time, I found that there is a mix of opinions on whether B(1) = +1/2 or B(1) = -1/2. For instance, here is a discussion from sympy: sympy/sympy#23866.
While it is incorrect to use B(1) = 0, the choice that must be made is between +1/2 or -1/2.
sympy now uses +1/2 (it used -1/2 earlier). There's a discussion at sagemath too: sagemath/sage#34521.

Overall, I think, it would be better if we too, use B(1) = +1/2. I'll make this change in math/base/special/bernoulli, if this is fine.

@gunjjoshi
Copy link
Member

gunjjoshi commented Nov 11, 2024

But yes, NIST prescribes the convention to use B(1) = -1/2: https://en.wikipedia.org/wiki/Bernoulli_number#Notation
What should we follow, in this case?

@kgryte
Copy link
Member

kgryte commented Nov 13, 2024

Let's go ahead and use 1/2. This will match SymPy and is also used as a convention in R. As commented elsewhere, how much the choice actually matters in practice is subject to some debate. In this case, I'm more inclined to go with Knuth.

@kgryte
Copy link
Member

kgryte commented Nov 13, 2024

Similar to the changes proposed in #3108, we'll want to make similar changes here.

kgryte added a commit that referenced this pull request Nov 14, 2024
…lli`

BREAKING CHANGE: update return value for `n=1`

In order to migrate and preserve prior behavior, users should special case `n=1` and return `0`. The change in this commit aligns return values with SymPy and R; although, other libraries and envs choose to return `-0.5`.

PR-URL: #3108
Ref: #3037 (comment)
Co-authored-by: Athan Reines <[email protected]>
Reviewed-by: Athan Reines <[email protected]> 
Signed-off-by: Gunj Joshi <[email protected]>
Signed-off-by: Athan Reines <[email protected]>
@gururaj1512
Copy link
Member Author

Refactored it as suggested.

@kgryte
Copy link
Member

kgryte commented Nov 18, 2024

/stdlib merge

@kgryte kgryte added the Needs Review A pull request which needs code review. label Nov 18, 2024
@kgryte kgryte requested a review from gunjjoshi November 18, 2024 04:12
@kgryte kgryte added Needs Review A pull request which needs code review. and removed Needs Changes Pull request which needs changes before being merged. labels Nov 25, 2024
@kgryte
Copy link
Member

kgryte commented Nov 25, 2024

@gururaj1512 Looks like this PR still has failing tests. We'll need to get those resolved before further review and subsequent merge.

@kgryte kgryte added Needs Changes Pull request which needs changes before being merged. and removed Needs Review A pull request which needs code review. labels Nov 25, 2024
Signed-off-by: Gururaj Gurram <[email protected]>
@stdlib-bot
Copy link
Contributor

stdlib-bot commented Nov 25, 2024

Coverage Report

Package Statements Branches Functions Lines
math/base/special/bernoullif $\color{green}239/239$
$\color{green}+100.00\%$
$\color{green}16/16$
$\color{green}+100.00\%$
$\color{green}2/2$
$\color{green}+100.00\%$
$\color{green}239/239$
$\color{green}+100.00\%$

The above coverage report was generated for the changes in this PR.

@gururaj1512
Copy link
Member Author

@gururaj1512 Looks like this PR still has failing tests. We'll need to get those resolved before further review and subsequent merge.

Resolved.

@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Dec 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Issue or pull request for adding a new feature. Math Issue or pull request specific to math functionality. Needs Changes Pull request which needs changes before being merged. Needs Review A pull request which needs code review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants