Skip to content

Read Ei, Ci, Chi and li at their logarithmic singularity in limits - #2687

Merged
Rafael-SOWNet merged 1 commit into
masterfrom
fix-2661-fast-undecided-bound-decline
Dec 3, 2026
Merged

Rafael-SOWNet merged 1 commit into
masterfrom
fix-2661-fast-undecided-bound-decline

Conversation

@Rafael-SOWNet

Copy link
Copy Markdown
Member

Fixes #2661

Cause

ABoundWhoseLimitIsNotDecidedLeavesTheIntegralAsWritten("ln(x) * erf(x)") took 14 s. Simplify integrates three spellings of the integrand. One of them, erf(x) * ln(x), which Evaled of a candidate also reaches through the decimal-e spelling erf(x) * log(2.718…, x), has the antiderivative

erf(x) (x ln(x) - x) - ((ln(x) * 2 * -e^(-x^2)/2 - -Ei(-x^2)/2) / sqrt(pi) + …)

Its limit at 0 is ln(x) against Ei(-x^2)/(2 sqrt(pi)), an infinity less an infinity. That one limit took 10.3 s and spent the whole budget of 2000 limits. Logging every limit it took showed 256 distinct questions among the 2000. Ei(-1/x^2) at +oo alone was asked 574 times: Ei at 0 had no limit, and an undecided limit is not memoised. The other two spellings took 2.4 s and 0.7 s (66 limits each).

What was checked and ruled out on the way:

  • Reading only the leaf (Ei(u) -> -oo as u -> 0) made the row slower, 20.6 s. The search got further and still spent the 2000. A missing leaf value was not the whole cause.
  • The decimal-e spelling comes from Integralf.InnerSimplify asking this.Evaled first, and from Simplificator.AddHistory. It costs about 2.5 s and is unchanged here.

The change

Ei(u) = eulergamma + ln|u| + sum u^k/(k k!), Ci(u) and Chi(u) are eulergamma + ln u + O(u^2), and li(u) = Ei(ln u).

  1. Leaf: Ei, Ci and Chi tend to -oo as their argument tends to 0, and li as its argument tends to 1, along the real line. Ci and Chi are answered from above only, because the principal logarithm below 0 is ln|u| + pi i.
  2. Additive rule: suppose expr = A + c N, linear in such a node N, and c has a finite limit. Then expr has the limit of A + c (eulergamma + ln(±u)), because c (N - L) -> 0. That limit is asked once, and a decline there is final: the original is not searched again.
  3. Ei, Si and Shi of a real argument, and Ci, Chi and li of a positive one, are read as real in IsRealOnBothSides. Without this, x Ei(x) at 0 came out NaN once the leaf was read: both sides are 0, but the agreement was not promoted. A first attempt instead made a non-promoted agreement "undecided" rather than NaN. It broke 20 tests of the library's convention that x ln(x) and x^x have no two-sided limit, so it was dropped.

Measurements (abd100a vs this branch, same machine, under the shared lock)

Each row run alone (Simplify of the integral, a new process each time, master and branch alternating, 3 runs each):

row master branch
ln(x) * erf(x) 14.26 / 13.83 / 13.95 s 3.86 / 3.86 / 3.85 s
ln(x) * Si(x) 2.17 / 2.12 / 1.99 s 2.96 / 2.95 / 2.99 s

In dotnet test (the Theory, Si row after erf in one process, 2 runs each): erf 14 s / 14 s → 4 s / 3 s; Si 367 / 368 ms → 904 / 919 ms.

The Si row is about 0.8 s slower. The rule rewrites its third spelling's limit to Si(x)(x ln x - x) - (-ln(x) cos(x) + eulergamma + ln(x) + cos(x)). The engine does not settle that: ln(x) cos(x) - ln(x) at 0+ is itself undecided on master, while ln(x)(cos(x) - 1) is 0. The search for it takes 675 limits, against 101 for the original form. Both decline.

Both rows still decline under Simplify, and the Theory is unchanged. But the erf integral is decidable: Integrate(erf(x) * ln(x), x, 0, 1) now answers (1 - Ei(-1)/2 - 1/e + eulergamma/2)/sqrt(pi) - erf(1). mpmath gives -0.261348360021398964235459389701 both from that closed form and from quad(log(x)*erf(x), [0, 1]). Simplify of the ln(x) * erf(x) spelling still keeps the integral as written, because:

  • that spelling's limit is the same ln(x) * (…) - ln(x)-type form that stays undecided;
  • the cost model ranks the unevaluated integral below the answered value.

