Skip to content

Include the last term in the Fejer quadrature weights - #337

Open
SajalDevX wants to merge 2 commits into
theochem:masterfrom
SajalDevX:fix-fejer-weights
Open

SajalDevX wants to merge 2 commits into
theochem:masterfrom
SajalDevX:fix-fejer-weights

Conversation

@SajalDevX

Copy link
Copy Markdown

Fixes #336

FejerFirst and FejerSecond summed j = 1 .. nsum-1 when building the
weights, but the Fejér formulas run to j = nsum. Without the last term an
n-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 over j = 1 .. nsum in both rules.
  • test_onedgrid.py: the reference loops in test_FejerFirst / test_FejerSecond
    had the same off-by-one (range(1, nsum)), so I changed them to
    range(1, nsum + 1). I added test_fejer_polynomial_exactness, which checks
    that both rules integrate x^k exactly for k < n, n = 2..15.

On master the new test and test_FejerSecond fail; with the change the whole
test_onedgrid.py passes (36 tests).

I used Claude to help find this and write the tests; I reviewed the change and
ran everything locally.

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FejerFirst and FejerSecond weights drop the last term of the sum

2 participants