Conversation
FejerFirst and FejerSecond summed j = 1 .. nsum-1, but the Fejer weight formulas run to j = nsum (floor(n/2) for the first rule, ceil(n/2) for the second). Dropping the last term means an n-point rule no longer integrates x^k exactly for k < n. Fixes theochem#336
The reference loops in test_FejerFirst and test_FejerSecond had the same off-by-one as the code (range(1, nsum)), so they agreed with it. Use the full range there, and check that both rules integrate x^k exactly for k < n, n = 2..15.
PaulWAyers
requested review from
Ao-chuba,
FarnazH and
marco-2023
and
a balanced review from Copilot
September 30, 2026 11:55
Contributor
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The corrected formulas match the documented bounds and the regression tests validate both rules across multiple orders.
Review effort: Balanced
Findings: None
What changed in this PR
Fixes off-by-one errors in Fejér quadrature weight summations, restoring polynomial exactness.
Changes:
- Includes the final summation term in both Fejér rules.
- Updates reference calculations and adds polynomial-exactness tests.
| File | Description |
|---|---|
src/grid/onedgrid.py |
Corrects Fejér weight calculations. |
src/grid/tests/test_onedgrid.py |
Updates references and adds regression coverage. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #336
FejerFirstandFejerSecondsummedj = 1 .. nsum-1when building theweights, but the Fejér formulas run to
j = nsum. Without the last term ann-point rule isn't exact for x^k with k < n (e.g.
FejerSecond(4)gives 0.5 for∫x² instead of 2/3).
Changes:
onedgrid.py: sum overj = 1 .. nsumin both rules.test_onedgrid.py: the reference loops intest_FejerFirst/test_FejerSecondhad the same off-by-one (
range(1, nsum)), so I changed them torange(1, nsum + 1). I addedtest_fejer_polynomial_exactness, which checksthat both rules integrate x^k exactly for k < n, n = 2..15.
On master the new test and
test_FejerSecondfail; with the change the wholetest_onedgrid.pypasses (36 tests).I used Claude to help find this and write the tests; I reviewed the change and
ran everything locally.