Skip to content

Commit b0a287c

Browse files
author
Release Manager
committed
gh-39681: Fix eulerian_number(0,0) and eulerian_polynomial(0) to return 1 <!-- ^ Please provide a concise and informative title. --> <!-- ^ Don't put issue numbers in the title, do this in the PR description below. --> <!-- ^ For example, instead of "Fixes #12345" use "Introduce new method to calculate 1 + 2". --> <!-- v Describe your changes below in detail. --> <!-- v Why is this change required? What problem does it solve? --> <!-- v If this PR resolves an open issue, please link to it here. For example, "Fixes #12345". --> This PR fixes a bug in the `eulerian_number` and `eulerian_polynomial` functions where `eulerian_number(0, 0)` and `eulerian_polynomial(0)` incorrectly return `0` instead of `1`. The change ensures these functions align with the standard combinatorial definitions of Eulerian numbers and polynomials. Fixes: #39679 ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [ ] I have created tests covering the changes. - [ ] I have updated the documentation and checked the documentation preview. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - #12345: short description why this is a dependency --> <!-- - #34567: ... --> URL: #39681 Reported by: Vidip Singh Reviewer(s):
2 parents 12c7aa5 + 09d7981 commit b0a287c

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/sage/combinat/combinat.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,8 @@ def eulerian_number(n, k, algorithm='recursive') -> Integer:
562562
[0, 1, 4, 1, 0]
563563
"""
564564
n = ZZ(n)
565+
if n == 0:
566+
return ZZ.one() if k == 0 else ZZ.zero()
565567
if k < 0 or k > n - 1:
566568
return ZZ.zero()
567569
if k == 0 or k == n - 1:
@@ -614,7 +616,7 @@ def eulerian_polynomial(n, algorithm='derivative'):
614616
R = PolynomialRing(ZZ, 't')
615617
if n < 0:
616618
return R.zero()
617-
if n == 1:
619+
if n <= 1:
618620
return R.one()
619621
t = R.gen()
620622
if algorithm == 'derivative':

0 commit comments

Comments
 (0)