Skip to content

Commit 2d26789

Browse files
Give the error functions and the exponential and trigonometric integrals limits (#2373)
erf, erfc, erfi, Si, Ci, Shi, Chi, Ei and li had no limit at all: even erf(x) at +oo, which is 1, and erf(x) at 1 were left unevaluated, on master and on 2.6.0. At an infinity each now gives its known value (erf to +-1, erfc to 0 and 2, Si to +-pi/2, Ci to 0, Ei to +oo and 0; erfi, Shi, Chi and li to +-oo), each checked with mpmath at +-10^6, or +-50 for erfi, Shi and Chi. At a finite point the limit is the function of the argument's limit, kept exact. erf, erfc, erfi, Si and Shi are entire, so any finite point is accepted; Ci, Chi, Ei and li are singular at 0 and cut below it, so only a positive real point is, and li also excludes 1. Nothing is claimed on a cut. The limitcheck A/B over 24 seeds decides 30 to 290 more limits per seed, with no value lost. The new two-sided NaNs are 0^0 forms such as erf(x)^x at 0, which follow the x^x convention; their one-sided limits are right. 16 of the 19 new test rows fail on master. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent eda9e03 commit 2d26789

3 files changed

Lines changed: 193 additions & 0 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,31 @@ filed; a check of limits against values near the destination found it.
574574

575575
The same spelled `(-ln(2)/ln(x))^(exp(x) - 1)` was `1` in 2.6.0 and did not return after it; it is `1` again.
576576

577+
### The error functions and the exponential and trigonometric integrals have limits
578+
579+
**`erf(x)` at +oo is `1`, where it was left unevaluated.** None of erf, erfc, erfi, Si, Ci, Shi, Chi, Ei or li had a
580+
limit at all, not even at a point where it is continuous: `erf(x)` at 1 was unevaluated too. Their limits at the
581+
infinities are now their values there:
582+
- erf: 1 and -1
583+
- erfc: 0 and 2
584+
- erfi and Shi: +oo and -oo
585+
- Si: pi/2 and -pi/2
586+
- Ci: 0
587+
- Chi and li: +oo
588+
- Ei: +oo and 0
589+
590+
A finite limit of the argument is put in where the function is continuous. For the entire ones that is anywhere.
591+
For Ci, Chi, Ei and li it is only a positive real point, since they are singular at 0 and cut below it, and li is
592+
singular at 1 too.
593+
594+
| Input | Was (2.6.0) | Now |
595+
|---|---|---|
596+
| `"erf(x)".ToEntity().Limit("x", "+oo")` | `limit(erf(x), x, +oo)` | `1` |
597+
| `"erf(x)".ToEntity().Limit("x", 1)` | `limit(erf(x), x, 1)` | `erf(1)` |
598+
| `"Si(x)".ToEntity().Limit("x", "+oo")` | `limit(Si(x), x, +oo)` | `pi / 2` |
599+
| `"Ei(x)".ToEntity().Limit("x", "-oo")` | `limit(Ei(x), x, -oo)` | `0` |
600+
| `"erf(x)/x + 1".ToEntity().Limit("x", 0)` | `limit(erf(x) / x + 1, x, 0)` | `2 / sqrt(pi) + 1` |
601+
577602
### A limit of a logarithm that is not decided is left unevaluated
578603

579604
**Not silent: what overflowed the stack now returns.** A limit of a logarithm whose argument has no limit, as

‎Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Limit.Classes.cs‎

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,115 @@ partial record Arccosf
402402
}
403403
}
404404

