Skip to content

Integrate numerically by Gauss-Legendre, and give the digits it knows - #2063

Merged
Rafael-SOWNet merged 2 commits into
masterfrom
integrate-numerically-by-gauss-legendre
Oct 22, 2026
Merged

Rafael-SOWNet merged 2 commits into
masterfrom
integrate-numerically-by-gauss-legendre

Conversation

@Rafael-SOWNet

Copy link
Copy Markdown
Member

Fixes #1675.

  • The defect. DefiniteIntegral took the mean of steps + 1 equally weighted samples, the two bounds among them. That is a first-order rule. At the default 100 steps, x^2 over [0, 1] was off in the third digit, and the value printed to a hundred digits. A convergent integral with a singular bound came out NaN, sin(x)/x and ln(x) over [0, 1] among them.
  • The change. The rule is now five-point Gauss–Legendre on steps panels, which is exact on each panel up to degree nine and never evaluates a bound. It runs on steps panels, then twice as many, then four times as many.
    • Divergence. Because no bound is ever evaluated, a divergent integral gets a finite value: 1/x over [0, 1] came to about 10. So when the differences between the three runs do not shrink faster than the rounding, the integral is NaN.
    • Slow convergence. When the differences do shrink, the rest of their geometric series is added to the value and is reported as the error. For x^-0.9 over [0, 1], the value without that tail was 7, where the integral is 10.
    • Odd integrands. The rounding is measured against the integral of the modulus, so x^3 over [-1, 1] is 0 and not NaN.
    • Digits. The value is rounded to the place of its error, at most fifteen digits. Downcasting is off while it rounds, so -0.9999 does not print as -9999/10000.
    • Not covered. A singularity inside the segment is not detected, and the docs say so.
  • The MCP server used to run the old rule at 2000 and 4000 steps and report the digits on which the two agreed. Its self-test listed the first-order rule as a defect, which no longer reproduces. It now asks once and reports the digits of the value it gets, with half a unit in the last place as the error. Its caveat says what the rule does at a bound, and its README lists the workarounds that remain.

DefiniteIntegralByGaussLegendreTest: 7 of its 11 cases fail on master. Those are x^2, sin(x)/x, ln(x), 1/sqrt(x), e^x and sin(x) to their tolerances, plus the digit count. The full unit suite passes (16,714), and so do the MCP tests (325). The library builds for netstandard2.0. The BREAKING-CHANGES entry lists the changed values: x^2 was 0.33499… and is 0.333333333333333; sin(x)/x was NaN and is 0.946083070367182; ln(x) was NaN and is -1.00000; 1/x is still NaN. #2061 and #2062 open the same section, so whichever of the three merges later has one heading to resolve.

🤖 Generated with Claude Code

https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura

DefiniteIntegral was the mean of steps + 1 equally weighted samples, its
bounds among them: a first-order rule, off in the third digit on x^2 over
[0, 1] at the default 100 steps and printed to a hundred digits, and NaN
for a convergent integral with a singular bound, sin(x)/x and ln(x) over
[0, 1] among them. It is now the five-point Gauss-Legendre rule on steps
panels, which never evaluates a bound and is exact on each panel for
degree nine, run on the panels, twice as many and four times as many.

Never evaluating a bound, the rule gives a divergent integral a finite
value -- 1/x over [0, 1] came to about 10 -- so where the differences
between the three do not shrink above the rounding, the integral is NaN.
Where they shrink, the rest of their geometric series is added and is the
error: for x^-0.9 the last difference is a fourteenth of it, and the value
without it was 7 where it is 10. The rounding is measured against the
integral of the modulus, so x^3 over [-1, 1] is 0 and not NaN. The value is
rounded to the place of the error, at most fifteen digits, with the
downcasting off so that -0.9999 does not print as -9999/10000. A
singularity inside the segment is not seen, and the docs say so.

The MCP server ran the old rule at 2000 and 4000 steps and reported the
digits the two agreed on, and its self-test documented the first-order
rule, which no longer reproduces. It now asks once and reports the digits
of the value it gets, with half a unit in the last place for the error;
its caveat says what the rule does at a bound, and its README lists the
workarounds that remain.

Fixes #1675.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura
…ly-by-gauss-legendre

# Conflicts:
#	BREAKING-CHANGES.md
#	Sources/MCP/AngouriMath.Mcp/SelfTest.cs
#	Sources/MCP/README.md
@Rafael-SOWNet
Rafael-SOWNet merged commit e043a06 into master Oct 22, 2026
34 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in AngouriMath Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

DefiniteIntegral is a first-order rule, and is NaN where an endpoint is singular

1 participant