The Si integral is decidable too: 1 + eulergamma - Si(1) - cos(1) - Ci(1), mpmath -0.246573634234758006. It is undecided for the same engine gap.

Checks

  • Full C# suite: 22125 passed, 0 failed, 13 skipped. F# wrapper 135/135, Mcp 470, Terminal 69, Interactive 19 (+1 skipped). AOT smoke OK.
  • CasBench: the same 162 rows, verdicts and outputs on master and branch, 120/121 solved, 0 wrong. Total time 1986 ms on master, 1896 ms on the branch.
  • BoundCheck, RootCheck, PropCheck and SimpSweep reports: identical to master. RuleCheck, CanonCheck, Confluence and ModenovCorpus match their baselines.
  • limitcheck (600 cases, seed 1) and symlimitcheck: reports identical to master. Times: limitcheck 33 / 32 s master and 33 / 28 s branch; symlimitcheck 31 / 31 s master and 26 / 25 s branch.
  • New tests: ErrorAndIntegralFunctionLimitsTest.HasItsLimitAtItsLogarithmicSingularity has 17 rows, each value checked against mpmath at 1e-10. IsNotAnsweredAtTheSingularityFromBelowTheCut covers Ci and Chi from the left. ImproperIntegralTest.ABoundAtTheExponentialIntegralsSingularityIsItsLimit checks the integral against the closed form and the mpmath value to 1e-25.
  • BREAKING-CHANGES.md entry: the limits that went from unevaluated to values, and the erf integral.

Not done here (follow-ups)

  • ln(x) cos(x) - ln(x) at 0+ (and ln(x)(x Si(x) + cos(x)) - ln(x)) is undecided. A sum of terms that share one diverging factor is not gathered over it. Fixing that would answer both rows of the Theory, and the Theory would then need an integrand that is genuinely undecided.
  • An answered integral loses to the unevaluated one in the cost model when only a reordered spelling answers it.

🤖 Generated with Claude Code

Ei(u), Ci(u) and Chi(u) are eulergamma plus the logarithm of u plus what tends
to 0 with u, and li(u) is Ei(ln u). Each is now -oo at its singularity along the
real line (Ci and Chi from above only), and a sum holding one with a coefficient
that has a finite limit takes the limit of the same sum with eulergamma and the
logarithm in its place, asked once and not searched again. Ei, Si and Shi of a
real argument, and Ci, Chi and li of a positive one, are read as real where a
two-sided limit promotes its agreeing sides.

The antiderivative of ln(x) erf(x) at 0 holds ln(x) against Ei(-x^2); its
limit spent the whole budget of 2000 limits on 256 distinct questions, asking
the limit of Ei(-1/x^2) at +oo 574 times, and the improper-integral test row
took 14 s. It takes about 4 s, and the integral of erf(x) ln(x) over [0, 1]
is answered: -0.26134836002139896, as mpmath's quadrature gives.

Fixes #2661

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Rafael-SOWNet Rafael-SOWNet added this to the 2.11 milestone Dec 3, 2026
@codecov

codecov Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.50000% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.64%. Comparing base (abd100a) to head (57e5353).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...ns/Continuous/Limits/Solvers/Solvers.Definition.cs 82.35% 2 Missing and 4 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2687      +/-   ##
==========================================
- Coverage   86.64%   86.64%   -0.01%     
==========================================
  Files         346      346              
  Lines       76412    76512     +100     
  Branches    22425    22468      +43     
==========================================
+ Hits        66208    66293      +85     
- Misses       5512     5517       +5     
- Partials     4692     4702      +10     
Flag Coverage Δ
cpp 37.77% <ø> (ø)
csharp 87.13% <87.50%> (-0.01%) ⬇️
fsharp 32.79% <ø> (ø)
interactive 40.09% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...nctions/Continuous/Limits/Solvers/Limit.Classes.cs 80.07% <100.00%> (+0.53%) ⬆️
...ns/Continuous/Limits/Solvers/Solvers.Definition.cs 89.48% <82.35%> (-1.32%) ⬇️

... and 8 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Rafael-SOWNet
Rafael-SOWNet merged commit 70b17bb into master Dec 3, 2026
35 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in AngouriMath Dec 3, 2026
@Rafael-SOWNet
Rafael-SOWNet deleted the fix-2661-fast-undecided-bound-decline branch December 3, 2026 13:10
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.

ln(x) erf(x) improper-integral decline takes 16 s and times out on the Windows runner

1 participant