405+
/// <summary>
406+
/// The limit of an error function or an exponential or trigonometric integral, given its
407+
/// argument's limit: the value it tends to at an infinity, and the function of a finite limit
408+
/// where it is continuous there.
409+
/// </summary>
410+
/// <remarks>
411+
/// None of these had a limit at all, so erf(x) at +oo, which is 1, was left unevaluated, and
412+
/// so was erf(x) at 1. A logarithm of something holding one came to a stop that took more than
413+
/// forty seconds: log(x + pi + erf(x), x^2 + tanh(1)) at +oo, which is 2. At an infinity:
414+
/// erf to 1 and -1, erfc to 0 and 2, erfi, Shi to +oo and -oo, Si to pi/2 and -pi/2, Ci to 0,
415+
/// Chi and li to +oo, and Ei to +oo and 0. Erf, erfc, erfi, Si and Shi are entire, so a finite
416+
/// limit is put in as it is. Ci, Chi, Ei and li have a logarithm's singularity at 0 and its cut
417+
/// below it, and li another at 1, so only a positive real limit other than li's 1 is put in;
418+
/// elsewhere nothing is claimed. Each value at an infinity was checked against mpmath at 10^6 and
419+
/// -10^6, and at 50 and -50 for erfi, Shi and Chi.
420+
/// </remarks>
421+
private static Entity? OfAnErrorOrIntegralFunction(Entity node, Entity argument, Variable x, Entity dist, ApproachFrom side)
422+
{
423+
if (argument.ComputeLimitDivideEtImpera(x, dist, side) is not { } limit)
424+
return null;
425+
if (limit.Evaled is Real { IsFinite: false, IsNaN: false } infinity)
426+
{
427+
var upwards = !infinity.IsNegative;
428+
return node switch
429+
{
430+
Erff => upwards ? Integer.One : Integer.MinusOne,
431+
Erfcf => upwards ? Integer.Zero : Integer.Create(2),
432+
Erfif or Shif => upwards ? Real.PositiveInfinity : Real.NegativeInfinity,
433+
Sif => upwards ? MathS.pi / 2 : -MathS.pi / 2,
434+
Cif => upwards ? Integer.Zero : null,
435+
Chif or Lif => upwards ? Real.PositiveInfinity : null,
436+
Eif => upwards ? Real.PositiveInfinity : Integer.Zero,
437+
_ => null
438+
};
439+
}
440+
if (limit.Evaled is not Number { IsFinite: true, IsNaN: false } value)
441+
return null;
442+
var entire = node is Erff or Erfcf or Erfif or Sif or Shif;
443+
if (!entire && !(value is Real { IsPositive: true } && !(node is Lif && value == Integer.One)))
444+
return null;
445+
return node switch
446+
{
447+
Erff => new Erff(limit),
448+
Erfcf => new Erfcf(limit),
449+
Erfif => new Erfif(limit),
450+
Sif => new Sif(limit),
451+
Cif => new Cif(limit),
452+
Shif => new Shif(limit),
453+
Chif => new Chif(limit),
454+
Eif => new Eif(limit),
455+
Lif => new Lif(limit),
456+
_ => null
457+
};
458+
}
459+
460+
partial record Erff
461+
{
462+
internal override Entity? ComputeLimitDivideEtImpera(Variable x, Entity dist, ApproachFrom side)
463+
=> OfAnErrorOrIntegralFunction(this, Argument, x, dist, side);
464+
}
465+
466+
partial record Erfcf
467+
{
468+
internal override Entity? ComputeLimitDivideEtImpera(Variable x, Entity dist, ApproachFrom side)
469+
=> OfAnErrorOrIntegralFunction(this, Argument, x, dist, side);
470+
}
471+
472+
partial record Erfif
473+
{
474+
internal override Entity? ComputeLimitDivideEtImpera(Variable x, Entity dist, ApproachFrom side)
475+
=> OfAnErrorOrIntegralFunction(this, Argument, x, dist, side);
476+
}
477+
478+
partial record Sif
479+
{
480+
internal override Entity? ComputeLimitDivideEtImpera(Variable x, Entity dist, ApproachFrom side)
481+
=> OfAnErrorOrIntegralFunction(this, Argument, x, dist, side);
482+
}
483+
484+
partial record Cif
485+
{
486+
internal override Entity? ComputeLimitDivideEtImpera(Variable x, Entity dist, ApproachFrom side)
487+
=> OfAnErrorOrIntegralFunction(this, Argument, x, dist, side);
488+
}
489+
490+
partial record Shif
491+
{
492+
internal override Entity? ComputeLimitDivideEtImpera(Variable x, Entity dist, ApproachFrom side)
493+
=> OfAnErrorOrIntegralFunction(this, Argument, x, dist, side);
494+
}
495+
496+
partial record Chif
497+
{
498+
internal override Entity? ComputeLimitDivideEtImpera(Variable x, Entity dist, ApproachFrom side)
499+
=> OfAnErrorOrIntegralFunction(this, Argument, x, dist, side);
500+
}
501+
502+
partial record Eif
503+
{
504+
internal override Entity? ComputeLimitDivideEtImpera(Variable x, Entity dist, ApproachFrom side)
505+
=> OfAnErrorOrIntegralFunction(this, Argument, x, dist, side);
506+
}
507+
508+
partial record Lif
509+
{
510+
internal override Entity? ComputeLimitDivideEtImpera(Variable x, Entity dist, ApproachFrom side)
511+
=> OfAnErrorOrIntegralFunction(this, Argument, x, dist, side);
512+
}
513+
405514
partial record Arctanf
406515
{
407516
internal override Entity? ComputeLimitDivideEtImpera(Variable x, Entity dist, ApproachFrom side)
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
//
2+
// Copyright (c) 2019-2026 Angouri.
3+
// AngouriMath is licensed under MIT.
4+
// Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.
5+
// Website: https://am.angouri.org.
6+
//
7+
8+
using AngouriMath.Core;
9+
using Xunit;
10+
11+
namespace AngouriMath.Tests.Calculus
12+
{
13+
/// <summary>
14+
/// The error functions and the exponential and trigonometric integrals had no limit at all: <c>erf(x)</c> at +oo,
15+
/// which is 1, was left unevaluated, and so was <c>erf(x)</c> at 1. Their limits at the infinities are now their
16+
/// values there, and a finite limit of the argument is put in where the function is continuous: anywhere for the
17+
/// entire ones, only at a positive real point for Ci, Chi, Ei and li, which are singular at 0 and cut below it, and
18+
/// li singular at 1 too. The same on 2.6.0. Found by limitcheck at <c>DEPTH=3</c>, <c>SEED=53</c>; no issue was
19+
/// filed.
20+
/// </summary>
21+
[Trait("Area", "Calculus")]
22+
public sealed class ErrorAndIntegralFunctionLimitsTest
23+
{
24+
[Theory]
25+
[InlineData("erf(x)", "+oo", "1")]
26+
[InlineData("erf(x)", "-oo", "-1")]
27+
[InlineData("erfc(x)", "+oo", "0")]
28+
[InlineData("erfc(x)", "-oo", "2")]
29+
[InlineData("erfi(x)", "+oo", "+oo")]
30+
[InlineData("Si(x)", "+oo", "pi/2")]
31+
[InlineData("Si(x)", "-oo", "-pi/2")]
32+
[InlineData("Ci(x)", "+oo", "0")]
33+
[InlineData("Shi(x)", "-oo", "-oo")]
34+
[InlineData("Chi(x)", "+oo", "+oo")]
35+
[InlineData("Ei(x)", "+oo", "+oo")]
36+
[InlineData("Ei(x)", "-oo", "0")]
37+
[InlineData("li(x)", "+oo", "+oo")]
38+
[InlineData("erf(x)", "1", "erf(1)")]
39+
[InlineData("Ci(x)", "2", "Ci(2)")]
40+
[InlineData("erf(x)/x + 1", "0", "2/sqrt(pi) + 1")]
41+
public void HasItsLimit(string input, string destination, string expected)
42+
=> Assert.Equal(MathS.FromString(expected).Simplify(), MathS.FromString(input).Limit("x", destination).Simplify());
43+
44+
[Fact]
45+
public void IsOneSidedWhereItsArgumentDiverges()
46+
{
47+
Assert.Equal(MathS.FromString("1"), MathS.FromString("erf(1/x)").Limit("x", 0, ApproachFrom.Right));
48+
Assert.Equal(MathS.FromString("-pi/2").Simplify(), MathS.FromString("Si(1/x)").Limit("x", 0, ApproachFrom.Left).Simplify());
49+
Assert.Equal(MathS.NaN, MathS.FromString("erf(1/x)").Limit("x", 0));
50+
}
51+
52+
// Nothing is claimed on Ci's cut or at li's pole.
53+
[Theory]
54+
[InlineData("Ci(x)", "-2")]
55+
[InlineData("Ci(x)", "-oo")]
56+
public void IsNotAnsweredOnACut(string input, string destination)
57+
=> Assert.IsType<Entity.Limitf>(MathS.FromString(input).Limit("x", destination));
58+
}
59+
}

0 commit comments

Comments
 (0)