diff --git a/BREAKING-CHANGES.md b/BREAKING-CHANGES.md
index d26ab2afa..1be44dd16 100644
--- a/BREAKING-CHANGES.md
+++ b/BREAKING-CHANGES.md
@@ -288,6 +288,31 @@ one point, or else `Simplify` proving it zero. A singular matrix answers as `[[1
| `"[[sin(x)^2, 1], [1 - cos(x)^2, 1]]^(-1)".Simplify()` | `NaN` | `1 / [[sin(x) ^ 2, 1], [sin(x) ^ 2, 1]]` |
| `"[[e^x, e^(2x)], [2, e^x]]^(-1)".Simplify()` | its inverse | unchanged |
+### Ei, Ci, Chi and li have limits at their logarithmic singularity
+
+Unevaluated limits become values. `Ei(u)`, `Ci(u)` and `Chi(u)` are `eulergamma` plus the logarithm of `u` plus what
+tends to 0 as `u` does, `ln|u|` for Ei and `ln u` for the other two, and `li(u)` is `Ei(ln u)`. So each is `-oo` at its
+singularity along the real line, and a sum holding one with a coefficient that has a finite limit has the limit of the
+same sum with `eulergamma` and the logarithm in its place. None of these was answered. Ci and Chi approached from
+below 0, where the principal logarithm is `ln|u| + pi i`, are still not answered. The antiderivative of `erf(x) ln(x)`
+holds `ln(x)` against `Ei(-x^2)`, so the definite integral over `[0, 1]` was left as written, after about ten seconds of
+search for its limit at 0; it is now its value, which mpmath's quadrature gives as `-0.26134836002139896`. `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 asks
+whether its two agreeing sides are its limit, so `x Ei(x)` at 0, 0 from each side, is 0 where it was left unevaluated; `x Ci(x)`, which is not real
+left of 0, is left unevaluated as it was. Measured on master
+`abd100a33` and on this branch ([#2661](https://github.com/asc-community/AngouriMath/issues/2661)).
+
+| Call | Was (`abd100a33`) | Now |
+|---|---|---|
+| `"Ei(x)".Limit("x", 0)` | `limit(Ei(x), x, 0)` | `-oo` |
+| `"Ci(x)".Limit("x", 0, ApproachFrom.Right)` | `limitright(Ci(x), x, 0)` | `-oo` |
+| `"li(x)".Limit("x", 1)` | `limit(li(x), x, 1)` | `-oo` |
+| `"Ei(x) - ln(x)".Limit("x", 0, ApproachFrom.Right)` | `limitright(Ei(x) - ln(x), x, 0)` | `eulergamma` |
+| `"Ei(2x) - Ei(x)".Limit("x", 0, ApproachFrom.Right)` | `limitright(Ei(2 * x) - Ei(x), x, 0)` | `ln(2)` |
+| `"x Ei(x)".Limit("x", 0)` | `limit(x * Ei(x), x, 0)` | `0` |
+| `"erf(x) * ln(x)".ToEntity().Integrate("x", 0, 1)` | `integral(erf(x) * ln(x), x, 0, 1)` | `erf(1) * (1 * ln(1) - 1) - ...`, `-0.2613483600...` |
+| `"Ci(x)".Limit("x", 0, ApproachFrom.Left)` | `limitleft(Ci(x), x, 0)` | unchanged |
+
### A real root beside a pole is found by the numeric search
**More roots in the same finite set.** Where no analytical route answers, `Solve` gives the roots Newton's method
diff --git a/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Limit.Classes.cs b/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Limit.Classes.cs
index 3ecfc803c..f04ae8ef5 100644
--- a/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Limit.Classes.cs
+++ b/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Limit.Classes.cs
@@ -771,6 +771,8 @@ partial record Arccosf
}
if (limit.Evaled is not Number { IsFinite: true, IsNaN: false } value)
return null;
+ if (AtTheLogarithmicSingularity(node, argument, value, x, dist, side) is { } singular)
+ return singular;
var entire = node is Erff or Erfcf or Erfif or Sif or Shif;
if (!entire && !(value is Real { IsPositive: true } && !(node is Lif && value == Integer.One)))
return null;
@@ -789,6 +791,38 @@ partial record Arccosf
};
}
+ ///
+ /// -oo for an exponential, cosine or hyperbolic cosine integral whose argument tends to 0, and a
+ /// logarithmic integral whose argument tends to 1, where the logarithm in it tends to -oo along the
+ /// real line; otherwise.
+ ///
+ ///
+ /// Ei(u) = gamma + ln|u| + O(u) for real u of either sign, and li(u) = Ei(ln u), so each
+ /// tends to -oo as u reaches its singularity along the real line. Ci(u) and Chi(u)
+ /// are gamma + ln u + O(u^2) with the principal logarithm, which is -oo from above and
+ /// -oo + pi i from below, so only the approach from above is answered. Undecided, Ei at 0 was asked again
+ /// by every rewrite the search for a limit holding it made: the antiderivative of erf(x) ln(x) at 0
+ /// asked the limit of Ei(-1/x^2) at +oo 574 times of the 2000 its budget allows, and the
+ /// integral over [0, 1] took sixteen seconds to be left as written. Checked against mpmath at
+ /// ±1e-10, where ei, ci, chi and li(1 ± 1e-10) are all near -22.4.
+ /// https://github.com/asc-community/AngouriMath/issues/2661
+ ///
+ private static Entity? AtTheLogarithmicSingularity(Entity node, Entity argument, Number value, Variable x, Entity dist, ApproachFrom side)
+ {
+ var (logarithmOf, bothSigns) = node switch
+ {
+ Eif when value == Integer.Zero => (argument, true),
+ Cif or Chif when value == Integer.Zero => (argument, false),
+ Lif when value == Integer.One => ((Entity)MathS.Ln(argument), true),
+ _ => (null, false)
+ };
+ if (logarithmOf is null)
+ return null;
+ return SignOnEachSide(logarithmOf, x, dist, side) is { } sign && (sign is 1 || bothSigns && sign is -1)
+ ? Real.NegativeInfinity
+ : null;
+ }
+
partial record Erff
{
internal override Entity? ComputeLimitDivideEtImpera(Variable x, Entity dist, ApproachFrom side)
diff --git a/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Solvers.Definition.cs b/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Solvers.Definition.cs
index 4031c189f..d83d5949a 100644
--- a/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Solvers.Definition.cs
+++ b/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Solvers.Definition.cs
@@ -348,6 +348,15 @@ bool RealThere(Entity node)
Ceilf(var argument) => RealThere(argument),
Roundf(var argument) => RealThere(argument),
Signumf(var argument) => RealThere(argument),
+ // And the exponential, sine and hyperbolic sine integrals of a real argument, and the cosine,
+ // hyperbolic cosine and logarithmic integrals of a positive one, below which they take the
+ // logarithm's cut. x Ei(x) at 0 is 0 from each side. https://github.com/asc-community/AngouriMath/issues/2661
+ Eif(var argument) => RealThere(argument),
+ Sif(var argument) => RealThere(argument),
+ Shif(var argument) => RealThere(argument),
+ Cif(var argument) => RealThere(argument) && PositiveOnBothSides(argument),
+ Chif(var argument) => RealThere(argument) && PositiveOnBothSides(argument),
+ Lif(var argument) => RealThere(argument) && PositiveOnBothSides(argument),
_ => false
};
}
@@ -495,6 +504,60 @@ private static Entity ExpandLogarithm(Entity expr)
_ => expr
};
+ ///
+ /// The limit of with an exponential, cosine or hyperbolic cosine integral whose argument
+ /// tends to 0, or a logarithmic integral whose argument tends to 1, written as the logarithm it differs from by
+ /// what tends to 0; or .
+ ///
+ ///
+ ///
+ /// Ei(u) - gamma - ln|u| is sum_(k >= 1) u^k / (k k!) for real u, Ci(u) - gamma - ln u
+ /// is int_0^u (cos t - 1)/t dt and Chi's the same with cosh, and li(u) = Ei(ln u); each
+ /// tends to 0 at the singularity. Where expr is A + c N in the function N, with c
+ /// tending to a finite value, c (N - L) tends to 0 for L the logarithmic part, and expr has
+ /// the limit of A + c L, which the logarithms already in A can cancel. Left as the function, the
+ /// infinity less an infinity was settled by nothing: the antiderivative of ln(x) erf(x) at 0 holds
+ /// ln(x) against Ei(-x^2)/(2 sqrt(pi)), and the search for its limit spent its whole budget of
+ /// 2000 limits in ten seconds, asking 256 questions over and over, and left the integral over [0, 1]
+ /// unevaluated where it is 1/sqrt(pi) + eulergamma/(2 sqrt(pi)) - erf(1) - 1/(e sqrt(pi)) - Ei(-1)/(2 sqrt(pi)),
+ /// -0.26135. https://github.com/asc-community/AngouriMath/issues/2661
+ ///
+ ///
+ /// Only along the real line: ln|u| is Ei's logarithmic part for a real u of either sign, and
+ /// ln u is Ci's and Chi's for a positive one. The principal logarithm of a negative
+ /// u is ln|u| + pi i, which is where they take theirs, and that is not asked.
+ ///
+ ///
+ private static (bool Asked, Entity? Limit) ThroughALogarithmicSingularity(Entity expr, Variable x, Entity dest, ApproachFrom side, bool acceptNaN)
+ {
+ foreach (var node in expr.Nodes)
+ {
+ var (argument, singularAt, logarithmOf, bothSigns) = node switch
+ {
+ Eif(var u) => (u, (Entity)Integer.Zero, u, true),
+ Cif(var u) => (u, Integer.Zero, u, false),
+ Chif(var u) => (u, Integer.Zero, u, false),
+ Lif(var u) => (u, Integer.One, MathS.Ln(u), true),
+ _ => (null!, null!, null!, false)
+ };
+ if (argument is null || !argument.ContainsNode(x)
+ || ComputeLimit(argument, x, dest, side) is not { } atTheSingularity || atTheSingularity.Evaled != singularAt
+ || SignOnEachSide(logarithmOf, x, dest, side) is not { } sign || !(sign is 1 || bothSigns && sign is -1))
+ continue;
+ var standIn = Variable.CreateUnique(expr, "u");
+ var linear = expr.Substitute(node, standIn);
+ var coefficient = linear.Differentiate(standIn).InnerSimplified;
+ if (coefficient.ContainsNode(standIn) || coefficient.Nodes.Any(static inner => inner is Derivativef)
+ || ComputeLimit(coefficient, x, dest, side) is not { } coefficientLimit
+ || coefficientLimit.ContainsNode(x) || coefficientLimit.Nodes.Any(static inner => inner is Limitf)
+ || coefficientLimit.Evaled is Number { IsFinite: false } or Number { IsNaN: true })
+ continue;
+ var logarithmicPart = MathS.eulergamma + MathS.Ln(sign is 1 ? logarithmOf : -logarithmOf);
+ return (true, ComputeLimit(linear.Substitute(standIn, logarithmicPart), x, dest, side, acceptNaN));
+ }
+ return (false, null);
+ }
+
///
/// How many limits a budgeted computation may still take, every one it asks along the way counted, or
/// where there is no budget. Past it each is undecided. Set by .
@@ -723,6 +786,12 @@ node is Derivativef(var expression, Variable variable, var iterations) && iterat
expr = expr.Replace(c => AsSineOverCosine(c, x));
MultithreadingFunctional.ExitIfCancelled();
+ // Asked whole and answered or declined there: what is left is the same limit, without the infinity less an
+ // infinity that nothing settles, and searching the original for it again spent the budget the definite
+ // integral's bound is taken within.
+ if (ThroughALogarithmicSingularity(expr, x, dest, side, acceptNaN) is (true, var throughTheSingularity))
+ return throughTheSingularity;
+
if (side is ApproachFrom.Left or ApproachFrom.Right)
{
expr = WithStepsAtTheirLimits(expr, x, dest, side);
@@ -836,6 +905,7 @@ node is Derivativef(var expression, Variable variable, var iterations) && iterat
else if (DescendComparingSides(ApproachFrom.Left) is { } fromLeft
&& DescendComparingSides(ApproachFrom.Right) is { } fromRight)
{
+
if (fromLeft == fromRight && (acceptNaN || fromLeft.Evaled != MathS.NaN))
return fromLeft;
if (ExpressionNumerical.AreEqual(fromLeft, fromRight) && (acceptNaN || fromLeft.Evaled != MathS.NaN))
diff --git a/Sources/Tests/UnitTests/Calculus/ErrorAndIntegralFunctionLimitsTest.cs b/Sources/Tests/UnitTests/Calculus/ErrorAndIntegralFunctionLimitsTest.cs
index 125d76b0e..45f3c8e52 100644
--- a/Sources/Tests/UnitTests/Calculus/ErrorAndIntegralFunctionLimitsTest.cs
+++ b/Sources/Tests/UnitTests/Calculus/ErrorAndIntegralFunctionLimitsTest.cs
@@ -49,11 +49,54 @@ public void IsOneSidedWhereItsArgumentDiverges()
Assert.Equal(MathS.NaN, MathS.FromString("erf(1/x)").Limit("x", 0));
}
- // Nothing is claimed on Ci's cut or at li's pole.
+ // Nothing is claimed on Ci's cut, nor at its singularity from below, where it is -oo + pi i.
[Theory]
[InlineData("Ci(x)", "-2")]
[InlineData("Ci(x)", "-oo")]
public void IsNotAnsweredOnACut(string input, string destination)
=> Assert.IsType(MathS.FromString(input).Limit("x", destination));
+
+ [Fact]
+ public void IsNotAnsweredAtTheSingularityFromBelowTheCut()
+ {
+ Assert.IsType(MathS.FromString("Ci(x)").Limit("x", 0, ApproachFrom.Left));
+ Assert.IsType(MathS.FromString("Chi(x) - ln(-x)").Limit("x", 0, ApproachFrom.Left));
+ }
+
+ private static ApproachFrom Side(string side)
+ => side switch { "left" => ApproachFrom.Left, "right" => ApproachFrom.Right, _ => ApproachFrom.BothSides };
+
+ ///
+ /// Ei, Ci and Chi are eulergamma + ln|u|, or ln u for Ci and Chi, plus what tends to 0 as u
+ /// does, and li(u) is Ei(ln u): each is -oo at its singularity along the real line, and a sum holding one
+ /// with a bounded coefficient has the limit of the same sum with the logarithm in its place. Each was left
+ /// unevaluated, and the antiderivative of ln(x) erf(x) at 0, ln(x) against Ei(-x^2),
+ /// spent the whole budget of limits a definite integral's bound is taken within before being left so. Each value
+ /// was checked against mpmath at 1e-10 from the side approached.
+ /// https://github.com/asc-community/AngouriMath/issues/2661
+ ///
+ [Theory]
+ [InlineData("Ei(x)", "0", "both", "-oo")]
+ [InlineData("Ei(-x^2)", "0", "both", "-oo")]
+ [InlineData("Ei(-1/x^2)", "+oo", "both", "-oo")]
+ [InlineData("Ci(x)", "0", "right", "-oo")]
+ [InlineData("Chi(x)", "0", "right", "-oo")]
+ [InlineData("li(x)", "1", "both", "-oo")]
+ [InlineData("Ei(x) - ln(x)", "0", "right", "eulergamma")]
+ [InlineData("Ei(x) - ln(-x)", "0", "left", "eulergamma")]
+ [InlineData("Ci(x) - ln(x)", "0", "right", "eulergamma")]
+ [InlineData("Chi(x) - ln(x)", "0", "right", "eulergamma")]
+ [InlineData("Ei(-x^2)/2 - ln(x)", "0", "right", "eulergamma/2")]
+ [InlineData("li(x) - ln(ln(x))", "1", "right", "eulergamma")]
+ [InlineData("li(x) - ln(-ln(x))", "1", "left", "eulergamma")]
+ [InlineData("Ei(2x) - Ei(x)", "0", "right", "ln(2)")]
+ [InlineData("Ei(x)/ln(x)", "0", "right", "1")]
+ [InlineData("Ei(x) + 1/x", "0", "right", "+oo")]
+ [InlineData("x Ei(x)", "0", "both", "0")]
+ public void HasItsLimitAtItsLogarithmicSingularity(string input, string destination, string side, string expected)
+ {
+ var limit = MathS.FromString(input).Limit("x", MathS.FromString(destination), Side(side));
+ Assert.Equal(MathS.FromString(expected).Simplify(), limit.Simplify());
+ }
}
}
diff --git a/Sources/Tests/UnitTests/Calculus/ImproperIntegralTest.cs b/Sources/Tests/UnitTests/Calculus/ImproperIntegralTest.cs
index ac7723b1c..1419fdaac 100644
--- a/Sources/Tests/UnitTests/Calculus/ImproperIntegralTest.cs
+++ b/Sources/Tests/UnitTests/Calculus/ImproperIntegralTest.cs
@@ -75,13 +75,33 @@ public void ABoundWhoseLimitIsNotDecidedLeavesTheIntegralAsWritten(string integr
Entity? result = null;
var task = System.Threading.Tasks.Task.Run(() => result = Definite(integrand, "0", "1"));
// The budget bounds the work, in limits; this wall is a backstop against a hang that the budget no longer
- // bounds, not a measure of time. The erf integral takes about nine seconds alone, and a wall of sixty
- // fired in the full suite on a loaded machine.
+ // bounds, not a measure of time. The erf integral took fourteen seconds alone, ten of them one limit spending
+ // the whole budget, and a wall of sixty fired in the full suite on a loaded machine; it takes about four
+ // since Ei's limit at 0 is read (https://github.com/asc-community/AngouriMath/issues/2661). Written as
+ // erf(x) ln(x) it is answered (see ABoundAtTheExponentialIntegralsSingularityIsItsLimit), but the limit
+ // through this spelling's antiderivative is still not decided, and Simplify keeps the integral as written.
Assert.True(task.Wait(System.TimeSpan.FromMinutes(5)), $"the integral of {integrand} from 0 to 1 was still being simplified");
Assert.IsType(result);
Assert.DoesNotContain(result!.Nodes, node => node == MathS.NaN);
}
+ ///
+ /// The antiderivative of erf(x) ln(x) holds ln(x) against Ei(-x^2) / (2 sqrt(pi)), an infinity
+ /// less an infinity at 0 that is -(1 + eulergamma/2) / sqrt(pi) once Ei is read as the logarithm it differs
+ /// from by what tends to 0. The integral over [0, 1] was left as written, after ten seconds spent on that
+ /// limit; it is -0.2613483600213989642, which mpmath's quadrature gives to thirty digits.
+ /// https://github.com/asc-community/AngouriMath/issues/2661
+ ///
+ [Fact]
+ public void ABoundAtTheExponentialIntegralsSingularityIsItsLimit()
+ {
+ var value = "erf(x) * ln(x)".ToEntity().Integrate("x", 0, 1);
+ Assert.False(value.Nodes.Any(node => node is Entity.Integralf or Entity.Limitf), value.Stringize());
+ var closedForm = "(1 - Ei(-1)/2 - 1/e + eulergamma/2)/sqrt(pi) - erf(1)".ToEntity();
+ Assert.True((value - closedForm).EvalNumerical().Abs() < 1e-25, $"was {value}");
+ Assert.True((value - "-0.2613483600213989642354593897".ToEntity()).EvalNumerical().Abs() < 1e-25, $"was {value}");
+ }
+
/// A bound the substitution answers is answered as it was.
[Theory]
[InlineData("e^(-x)", "0", "+oo", "1")]