Repository navigation
Diverge across a singularity of Ei, Ci, Chi or li, and integrate a step times a pole piecewise - #2746
Open
Rafael-SOWNet wants to merge 4 commits into
Open
Rafael-SOWNet wants to merge 4 commits into
Rafael-SOWNet wants to merge 4 commits into
Conversation
…ep times a pole piecewise A definite integral whose antiderivative is Ei, Ci, Chi or li of something that passes through 0 (or li's argument through 1) was evaluated by substituting the bounds, so the logarithmic singularity inside the range was never seen: exp(x)/x over [-1, 2], 1/ln(x) over [1/2, 2] and cos(x)/x over [-1, 1] all came back finite although each diverges. The antiderivative breaks there, so it is now listed in AntiderivativeBreaks.Inside, and the one-sided limits at the break decide: -oo - (-oo) is NaN, as for 1/x, and a range ending at the singularity gets the infinity of its one side. Si and Shi are entire and do not break. Taking those limits needed the limit solver to know what the functions do off the positive reals. Ei(u) tends to i pi sgn(Im u) as Re u -> -oo off the real line, li(u) to i pi sgn(arg u) as u -> 0 off the positive reals, and below 0 Ci and Chi go to -oo like gamma + ln u. The logarithmic-singularity rule kept gamma inside the limit of ln(x) - ln|x|, which it cannot take at 0-; it now adds gamma afterwards, which turns (exp(x) - 1)/x over [-1, 2] from unevaluated into its value. A bound sitting on a branch point of one of these functions is now approached from inside rather than substituted. A step times a pole at the step's zero, such as floor(x)/x over [0, 1], gave 0/0 = NaN where the integral converges. When the unit-interval sum is NaN, each unit interval is now integrated with the step replaced by its constant there, up to 64 intervals, and nothing is answered if any piece stays unevaluated. Every changed answer was checked against mpmath at 50 digits; they are in BREAKING-CHANGES.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #2746 +/- ##
==========================================
- Coverage 86.70% 86.69% -0.02%
==========================================
Files 347 347
Lines 77376 77457 +81
Branches 22783 22814 +31
==========================================
+ Hits 67089 67149 +60
- Misses 5546 5558 +12
- Partials 4741 4750 +9
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
…nction-pole-and-li-negative
…iderivative A definite integral took ln(abs(u)) for every ln(u) in the antiderivative whose argument was negative somewhere in the range (#2616). That drops i pi times the logarithm's coefficient, which is a constant between the breaks only where the coefficient is. With the breaks this branch adds at the singularities of li, ln(x) li(2x) over [-pi, pi] reached that step: its antiderivative holds ln(x) against li(2x) and Ei(2 ln(2x)), and with the moduli taken it came out as pi (li(-2 pi) + li(2 pi)) (ln(pi) - 1), 1.784 + 2.217i, where mpmath gives -34.8874626534 + 2.1706698626i. Master timed out on it. The moduli are now taken only when every such logarithm is c ln(u) + G with c constant and G free of it, the same rule as #2751 (the hunk is identical, so that the two merge cleanly there). ln(x) li(2x) over [-pi, pi] is left unevaluated, as on master; over [-pi, -1] and [-1, -1/2] it is right, and an integral of the logarithm of a negative number keeps its imaginary part (ln(x) over [-2, -1] was 2 ln(2) - 1, and is 0.3863 + 3.1416i). Sweeps against mpmath quad split at every singularity, master 2ddbc2e vs this branch: {ln(x), x, x^2, 1/x} times {li, Ei, Ci, Si, Chi, Shi}(a x + b), 864 rows: right 400 -> 537, wrong 58 -> 0, declined 309 -> 276, timeout 97 -> 51. Logarithm class (x^k ln(u)^m, artanh, ln(x)/x), 216 rows: right 93 -> 192, wrong 80 -> 0. No row got worse (six declined -> timeout under load were re-run alone and decline on both in the same time). Part of #2716 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
netstandard2.0 has no Enumerable.ToHashSet, so the library did not build for that target. The HashSet constructor removes duplicates the same way. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
A definite integral whose antiderivative is
Ei,Ci,Chiorliof something passing through its logarithmic singularity inside the range was evaluated by substituting the bounds, so a divergent integral got a finite value. The singularity is now an antiderivative break, and the one-sided limits there decide:NaNwhere both sides diverge,±oowhere the range ends at it.SiandShiare entire and unchanged.The limit solver learns what these functions do off the positive reals (
Ei(u) -> i pi sgn(Im u)asRe u -> -oo,li(u) -> i pi sgn(arg u)at 0,Ci/Chi->-oobelow 0), and the logarithmic-singularity rule addseulergammaafter the limit instead of inside it.A step times a pole at the step's zero (
floor(x)/xover[0, 1]) gave0/0 = NaN; when the unit-interval sum isNaN, each unit interval is now integrated with the step's constant, up to 64 intervals.exp(x)/x, [-1, 2]NaNexp(x)/x, [0, 2] / [-2, 0]+oo/-oo1/ln(x), [1/2, 2]NaNcos(x)/x, [-1, 1]NaNcos(x^2)/x, [-pi, pi]NaN(exp(x) - 1)/x, [-1, 2]abs(x - 1/2) Chi(-x), [-1, 1]x li(sqrt(x)), [-2, 2]ln(ln(x)), [0, 2]ln(x) li(x), [0, 1]floor(x)/x, [0, 1]NaNfloor(x)/x, [0, 3]NaNfloor(x) Si(1/x), [-pi, pi]NaNCi(x),x -> 0--ooli(x),x -> 0-i piThe rows of
liover negative arguments in the issue (li(x)over [-2, -1],li(-x)over [0, 1],li(x^3)over [-1, 0]) come fromln(u)being replaced byln|u|; that is the fix for #2715 and is not repeated here. With that fix's working patch applied on top of this branch they are right. #2731 also editsIntegration.Definition.csandBREAKING-CHANGES.md; the hunks are apart.Checked on master 9b75a26: full unit suite (22405 passed, 0 failed), CasBench (120/121, 0 wrong, as master), PropCheck (1355 checks, 0 failures). A sweep of 757 related integrals: 19 answers changed, every one checked against mpmath (improvements or reorderings); the slowest new answer is
abs(x - 1/2) Ci(sqrt(x))over [-1, 1], 1.3 s -> 2.2 s.A logarithm is taken of its modulus only where it stands alone (second commit)
With the breaks above,
ln(x) li(2x)over[-pi, pi]came out aspi (li(-2 pi) + li(2 pi)) (ln(pi) - 1)= 1.784 + 2.217i, where mpmath gives -34.8874626534 + 2.1706698626i (master timed out). The cause was not the breaks butWithRealLogarithms(#2616), which replaced everyln(u)whose argument is negative in the range byln(abs(u)). That dropsi pitimes the coefficient, which is a constant between the breaks only where the coefficient is; this antiderivative holdsln(x)againstli(2x)andEi(2 ln(2x)). Tested by the fix it predicts: with the moduli taken only when each logarithm isc ln(u) + G(cconstant,Gfree of it), the integral is left unevaluated as on master, and its pieces over[-pi, -1]and[-1, -1/2]are right (the second was-ooon both before).That is #2751's
WithRealLogarithms/StandsAlonehunk, copied byte for byte, so the two agree there. It also fixes, ahead of #2751, integrals of the logarithm of a negative number that lost their imaginary part:ln(x)over[-2, -1]was2 ln(2) - 1, now0.38629 + 3.14159i;x ln(x),ln(x)^2,ln(x)/x,x^2 ln(x)likewise (entries inBREAKING-CHANGES.md).1/xover[-2, -1]is still-ln(2).Sweeps against mpmath
quadsplit at every singularity, master2ddbc2e4dvs this head:{ln(x), x, x^2, 1/x}times{li, Ei, Ci, Si, Chi, Shi}(a x + b), intervals across 0, the pole, the branch point: masterx^k ln(u)^m,artanh,ln(x)/x,1/(x - a): masterNo row got worse. Ten rows went from declined to timeout under load; I re-ran them alone and they decline on both sides in the same time. Three
li(a x)/xrows ending at 0 from the negative side are now∓i oo. That is right, sinceli(x) -> i pithere. On rows answered the same way on both sides, the median time is 69 -> 48 ms and 21 -> 16 ms.Merged master
8b4f507c1. Full unit suite: 22584 passed and 2 failed, run alongside the sweeps at load ~20. The two failures were wall-clock tests (IntegralAnswerCacheTest.AnIntegralWithNoAnswerStillFinishesQuickly,ALimitAtABreakIsRememberedTestfor1/(a + sin(x))), and both pass when run alone.1/(a + sin(x))over[0, 2 pi]takes 7.8 s on master and 8.0 s here. CasBench 120/121 with 0 wrong, PropCheck 1355 checks with 0 failures, SimpSweep 10463/10463 agree, BoundCheck 0 disagreements.For #2751: after this merges, the
StandsAlonehunk is identical on both sides. Its only conflict inIntegration.Definition.csis whereHoldsAModulusOffTheRealLinefollowsStandsAlone; take #2751's side there. TheAtTheBoundconflict and theLimit.Classes.csconflict are as before, and this commit does not touchLimit.Classes.cs.Part of #2716. Fixes #2737:
integral(abs(x - 1/2) Chi(-x), x, -1, 1)is now -0.19562144704 + 0.78539816340i, matching mpmath (master had half the imaginary part).: parts 1 and 3. Part 2 (liover negative arguments) lands with the fix for #2715.🤖 Generated with Claude Code